結果

問題 No.850 企業コンテスト2位
ユーザー startcppstartcpp
提出日時 2019-07-05 22:20:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,073 bytes
コンパイル時間 2,291 ms
コンパイル使用メモリ 52,112 KB
実行使用メモリ 24,168 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-23 17:28:57
合計ジャッジ時間 5,041 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
23,520 KB
testcase_01 AC 26 ms
24,168 KB
testcase_02 AC 27 ms
23,544 KB
testcase_03 AC 26 ms
23,748 KB
testcase_04 AC 27 ms
24,120 KB
testcase_05 AC 26 ms
23,316 KB
testcase_06 AC 27 ms
23,760 KB
testcase_07 AC 30 ms
23,544 KB
testcase_08 AC 32 ms
24,144 KB
testcase_09 AC 32 ms
24,168 KB
testcase_10 AC 36 ms
23,556 KB
testcase_11 AC 36 ms
23,964 KB
testcase_12 AC 36 ms
23,532 KB
testcase_13 AC 36 ms
23,268 KB
testcase_14 AC 36 ms
23,760 KB
testcase_15 AC 35 ms
23,928 KB
testcase_16 AC 36 ms
23,904 KB
testcase_17 AC 36 ms
23,508 KB
testcase_18 AC 36 ms
23,448 KB
testcase_19 AC 36 ms
23,568 KB
testcase_20 AC 35 ms
23,280 KB
testcase_21 AC 35 ms
23,292 KB
testcase_22 AC 36 ms
23,952 KB
testcase_23 AC 37 ms
23,964 KB
testcase_24 AC 36 ms
23,448 KB
testcase_25 AC 37 ms
23,892 KB
testcase_26 AC 36 ms
23,328 KB
testcase_27 AC 26 ms
23,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int query(int x, int y, int n) {
	if (y < 0 || y >= n) return x;
	if (x < 0 || x >= n) return y;
	cout << "? " << x + 1 << " " << y + 1 << endl;
	int ret;
	cin >> ret;
	return ret - 1;
}

const int DEPTH = 9;
int seg[1 << (DEPTH + 1)];

void init(int n) {
	int i;
	rep(i, (1 << (DEPTH + 1))) seg[i] = -1;
	rep(i, n) seg[(1 << DEPTH) - 1 + i] = i;
}

int construct(int n, int a = 0, int b = (1 << DEPTH), int id = 0) {
	if (b - a == 1) {
		return seg[id];
	}
	int u = construct(n, a, (a + b) / 2, id * 2 + 1);
	int v = construct(n, a, (a + b) / 2, id * 2 + 2);
	int res = query(u, v, n);
	seg[id] = res;
	return res;
}

int update(int pos, int val, int n) {
	pos += (1 << DEPTH) - 1;
	seg[pos] = val;
	while (pos > 0) {
		pos = (pos - 1) / 2;
		int res = query(seg[pos * 2 + 1], seg[pos * 2 + 2], n);
		seg[pos] = res;
	}
	return seg[0];
}

int main() {
	int n;
	cin >> n;
	init(n);
	int winner = construct(n);
	int ans = update(winner, -1, n);
	cout << "! " << ans + 1 << endl;
	return 0;
}
0