結果

問題 No.3496 協力カード当て
コンテスト
ユーザー startcpp
提出日時 2026-04-14 22:44:44
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 3,364 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 910 ms
コンパイル使用メモリ 89,764 KB
実行使用メモリ 30,320 KB
スコア 0
平均クエリ数 3.25
最終ジャッジ日時 2026-04-14 23:53:09
合計ジャッジ時間 8,205 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 2 RE * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <cassert>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int id, n, m;
vector<int> c;

void playA() {
	vector<int> cntA(m + 1), cntB(m + 1), cntAll(m + 1);
	for (int x: c) cntA[x]++;

	for (int i = 1; i <= m - 1; i++) {
		string s;
		cin >> s;
		cout << "ASK " << cntA[i] << endl;
		cout.flush();
		int x, K;
		cin >> s >> x >> K;
		cin >> s; //WAIT
		cin >> s >> x >> K;
		cntB[i] = x;
	}

	if (m % 2 == 1) { //Aから開始
		for (int i = 1; i <= m - 1; i += 2) {
			string s;
			cin >> s; // TURN
			cout << "ASK " << i << endl;
			cout.flush();
			int x, K;
			cin >> s >> x >> K;
			cntAll[x] = K;
			
			if (i + 1 <= m - 1) {
				cin >> s; //WAIT
				cin >> s >> x >> K;
				cntAll[x] = K;
			}
		}
	}
	else { //Bから開始
		for (int i = 1; i <= m - 1; i += 2) {
			string s;
			cin >> s; //WAIT
			int x, K;
			cin >> s >> x >> K;
			cntAll[x] = K;

			if (i + 1 <= m - 1) {
				cin >> s; //TURN
				cout << "ASK " << i << endl;
				cout.flush();
				cin >> s >> x >> K;
				cntAll[x] = K;
			}
		}
	}

	int sumA = 0, sumB = 0, sumAll = 0;
	for (int i = 1; i <= m - 1; i++) {
		sumA += cntA[i];
		sumB += cntB[i];
		sumAll += cntAll[i];
	}
	cntA[m] = n - sumA;
	cntB[m] = n - sumB;
	cntAll[m] = 3 * n - sumAll;

	vector<int> cntC(m + 1);
	vector<int> ans;
	for (int i = 1; i <= m; i++) {
		cntC[i] = cntAll[i] - cntA[i] - cntB[i];
		for (int j = 0; j < cntC[i]; j++) {
			ans.push_back(i);
		}
	}

	string s;
	while (cin >> s) { if (s == "TURN") break; }
	cout << "GUESSED ";
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i];
		if (i + 1 < ans.size()) cout << " ";
	}
	cout << endl;
	cout.flush();
}

void playB() {
	vector<int> cntA(m + 1), cntB(m + 1), cntAll(m + 1);
	for (int x: c) cntB[x]++;

	for (int i = 1; i <= m - 1; i++) {
		string s;
		cin >> s; //WAIT
		int x, K;
		cin >> s >> x >> K;
		cntA[i] = x;

		cin >> s; //TURN
		cout << "ASK " << cntB[i] << endl;
		cout.flush();
		cin >> s >> x >> K;
	}

	if (m % 2 == 0) { //Bから開始
		for (int i = 1; i <= m - 1; i += 2) {
			string s;
			cin >> s; // TURN
			cout << "ASK " << i << endl;
			cout.flush();
			int x, K;
			cin >> s >> x >> K;
			cntAll[x] = K;
			
			if (i + 1 <= m - 1) {
				cin >> s; //WAIT
				cin >> s >> x >> K;
				cntAll[x] = K;
			}
		}
	}
	else { //Aから開始
		for (int i = 1; i <= m - 1; i += 2) {
			string s;
			cin >> s; //WAIT
			int x, K;
			cin >> s >> x >> K;
			cntAll[x] = K;

			if (i + 1 <= m - 1) {
				cin >> s; //TURN
				cout << "ASK " << i << endl;
				cout.flush();
				cin >> s >> x >> K;
				cntAll[x] = K;
			}
		}
	}

	int sumA = 0, sumB = 0, sumAll = 0;
	for (int i = 1; i <= m - 1; i++) {
		sumA += cntA[i];
		sumB += cntB[i];
		sumAll += cntAll[i];
	}
	cntA[m] = n - sumA;
	cntB[m] = n - sumB;
	cntAll[m] = 3 * n - sumAll;

	vector<int> cntC(m + 1);
	vector<int> ans;
	for (int i = 1; i <= m; i++) {
		cntC[i] = cntAll[i] - cntA[i] - cntB[i];
		for (int j = 0; j < cntC[i]; j++) {
			ans.push_back(i);
		}
	}

	string s;
	while (cin >> s) { if (s == "TURN") break; }
	cout << "GUESSED ";
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i];
		if (i + 1 < ans.size()) cout << " ";
	}
	cout << endl;
	cout.flush();
}

int main() {
	int i;

	cin >> id >> n >> m;
	c.resize(n);
	rep(i, n) cin >> c[i];

	if (id == 1) { playA(); }
	else { playB(); }

	return 0;
}
0