結果

問題 No.850 企業コンテスト2位
ユーザー satashunsatashun
提出日時 2019-07-05 21:54:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,577 bytes
コンパイル時間 1,743 ms
コンパイル使用メモリ 168,748 KB
実行使用メモリ 24,348 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-23 17:24:17
合計ジャッジ時間 4,221 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,532 KB
testcase_01 AC 26 ms
23,376 KB
testcase_02 AC 26 ms
24,240 KB
testcase_03 AC 26 ms
23,784 KB
testcase_04 AC 27 ms
23,604 KB
testcase_05 AC 26 ms
23,784 KB
testcase_06 AC 26 ms
23,508 KB
testcase_07 AC 30 ms
24,348 KB
testcase_08 AC 32 ms
23,796 KB
testcase_09 AC 32 ms
23,520 KB
testcase_10 AC 37 ms
24,024 KB
testcase_11 AC 36 ms
24,216 KB
testcase_12 AC 36 ms
23,364 KB
testcase_13 AC 37 ms
23,940 KB
testcase_14 AC 36 ms
23,664 KB
testcase_15 AC 36 ms
23,400 KB
testcase_16 AC 37 ms
23,376 KB
testcase_17 AC 36 ms
23,496 KB
testcase_18 AC 35 ms
23,628 KB
testcase_19 AC 37 ms
24,348 KB
testcase_20 AC 36 ms
23,508 KB
testcase_21 AC 37 ms
23,340 KB
testcase_22 AC 37 ms
23,364 KB
testcase_23 AC 37 ms
23,412 KB
testcase_24 AC 37 ms
23,400 KB
testcase_25 AC 37 ms
23,616 KB
testcase_26 AC 37 ms
23,508 KB
testcase_27 AC 26 ms
24,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}
 
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

bool ask(int x, int y) {
	printf("? %d %d\n", x + 1, y + 1);
	fflush(stdout);
	int res;
	scanf("%d", &res); --res;
	return res == x;
}

void answer(int x) {
	printf("! %d\n", x + 1);
	fflush(stdout);
}

int w[310][310];

int rem(vi vec) {
	while (vec.size() >= 2) {
		vi nx;
		for (int i = 0; i < (int)vec.size() / 2; ++i) {
			int x = vec[i * 2];
			int y = vec[i * 2 + 1];
			bool f = ask(x, y);
			if (f) {
				w[x][y] = 1;
				w[y][x] = 0;
				nx.pb(x);
			} else {
				w[y][x] = 1;
				w[x][y] = 0;
				nx.pb(y);
			}
		}
		if (vec.size() & 1) {
			nx.pb(vec.back());
		}
		vec.swap(nx);
	}
	return vec[0];
}

int main() {
	int N; cin >> N;
	memset(w, -1, sizeof(w));

	vi vec; rep(i, N) vec.pb(i);

	int p = rem(vec);

	vi cand;
	rep(i, N) if (w[p][i] == 1) {
		cand.pb(i);
	}

	int q = rem(cand);
	answer(q);

	return 0;
}
0