結果
問題 | No.850 企業コンテスト2位 |
ユーザー |
![]() |
提出日時 | 2019-07-05 22:36:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 36 ms / 2,000 ms |
コード長 | 937 bytes |
コンパイル時間 | 2,251 ms |
コンパイル使用メモリ | 175,308 KB |
実行使用メモリ | 25,604 KB |
平均クエリ数 | 200.11 |
最終ジャッジ日時 | 2024-07-16 17:24:57 |
合計ジャッジ時間 | 4,523 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; using lint = long long; template<class T = int> using V = vector<T>; template<class T = int> using VV = V< V<T> >; int main() { int n; cin >> n; auto fn = [&](V<> id) -> VV<> { VV<> v{id}; while (id.size() >= 2) { int m = id.size(); V<> nid; for (int i = 0; i < m; i += 2) { if (i + 1 < m) { cout << "? " << id[i] << ' ' << id[i + 1] << endl; int x; cin >> x; nid.push_back(x); } else nid.push_back(id[i]); } swap(id, nid); v.push_back(id); } return v; }; V<> id(n); iota(begin(id), end(id), 1); auto v = fn(id); int x = v.back().back(); V<>().swap(id); for (const auto& e : v) { int m = e.size(); for (int i = 0; i < m; ++i) if (e[i] == x) { if ((i ^ 1) < m) id.push_back(e[i ^ 1]); } } int res = fn(id).back().back(); cout << "! " << res << endl; }