結果
問題 | No.850 企業コンテスト2位 |
ユーザー |
|
提出日時 | 2019-07-05 23:22:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 1,291 bytes |
コンパイル時間 | 2,061 ms |
コンパイル使用メモリ | 174,816 KB |
実行使用メモリ | 25,604 KB |
平均クエリ数 | 200.11 |
最終ジャッジ日時 | 2024-07-16 17:34:20 |
合計ジャッジ時間 | 4,892 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) using namespace std; using ll = long long; int cnt; #ifdef DEBUG int a[300]; bool lt(int x, int y) { cnt++; return a[x] > a[y]; } #else bool lt(int x, int y) { cnt++; cout << "? " << x+1 << ' ' << y+1 << endl; int res; cin >> res; return res == y+1 ? 1 : 0; } #endif int main() { // cin.tie(nullptr); // ios::sync_with_stdio(false); mt19937 mt(123); #ifdef DEBUG rep(i, 300) a[i] = i; int n = 300; #else int n; cin >> n; #endif vector<int> ord(n); rep(i, n) ord[i] = i; vector<vector<int>> win(n); while (ord.size() >= 2) { vector<int> next; for (int i = 0; i + 1 < ord.size(); i += 2) { if (lt(ord[i], ord[i + 1])) { next.push_back(ord[i + 1]); win[ord[i + 1]].push_back(ord[i]); } else { next.push_back(ord[i]); win[ord[i]].push_back(ord[i + 1]); } } if (ord.size() % 2 == 1) { next.push_back(ord.back()); } ord = next; } int x = ord[0]; int second = win[x][0]; for (int i = 1; i < win[x].size(); i++) { if (lt(second, win[x][i])) { second = win[x][i]; } } cout << "! " << second+1 << endl; cerr << cnt << endl; }