結果

問題 No.3120 Lower Nim
ユーザー cho435
提出日時 2025-04-23 01:37:34
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 1,609 bytes
コンパイル時間 4,826 ms
コンパイル使用メモリ 257,388 KB
実行使用メモリ 25,972 KB
平均クエリ数 2685.91
最終ジャッジ日時 2025-04-23 01:37:49
合計ジャッジ時間 13,292 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
#include <cassert>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define all(x) begin(x), end(x)

template <typename T> bool chmin(T& x, T y) {
	return x > y ? (x = y, true) : false;
}
template <typename T> bool chmax(T& x, T y) {
	return x < y ? (x = y, true) : false;
}

struct IOST {
	IOST() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout << fixed << setprecision(20);
	}
} IOST;

using mint = atcoder::modint998244353;

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];
	auto check_a = [&]() {
		rep(b, 0, 15) {
			int bit = (1 << b);
			int flg = 0;
			rep(i, 0, n) flg ^= ((a[i] / bit) & 1);
			if (flg) return bit;
		}
		return -1;
	};
	set<int> st;
	rep(i, 0, n) st.insert(i);
	int nk = 1e9;
	auto get_judge = [&]() {
		int i, x;
		cin >> i >> x;
		i--;
		a[i] -= x;
		chmin(nk, x);
		if (a[i] == 0) st.erase(i);
	};
	int x = check_a();
	int ret;
	if (x == -1) {
		cout << "Second" << endl;
		get_judge();
		x = check_a();
		cin >> ret;
		if (ret == -1) return;
		assert(x <= nk);
	} else {
		cout << "First" << endl;
	}
	while (1) {
		int ci = -1;
		while (1) {
			for (int i : st) {
				if (a[i] >= x) {
					ci = i;
					break;
				}
			}
			if (ci == -1) x /= 2;
			else break;
		}
		cout << ci + 1 << " " << x << endl;
		a[ci] -= x;
		if (a[ci] == 0) st.erase(ci);
		cin >> ret;
		if (ret != 0) break;

		get_judge();
		cin >> ret;
		if (ret != 0) break;

		if (nk < x) x = check_a();
	}
}

int main() {
	int t = 1;
	// cin >> t;
	rep(i, 0, t) solve();
}
0