結果

問題 No.130 XOR Minimax
ユーザー 👑 emthrmemthrm
提出日時 2020-01-14 13:13:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 1,553 bytes
コンパイル時間 2,088 ms
コンパイル使用メモリ 204,180 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-10 00:26:17
合計ジャッジ時間 3,765 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,356 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 10 ms
4,352 KB
testcase_05 AC 16 ms
4,352 KB
testcase_06 AC 13 ms
4,352 KB
testcase_07 AC 16 ms
4,352 KB
testcase_08 AC 31 ms
4,352 KB
testcase_09 AC 5 ms
4,348 KB
testcase_10 AC 7 ms
4,348 KB
testcase_11 AC 17 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 15 ms
4,352 KB
testcase_14 AC 33 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 24 ms
4,348 KB
testcase_17 AC 26 ms
4,352 KB
testcase_18 AC 27 ms
4,348 KB
testcase_19 AC 32 ms
4,348 KB
testcase_20 AC 16 ms
4,348 KB
testcase_21 AC 33 ms
4,356 KB
testcase_22 AC 8 ms
4,348 KB
testcase_23 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  sort(ALL(a));
  function<int(int, int, int)> solve = [&](int bit, int l, int r) {
    int i = l;
    for (; i < r; ++i) {
      if (a[i] >> bit & 1) break;
    }
    int res = 0;
    if (i == l || i == r) {
      if (bit - 1 >= 0) res = solve(bit - 1, l, r);
    } else {
      res += 1 << bit;
      if (bit - 1 >= 0) res += min(solve(bit - 1, l, i), solve(bit - 1, i, r));
    }
    return res;
  };
  cout << solve(29, 0, n) << '\n';
  return 0;
}
0