結果

問題 No.850 企業コンテスト2位
ユーザー mugen_1337mugen_1337
提出日時 2021-04-02 13:15:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,829 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 210,000 KB
実行使用メモリ 24,528 KB
平均クエリ数 291.21
最終ジャッジ日時 2023-09-24 10:21:03
合計ジャッジ時間 7,782 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 24 ms
24,012 KB
testcase_02 AC 24 ms
23,796 KB
testcase_03 AC 25 ms
23,664 KB
testcase_04 AC 26 ms
23,424 KB
testcase_05 WA -
testcase_06 AC 25 ms
23,832 KB
testcase_07 AC 32 ms
23,784 KB
testcase_08 AC 34 ms
23,388 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 26 ms
24,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

int query(int a,int b){
    cout<<"? "<<a+1<<" "<<b+1<<endl;
    int res;
    cin>>res;res--;
    return res;
}

signed main(){
    int n;cin>>n;

    using P=pair<int,int>;
    priority_queue<P,vector<P>,greater<P>> que;

    vector<vector<int>> v(n);
    rep(i,n){
        v[i].push_back(i);
        que.emplace(1,i);
    }

    while(que.size()>1){
        auto lp=que.top();que.pop();
        auto rp=que.top();que.pop();

        int l=lp.second,r=rp.second;

        vector<int> nx;
        for(int i=0,j=0;i<v[l].size() or j<v[r].size();){
            if(nx.size()>=2) break;

            int win=-1;
            if(i==v[l].size()) win=v[r][j++];
            else if(j==v[r].size()) win=v[l][i++];
            else{
                win=query(v[l][i],v[r][j]);
                if(v[l][i]==win) i++;
                else             j++;
            }

            nx.push_back(win);
        }

        v[l]=nx;
        que.emplace(v[l].size(),l);
    }
    cout<<"! "<<(v[0][1]+1)<<endl;
    return 0;
}
0