結果

問題 No.850 企業コンテスト2位
ユーザー square1001square1001
提出日時 2019-07-05 21:58:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,030 bytes
コンパイル時間 1,086 ms
コンパイル使用メモリ 77,544 KB
実行使用メモリ 24,360 KB
平均クエリ数 202.79
最終ジャッジ日時 2023-09-23 17:24:47
合計ジャッジ時間 5,459 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 27 ms
23,388 KB
testcase_02 AC 26 ms
23,436 KB
testcase_03 AC 26 ms
23,880 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 27 ms
24,024 KB
testcase_07 AC 31 ms
23,700 KB
testcase_08 AC 32 ms
23,412 KB
testcase_09 WA -
testcase_10 AC 37 ms
24,348 KB
testcase_11 WA -
testcase_12 AC 37 ms
23,544 KB
testcase_13 WA -
testcase_14 AC 37 ms
24,360 KB
testcase_15 WA -
testcase_16 AC 37 ms
24,348 KB
testcase_17 AC 38 ms
24,048 KB
testcase_18 WA -
testcase_19 AC 36 ms
24,276 KB
testcase_20 AC 36 ms
24,228 KB
testcase_21 AC 37 ms
23,532 KB
testcase_22 AC 37 ms
23,388 KB
testcase_23 WA -
testcase_24 AC 36 ms
23,580 KB
testcase_25 WA -
testcase_26 AC 37 ms
23,688 KB
testcase_27 AC 26 ms
23,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> cand;
int ask(int x, int y) {
	cout << "? " << x << ' ' << y << endl;
	int res;
	cin >> res;
	return res;
}
int solve(vector<int> v) {
	if (v.size() == 1) return v[0];
	if (v.size() % 2 == 1) {
		int cnt = 1;
		while (find(v.begin(), v.end(), cnt) != v.end()) ++cnt;
		v.push_back(cnt);
	}
	vector<int> pv;
	for (int i = 0; i < v.size(); i += 2) {
		int res = ask(v[i], v[i + 1]);
		if (res == v[i]) pv.push_back(v[i]);
		else pv.push_back(v[i + 1]);
	}
	int ans = solve(pv);
	cand.push_back(v[(find(v.begin(), v.end(), ans) - v.begin()) ^ 1]);
	return ans;
}
int main() {
	int N;
	cin >> N;
	vector<int> v;
	for (int i = 1; i <= N; ++i) {
		v.push_back(i);
	}
	solve(v);
	sort(cand.begin(), cand.end());
	cand.erase(unique(cand.begin(), cand.end()), cand.end());
	int cur = 0;
	for (int i = 1; i < cand.size(); ++i) {
		int res = ask(cand[cur], cand[i]);
		if (res == cand[i]) cur = i;
	}
	cout << "! " << cand[cur] << endl;
	return 0;
}
0