SRM515 Div1 Easy - RotatedClock

問題

ある目盛りから見て時針がh度、分針がm度を指している時計がある
しかし時計が真ん丸なのでどの目盛りが0時なのかわからない
あり得る時間として最小のものを求める (存在しない場合は空文字列を返す)

解法

12個の目盛りを全て0時にしてみて、矛盾しないものの中で最小のものを返せばいい
矛盾するかどうかの判定は、分針360度で時針が30度 ∴ 分針12度で時針1度 進むから
h%30 = m/12
∴ m = 12*(h%30)
これが成り立てばok

class RotatedClock {
	public:
	string tm(int h, int m) {
		if (m!=12*(h%30)) return ">_<";
		h /= 30, m /= 6;
		return (h/10 ? "" : "0") + to_string(h) + ":" + (m/10 ? "" : "0") + to_string(m);
	}
	
	string getEarliest(int h, int m) {
		string res = ">_<";
		rep(i,12) chmin(res, tm(h,m)), (h += 30) %= 360, (m += 30) %= 360;
		return (res==">_<" ? "" : res);
	}
};