結果

問題 No.850 企業コンテスト2位
ユーザー beetbeet
提出日時 2019-07-05 22:37:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,221 bytes
コンパイル時間 2,210 ms
コンパイル使用メモリ 213,244 KB
実行使用メモリ 24,324 KB
平均クエリ数 200.11
最終ジャッジ日時 2023-09-23 17:32:55
合計ジャッジ時間 4,711 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,388 KB
testcase_01 AC 24 ms
23,352 KB
testcase_02 AC 23 ms
23,652 KB
testcase_03 AC 24 ms
23,388 KB
testcase_04 AC 24 ms
23,508 KB
testcase_05 AC 24 ms
24,252 KB
testcase_06 AC 24 ms
24,324 KB
testcase_07 AC 28 ms
23,352 KB
testcase_08 AC 29 ms
23,508 KB
testcase_09 AC 28 ms
23,496 KB
testcase_10 AC 34 ms
24,180 KB
testcase_11 AC 34 ms
23,964 KB
testcase_12 AC 34 ms
24,324 KB
testcase_13 AC 33 ms
23,388 KB
testcase_14 AC 34 ms
23,616 KB
testcase_15 AC 32 ms
24,240 KB
testcase_16 AC 34 ms
23,520 KB
testcase_17 AC 34 ms
23,640 KB
testcase_18 AC 32 ms
24,180 KB
testcase_19 AC 34 ms
23,796 KB
testcase_20 AC 34 ms
23,352 KB
testcase_21 AC 35 ms
23,808 KB
testcase_22 AC 34 ms
23,616 KB
testcase_23 AC 34 ms
24,288 KB
testcase_24 AC 34 ms
23,808 KB
testcase_25 AC 35 ms
24,024 KB
testcase_26 AC 34 ms
24,252 KB
testcase_27 AC 23 ms
23,388 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;
    if(G[l].empty()){
      G[i]=G[r];
      continue;
    }
    if(G[r].empty()){
      G[i]=G[l];
      continue;
    }
    if(!comp(G[l][0],G[r][0])) swap(l,r);
    G[i]=G[l];
    G[i].emplace_back(G[r][0]);
  }
  int ans=*min_element(G[1].begin()+1,G[1].end(),comp);
  cout<<"! "<<ans<<endl;
  return 0;
}
0