結果

問題 No.130 XOR Minimax
ユーザー beetbeet
提出日時 2018-11-07 11:58:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 736 bytes
コンパイル時間 2,376 ms
コンパイル使用メモリ 205,320 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-10 00:23:44
合計ジャッジ時間 4,183 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 17 ms
4,372 KB
testcase_05 AC 44 ms
4,376 KB
testcase_06 AC 33 ms
4,376 KB
testcase_07 AC 45 ms
4,376 KB
testcase_08 AC 56 ms
4,376 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 11 ms
4,372 KB
testcase_11 AC 33 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 27 ms
4,372 KB
testcase_14 AC 52 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 37 ms
4,372 KB
testcase_17 AC 38 ms
4,372 KB
testcase_18 AC 41 ms
4,372 KB
testcase_19 AC 49 ms
4,376 KB
testcase_20 AC 24 ms
4,376 KB
testcase_21 AC 52 ms
4,372 KB
testcase_22 AC 12 ms
4,372 KB
testcase_23 AC 4 ms
4,372 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;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];

  sort(a.begin(),a.end());

  function<Int(Int, Int, Int)> dfs=
    [&](Int l,Int r,Int d)->Int{
      Int x=(a[l]>>d)&1,y=(a[r-1]>>d)&1;
      if(d==0) return x!=y;
      if(x==y) return dfs(l,r,d-1);
      Int m=lower_bound(a.begin(),a.end(),a[r-1]&~((1<<d)-1))-a.begin();
      assert(l<m&&m<r);
      return min(dfs(l,m,d-1),dfs(m,r,d-1))+(1<<d);
    };
  
  cout<<dfs(0,n,30)<<endl;
  return 0;
}
0