結果

問題 No.850 企業コンテスト2位
ユーザー beetbeet
提出日時 2019-07-05 22:19:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,207 bytes
コンパイル時間 2,241 ms
コンパイル使用メモリ 212,768 KB
実行使用メモリ 24,384 KB
平均クエリ数 228.25
最終ジャッジ日時 2023-09-23 17:29:31
合計ジャッジ時間 9,694 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
23,616 KB
testcase_01 AC 23 ms
23,496 KB
testcase_02 AC 23 ms
23,556 KB
testcase_03 AC 24 ms
24,348 KB
testcase_04 AC 24 ms
23,508 KB
testcase_05 AC 23 ms
23,628 KB
testcase_06 AC 24 ms
23,976 KB
testcase_07 AC 30 ms
23,988 KB
testcase_08 AC 32 ms
23,592 KB
testcase_09 AC 34 ms
23,964 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 24 ms
23,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  using P = pair<int, int>;
  map<P, int> memo;
  int cnt=0;
  auto comp=[&](int x,int y)->bool{
              if(x==y) return false;
              if(memo.count(P(x,y))) return memo[P(x,y)];
              if(memo.count(P(y,x))) return !memo[P(y,x)];
              cnt++;
              assert(cnt<=334);
              cout<<"? "<<x<<" "<<y<<endl;
              int ans;
              cin>>ans;
              return (memo[P(x,y)]=(ans==x));
            };

  const int MAX = 512;
  vector< vector<int> > G(MAX<<1);
  for(int i=0;i<n;i++) G[MAX+i].emplace_back(i+1);
  for(int i=MAX-1;i;i--){
    int l=(i<<1)|0;
    int r=(i<<1)|1;
    //cout<<":::"<<i<<" "<<l<<" "<<r<<endl;
    if(G[l].empty()){
      G[i]=G[r];
      continue;
    }
    if(G[r].empty()){
      G[i]=G[l];
      continue;
    }
    if(G[l].size()==1u&&G[r].size()==1u){
      int p=G[l][0];
      int q=G[r][0];
      if(comp(p,q)){
        G[i].emplace_back(p);
        G[i].emplace_back(q);
      }else{
        G[i].emplace_back(q);
        G[i].emplace_back(p);
      }
      continue;
    }
    if(G[l].size()<G[r].size()) swap(l,r);
    assert(G[l].size()==2u);
    int p=G[l][0];
    int s=G[l][1];
    if(G[r].size()==1u){
      int q=G[r][0];
      if(comp(p,q)){
        G[i].emplace_back(p);
        if(comp(q,s)){
          G[i].emplace_back(q);
        }else{
          G[i].emplace_back(s);
        }
      }else{
        G[i].emplace_back(q);
        G[i].emplace_back(p);
      }
    }else{
      assert(G[r].size()==2u);
      int q=G[r][0];
      int t=G[r][1];
      if(comp(p,q)){
        G[i].emplace_back(p);
        if(comp(q,s)){
          G[i].emplace_back(q);
        }else{
          G[i].emplace_back(s);
        }
      }else{
        G[i].emplace_back(q);
        if(comp(p,t)){
          G[i].emplace_back(p);
        }else{
          G[i].emplace_back(t);
        }
      }
    }
  }
  cout<<"! "<<G[1][1]<<endl;
  return 0;
}
0