はまやんはまやんはまやん

hamayanhamayan's blog

Pineapple Incident [Codeforces 362 : Div2 A]

問題

http://codeforces.com/contest/697/problem/A

時間 t,s と時刻 x が与えられる。
時間が t, t+s, t+s+1, t+2s, t+2s+1, ... と遷移する。
遷移状態の中に時刻 x が来るなら"YES"、そうでなければ"NO"を出力

0 <= t,x <= 10^9
2 <= s <= 10^9

考察

1. シミュレートでいける
t = 0, s = 2, x = 10^9も大丈夫そう
2. 引いて余りを見ても良い

実装

http://codeforces.com/contest/697/submission/19112443

int t, s, x;
//-----------------------------------------------------------------
string solve() {
	if (x == t + 1) return "NO";

	int d = x - t;
	if (d < 0) return "NO";

	if (d % s == 0) return "YES";
	else if (d % s == 1) return "YES";

	return "NO";
}
//-----------------------------------------------------------------
int main() {
	cin >> t >> s >> x;
	cout << solve() << endl;
}