結果

問題 No.249 N言っちゃダメゲーム (2)
ユーザー ty70ty70
提出日時 2015-12-14 03:39:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,033 bytes
コンパイル時間 448 ms
コンパイル使用メモリ 60,064 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 16:10:42
合計ジャッジ時間 1,080 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>	// require memset
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;

bool is_win(int n, int k){
	return (n - 1) % (k + 1) != 0;	// 先攻が勝つ true 後攻が勝つ false
}

int n[1000], k[1000];
bool game[1000];	// 先攻が勝利する true 敗退する false
bool res[1000];

int main()
{
	memset (n, 0, sizeof(n));
	memset (k, 0, sizeof(k));
	memset (game, false, sizeof(game));
	memset (res, false, sizeof(res));

	ios_base::sync_with_stdio(0);
	rep (i, 1000){
		cin >> n[i] >> k[i];
		game[i] = is_win(n[i],k[i]);
	} // end rep

	bool  batting_first = true;
	res[0] = game[0];
	for (int i = 1; i < 1000; ++i){
		if (!res[i-1]){
			batting_first = game[i];
		}else{
			batting_first = !game[i];
		} // end if
		res[i] = !(batting_first ^ game[i]);
	} // end for

	int ans = count(res, res+1000, true);
	cout << ans << endl;
	
	return 0;
}
0