結果

問題 No.850 企業コンテスト2位
ユーザー square1001square1001
提出日時 2019-07-05 21:59:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,073 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 77,472 KB
実行使用メモリ 24,348 KB
平均クエリ数 203.36
最終ジャッジ日時 2023-09-23 17:24:51
合計ジャッジ時間 3,152 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
24,288 KB
testcase_01 AC 23 ms
23,424 KB
testcase_02 AC 23 ms
23,496 KB
testcase_03 AC 23 ms
23,520 KB
testcase_04 AC 23 ms
23,340 KB
testcase_05 AC 22 ms
23,340 KB
testcase_06 AC 23 ms
23,832 KB
testcase_07 AC 26 ms
23,844 KB
testcase_08 AC 28 ms
23,376 KB
testcase_09 AC 29 ms
24,348 KB
testcase_10 AC 32 ms
23,940 KB
testcase_11 AC 32 ms
23,568 KB
testcase_12 AC 32 ms
23,400 KB
testcase_13 AC 34 ms
23,844 KB
testcase_14 AC 32 ms
23,796 KB
testcase_15 AC 32 ms
23,496 KB
testcase_16 AC 32 ms
23,976 KB
testcase_17 AC 33 ms
24,300 KB
testcase_18 AC 31 ms
23,604 KB
testcase_19 AC 33 ms
23,604 KB
testcase_20 AC 32 ms
23,340 KB
testcase_21 AC 33 ms
23,388 KB
testcase_22 AC 32 ms
23,388 KB
testcase_23 AC 32 ms
23,832 KB
testcase_24 AC 34 ms
24,264 KB
testcase_25 AC 34 ms
23,784 KB
testcase_26 AC 32 ms
23,652 KB
testcase_27 AC 23 ms
24,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N; vector<int> cand;
int ask(int x, int y) {
	if (x > N) return y;
	if (y > N) return x;
	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() {
	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