結果

問題 No.850 企業コンテスト2位
ユーザー erbowlerbowl
提出日時 2019-07-23 22:45:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,675 bytes
コンパイル時間 1,531 ms
コンパイル使用メモリ 171,588 KB
実行使用メモリ 24,336 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-23 17:56:30
合計ジャッジ時間 4,008 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,616 KB
testcase_01 AC 23 ms
24,000 KB
testcase_02 AC 24 ms
23,508 KB
testcase_03 AC 22 ms
23,400 KB
testcase_04 AC 24 ms
23,508 KB
testcase_05 AC 23 ms
23,628 KB
testcase_06 AC 23 ms
23,340 KB
testcase_07 AC 28 ms
23,388 KB
testcase_08 AC 30 ms
24,216 KB
testcase_09 AC 27 ms
23,340 KB
testcase_10 AC 34 ms
23,616 KB
testcase_11 AC 33 ms
24,120 KB
testcase_12 AC 34 ms
23,376 KB
testcase_13 AC 32 ms
23,808 KB
testcase_14 AC 34 ms
23,640 KB
testcase_15 AC 33 ms
23,976 KB
testcase_16 AC 33 ms
23,604 KB
testcase_17 AC 34 ms
24,000 KB
testcase_18 AC 32 ms
23,640 KB
testcase_19 AC 34 ms
24,024 KB
testcase_20 AC 33 ms
23,340 KB
testcase_21 AC 33 ms
23,352 KB
testcase_22 AC 33 ms
23,652 KB
testcase_23 AC 33 ms
24,336 KB
testcase_24 AC 32 ms
23,988 KB
testcase_25 AC 34 ms
23,388 KB
testcase_26 AC 33 ms
23,604 KB
testcase_27 AC 24 ms
23,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n;
    std::cin >> n;
    // トーナメントを行って1位と戦って負けたやつの中で一番強いやつ
    vector<ll> next;
    for (int i = 1; i <= n; i++) {
        next.push_back(i);
    }
    vector<ll> list[400];
    while(next.size()!=1){
        vector<ll> next_next;
        for (int i = 0; i < next.size()/2; i++) {
            std::cout << "? "<<next[i*2]<<" "<<next[i*2+1]<< std::endl;
            list[next[i*2]].push_back(next[i*2+1]);
            list[next[i*2+1]].push_back(next[i*2]);
            ll tmp;
            std::cin >> tmp;
            next_next.push_back(tmp);
        }
        if(next.size()%2==1){
            ll a,b;
            a = next_next[next_next.size()-1];
            next_next.erase(next_next.begin()+next_next.size()-1);
            b = next[next.size()-1];
            list[a].push_back(b);
            list[b].push_back(a);
            std::cout << "? "<<a<<" "<<b<< std::endl;
            ll tmp;
            std::cin >> tmp;
            next_next.push_back(tmp);
        }
        next.clear();
        for (auto e : next_next) {
            next.push_back(e);
        }
    }
    ll win = next[0];
    ll now = list[win][0];
    for (int i = 1; i < list[win].size(); i++) {
        std::cout << "? "<<now<<" "<<list[win][i]<< std::endl;
        ll tmp;
        std::cin >> tmp;
        now = tmp;
    }
    std::cout << "! "<<now << std::endl;
}
0