結果
問題 | No.850 企業コンテスト2位 |
ユーザー |
![]() |
提出日時 | 2019-07-05 21:58:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,030 bytes |
コンパイル時間 | 909 ms |
コンパイル使用メモリ | 78,260 KB |
実行使用メモリ | 25,476 KB |
平均クエリ数 | 202.79 |
最終ジャッジ日時 | 2024-07-16 17:18:28 |
合計ジャッジ時間 | 4,540 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 17 WA * 10 |
ソースコード
#include <vector>#include <iostream>#include <algorithm>using namespace std;vector<int> cand;int ask(int x, int y) {cout << "? " << x << ' ' << y << endl;int res;cin >> res;return res;}int solve(vector<int> v) {if (v.size() == 1) return v[0];if (v.size() % 2 == 1) {int cnt = 1;while (find(v.begin(), v.end(), cnt) != v.end()) ++cnt;v.push_back(cnt);}vector<int> pv;for (int i = 0; i < v.size(); i += 2) {int res = ask(v[i], v[i + 1]);if (res == v[i]) pv.push_back(v[i]);else pv.push_back(v[i + 1]);}int ans = solve(pv);cand.push_back(v[(find(v.begin(), v.end(), ans) - v.begin()) ^ 1]);return ans;}int main() {int N;cin >> N;vector<int> v;for (int i = 1; i <= N; ++i) {v.push_back(i);}solve(v);sort(cand.begin(), cand.end());cand.erase(unique(cand.begin(), cand.end()), cand.end());int cur = 0;for (int i = 1; i < cand.size(); ++i) {int res = ask(cand[cur], cand[i]);if (res == cand[i]) cur = i;}cout << "! " << cand[cur] << endl;return 0;}