結果

問題 No.1149 色塗りゲーム
ユーザー tkmst201tkmst201
提出日時 2021-01-20 15:49:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,047 bytes
コンパイル時間 2,726 ms
コンパイル使用メモリ 211,764 KB
実行使用メモリ 24,480 KB
平均クエリ数 3.64
最終ジャッジ日時 2023-09-24 09:41:47
合計ジャッジ時間 6,838 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
24,240 KB
testcase_01 AC 38 ms
24,240 KB
testcase_02 AC 38 ms
23,880 KB
testcase_03 WA -
testcase_04 AC 37 ms
23,532 KB
testcase_05 AC 38 ms
24,012 KB
testcase_06 AC 36 ms
23,700 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 38 ms
23,532 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 40 ms
24,204 KB
testcase_13 AC 40 ms
23,640 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 40 ms
24,228 KB
testcase_17 AC 39 ms
23,856 KB
testcase_18 AC 41 ms
24,012 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 42 ms
23,412 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	vector<int> grundy(N + 1);
	grundy[0] = 0;
	
	vector<bool> done;
	FOR(i, 1, N + 1) {
		done.assign(N + 1, false);
		REP(j, i) {
			done[grundy[j] ^ grundy[i - 1 - j]] = true;
			if (j + 1 < i) done[grundy[j] ^ grundy[i - 2 - j]] = true;
		}
		REP(j, i + 1) if (!done[j]) { grundy[i] = j; break; }
	}
	
	auto query = [](vector<bool> & board, int k, int x) -> pii {
		board[x] = true;
		if (k == 2) board[x + 1] = true;
		cout << k << " " << x + 1 << endl;
		int t;
		cin >> t;
		if (t <= 1) return {-1, 0};
		cin >> k >> x; --x;
		if (t == 2) return {-1, 0};
		board[x] = true;
		if (k == 2) board[x + 1] = true;
		return {k, x};
	};
	
	vector<bool> board(N);
	while (true) {
		vector<pii> cnt; // cnt, pos
		for (int i = 0, r = 0; i < N; i = r) {
			while (r < N && !board[r]) ++r;
			if (i == r) ++r;
			else cnt.emplace_back(r - i, i);
		}
		int g = 0;
		for (auto [c, _] : cnt) g ^= grundy[c];
		
		assert(g > 0);
		
		int mxbit = -1;
		for (int i = 6; i >= 0; --i) if (g >> i & 1) { mxbit = i; break; }
		
		pii cur {-1, 0};
		for (auto [c, p] : cnt) {
			if (~c >> mxbit & 1) continue;
			int nex = grundy[c] ^ g;
			REP(i, c) {
				if ((grundy[i] ^ grundy[c - 1 - i]) == nex) { cur = {1, p + i}; break; }
				if (i + 1 < c && (grundy[i] ^ grundy[c - 2 - i]) == nex) { cur = {2, p + i}; break; }
			}
			break;
		}
		
		auto res = query(board, cur.first, cur.second);
		if (res.first == -1) break;
	}
}
0