結果

問題 No.130 XOR Minimax
ユーザー kk
提出日時 2021-02-26 19:45:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 125 ms / 5,000 ms
コード長 630 bytes
コンパイル時間 1,927 ms
コンパイル使用メモリ 201,332 KB
実行使用メモリ 53,416 KB
最終ジャッジ日時 2024-04-10 10:21:06
合計ジャッジ時間 4,617 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 63 ms
53,288 KB
testcase_05 AC 72 ms
53,416 KB
testcase_06 AC 56 ms
29,984 KB
testcase_07 AC 59 ms
29,232 KB
testcase_08 AC 125 ms
9,472 KB
testcase_09 AC 13 ms
7,168 KB
testcase_10 AC 18 ms
9,472 KB
testcase_11 AC 57 ms
25,768 KB
testcase_12 AC 7 ms
6,940 KB
testcase_13 AC 48 ms
21,444 KB
testcase_14 AC 116 ms
8,840 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 84 ms
6,944 KB
testcase_17 AC 88 ms
7,068 KB
testcase_18 AC 95 ms
7,648 KB
testcase_19 AC 112 ms
8,496 KB
testcase_20 AC 56 ms
6,940 KB
testcase_21 AC 119 ms
8,692 KB
testcase_22 AC 28 ms
6,940 KB
testcase_23 AC 10 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

long long dfs(vector<long long> a, int d = 1<<30) {
  vector<long long> b, c;
  for (long long x: a) {
    if (x & d)
      b.push_back(x ^ d);
    else
      c.push_back(x);
  }

  if (d == 1) return (b.size() && c.size()) ? 1 : 0;
  if (!c.size()) return dfs(b, d>>1);
  if (!b.size()) return dfs(c, d>>1);
  
  long long ret = min(dfs(b, d>>1), dfs(c, d>>1));
  return d | ret;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  cout << dfs(a) << endl;
  
  return 0;
}
0