結果

問題 No.850 企業コンテスト2位
ユーザー QCFiumQCFium
提出日時 2019-07-12 14:26:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,009 bytes
コンパイル時間 1,527 ms
コンパイル使用メモリ 170,648 KB
実行使用メモリ 24,360 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-23 17:55:09
合計ジャッジ時間 3,891 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
23,520 KB
testcase_01 AC 21 ms
23,628 KB
testcase_02 AC 23 ms
24,228 KB
testcase_03 AC 22 ms
23,652 KB
testcase_04 AC 22 ms
24,360 KB
testcase_05 AC 21 ms
23,508 KB
testcase_06 AC 22 ms
23,988 KB
testcase_07 AC 26 ms
24,012 KB
testcase_08 AC 28 ms
23,496 KB
testcase_09 AC 27 ms
23,376 KB
testcase_10 AC 31 ms
23,796 KB
testcase_11 AC 31 ms
23,328 KB
testcase_12 AC 31 ms
24,012 KB
testcase_13 AC 30 ms
23,616 KB
testcase_14 AC 31 ms
23,508 KB
testcase_15 AC 32 ms
23,508 KB
testcase_16 AC 30 ms
24,204 KB
testcase_17 AC 33 ms
23,496 KB
testcase_18 AC 32 ms
23,508 KB
testcase_19 AC 31 ms
24,204 KB
testcase_20 AC 31 ms
23,364 KB
testcase_21 AC 32 ms
23,616 KB
testcase_22 AC 30 ms
23,796 KB
testcase_23 AC 31 ms
23,604 KB
testcase_24 AC 31 ms
24,216 KB
testcase_25 AC 31 ms
24,216 KB
testcase_26 AC 31 ms
24,216 KB
testcase_27 AC 22 ms
24,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int main() {
	int n;
	scanf("%d", &n);
	std::vector<int> x;
	for (int i = 0; i < n; i++) x.push_back(i);
	std::vector<std::pair<int, int> > log;
	while (x.size() > 1) {
		std::vector<int> next;
		for (int i = 0; i < x.size() / 2; i++) {
			log.push_back({x[2 * i], x[2 * i + 1]});
			printf("? %d %d\n", log.back().first + 1, log.back().second + 1);
			fflush(stdout);
			int cur;
			scanf("%d", &cur);
			next.push_back(cur - 1);
		}
		if (x.size() % 2) next.push_back(x.back());
		x.swap(next);
	}
	std::vector<int> y;
	for (auto &i : log) {
		if (i.first == x[0]) y.push_back(i.second);
		if (i.second == x[0]) y.push_back(i.first);
	}
	while (y.size() > 1) {
		std::vector<int> next;
		for (int i = 0; i < y.size() / 2; i++) {
			printf("? %d %d\n", y[2 * i] + 1, y[2 * i + 1] + 1);
			fflush(stdout);
			int cur;
			scanf("%d", &cur);
			next.push_back(cur - 1);
		}
		if (y.size() % 2) next.push_back(y.back());
		y.swap(next);
	}
	printf("! %d\n", y[0] + 1);
	
	
	return 0;
}
0