結果

問題 No.2085 Directed Complete Graph
ユーザー vjudge1
提出日時 2025-09-15 20:29:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 942 bytes
コンパイル時間 1,778 ms
コンパイル使用メモリ 198,440 KB
実行使用メモリ 25,972 KB
平均クエリ数 2464.59
最終ジャッジ日時 2025-09-15 20:29:48
合計ジャッジ時間 5,460 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
struct node {
	int s, t;
};
int n, pre[505], nxt[505];
bool query(int x, int y) {
	cout << "? " << x << ' ' << y << endl, cin >> x;
	return x;
}
node f(int l, int r) {
	if(l == r)
		return {l, l};
	int mid = l + r >> 1;
	auto x = f(l, mid), y = f(mid + 1, r);
	vector<int> a, b;
	for(int i = x.s; i; i = nxt[i])
		a.push_back(i);
	for(int i = y.s; i; i = nxt[i])
		b.push_back(i);
	for(; a.size() && b.size();)
		if(a.size() && (!b.size() || query(b.back(), a.back())))
			pre[nxt[a.back()] = nxt[b.back()]] = a.back(), pre[nxt[b.back()] = a.back()] = b.back(), a.pop_back();
		else
			pre[nxt[b.back()] = nxt[a.back()]] = b.back(), pre[nxt[a.back()] = b.back()] = a.back(), b.pop_back();
	return {pre[y.s] ? x.s : y.s, nxt[y.t] ? x.t : y.t};
}
int main() {
	cin >> n;
	auto res = f(1, n);
	cout << '!' << endl << n - 1 << endl;
	for(int i = res.s; i; i = nxt[i])
		cout << i << ' ';
	return 0;
}
0