結果

問題 No.257 N言っちゃダメゲーム (3)
ユーザー Yang33Yang33
提出日時 2018-08-27 16:01:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 2,584 bytes
コンパイル時間 1,386 ms
コンパイル使用メモリ 163,128 KB
実行使用メモリ 24,300 KB
平均クエリ数 3.70
最終ジャッジ日時 2023-09-24 01:53:18
合計ジャッジ時間 4,651 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
24,156 KB
testcase_01 AC 43 ms
24,156 KB
testcase_02 AC 43 ms
23,448 KB
testcase_03 AC 43 ms
23,916 KB
testcase_04 AC 43 ms
23,760 KB
testcase_05 AC 43 ms
23,652 KB
testcase_06 AC 43 ms
23,928 KB
testcase_07 AC 44 ms
23,784 KB
testcase_08 AC 43 ms
23,328 KB
testcase_09 AC 43 ms
23,856 KB
testcase_10 AC 44 ms
23,292 KB
testcase_11 AC 43 ms
23,556 KB
testcase_12 AC 43 ms
23,568 KB
testcase_13 AC 44 ms
23,940 KB
testcase_14 AC 43 ms
23,856 KB
testcase_15 AC 43 ms
24,240 KB
testcase_16 AC 43 ms
23,556 KB
testcase_17 AC 43 ms
23,556 KB
testcase_18 AC 44 ms
23,604 KB
testcase_19 AC 43 ms
23,856 KB
testcase_20 AC 43 ms
23,292 KB
testcase_21 AC 43 ms
23,928 KB
testcase_22 AC 43 ms
23,436 KB
testcase_23 AC 43 ms
24,048 KB
testcase_24 AC 44 ms
23,868 KB
testcase_25 AC 44 ms
24,300 KB
testcase_26 AC 44 ms
23,448 KB
testcase_27 AC 43 ms
23,868 KB
testcase_28 AC 44 ms
23,688 KB
testcase_29 AC 43 ms
23,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/08/27  Problem: yukicoder 257  / Link: http://yukicoder.me/problems/no/257  ----- */
/* ------問題------

あなたとGrantは、いわゆる「21言っちゃダメゲーム(棒取りゲームというところも)」をすることにした。

ルールを拡張して正整数 N と K を使って以下のゲームを考える。

1. まず先攻のプレイヤーは 0 が与えられる。
2. そこから N 以上を宣言しないように(宣言したら負けになる)与えられた整数に 1~K のどれかの整数を加算したものを宣言し相手プレイヤーに渡す。
3. 勝負がつくまで代わり代わりに 2. を繰り返す。

実際にGrantと対戦し勝利してください。

最初にN,K が与えられ、
あなたは、先攻後攻どちらかを自由に選べる。
時間の都合上、相手は、5ターン連続で勝てる見込みがないと判断すると諦めることになっている。
相手が諦めた場合、ゲームの状態には関係なくN以上(N+K以下の数)が宣言される。これは相手が諦めたものであると解釈し、あなたの勝ちとし、プログラムを終了すること

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int N, K; cin >> N >> K;

	auto ask = [](int x) {
		cout << x << endl;
		int val; cin >> val;
		return val;
	};

	int next = 0;
	if ((N - 1) % (K + 1) == 0) { // 後攻
		next = 0;
	}
	else {
		next = (N - 1) % (K + 1);
	}

	while (1) {
		int res = ask(next);
		if (N <= res)break;
		else {
			next += (K + 1);
		}
	}

	return 0;
}
0