結果

問題 No.850 企業コンテスト2位
ユーザー ttttan2ttttan2
提出日時 2019-07-05 23:03:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,918 bytes
コンパイル時間 2,414 ms
コンパイル使用メモリ 148,416 KB
実行使用メモリ 24,348 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-23 17:38:09
合計ジャッジ時間 4,828 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,628 KB
testcase_01 AC 25 ms
23,568 KB
testcase_02 AC 25 ms
24,216 KB
testcase_03 AC 25 ms
24,252 KB
testcase_04 AC 25 ms
23,628 KB
testcase_05 AC 25 ms
23,568 KB
testcase_06 AC 25 ms
23,508 KB
testcase_07 AC 30 ms
24,024 KB
testcase_08 AC 31 ms
23,652 KB
testcase_09 AC 31 ms
23,940 KB
testcase_10 AC 37 ms
24,240 KB
testcase_11 AC 36 ms
24,240 KB
testcase_12 AC 36 ms
23,364 KB
testcase_13 AC 35 ms
23,628 KB
testcase_14 AC 35 ms
23,628 KB
testcase_15 AC 35 ms
23,928 KB
testcase_16 AC 35 ms
24,240 KB
testcase_17 AC 36 ms
24,036 KB
testcase_18 AC 35 ms
23,568 KB
testcase_19 AC 35 ms
23,484 KB
testcase_20 AC 35 ms
24,216 KB
testcase_21 AC 36 ms
23,880 KB
testcase_22 AC 35 ms
23,784 KB
testcase_23 AC 36 ms
23,508 KB
testcase_24 AC 36 ms
23,364 KB
testcase_25 AC 34 ms
24,348 KB
testcase_26 AC 35 ms
23,340 KB
testcase_27 AC 25 ms
23,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll n,k,m;
vector<ll> pri;
bool prijud(ll n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return true;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    int d[n+1];
    fill(d,d+n+1,-1);
    int cnt=0;
    int win=0;
    for(;;){
        if(cnt==n-1)break;
        int now=0;
        rep(i,1,n+1){
            if(d[i]>0)continue;
            if(now==0)now=i;
            else{
                cout<<"? "<<now<<" "<<i<<endl;
                int y;cin>>y;
                win=y;
                if(y==now)d[i]=now;
                else d[now]=i;
                now=0;
                cnt++;
            }
        }
    }
    vector<int> v;
    rep(i,1,n+1){
        if(d[i]==win)v.push_back(i);
    }
    int m=v.size();
    int e[m];
    fill(e,e+m,-1);
    win=0;
    cnt=0;
    if(m==1){
        cout<<"! "<<v[0]<<endl;
        return 0;
    }
    for(;;){
        if(cnt==m-1)break;
        int now=-1;
        rep(i,0,m){
            if(e[i]>=0)continue;
            if(now==-1)now=i;
            else{
                cout<<"? "<<v[now]<<" "<<v[i]<<endl;
                int y;cin>>y;
                win=y;
                if(y==v[now])e[i]=now;
                else e[now]=i;
                now=-1;
                cnt++;
            }
        }
    }
    cout<<"! "<<win<<endl;
}
0