結果
問題 | No.850 企業コンテスト2位 |
ユーザー | face4 |
提出日時 | 2019-07-08 23:05:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 32 ms / 2,000 ms |
コード長 | 967 bytes |
コンパイル時間 | 930 ms |
コンパイル使用メモリ | 72,276 KB |
実行使用メモリ | 25,220 KB |
平均クエリ数 | 200.11 |
最終ジャッジ日時 | 2024-07-16 17:44:18 |
合計ジャッジ時間 | 3,099 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 27 |
ソースコード
#include<iostream> #include<vector> using namespace std; vector<int> defeat[300]; int ask(int x, int y){ cout << "? " << x << " " << y << endl << flush; int ret; cin >> ret; if(ret == x) defeat[x].push_back(y); else defeat[y].push_back(x); return ret; } void answer(int x){ cout << "! " << x << endl << flush; } void shrink(vector<int> &a){ while(a.size() > 2){ vector<int> b; int pos = 0; while(pos+1 < a.size()){ b.push_back(ask(a[pos], a[pos+1])); pos += 2; } if(pos < a.size()) b.push_back(a[pos]); a = b; } } int main(){ int n; cin >> n; vector<int> a; for(int i = 1; i <= n; i++) a.push_back(i); shrink(a); int top = ask(a[0], a[1]); shrink(defeat[top]); if(defeat[top].size() == 1){ answer(defeat[top][0]); }else{ answer(ask(defeat[top][0], defeat[top][1])); } return 0; }