結果

問題 No.130 XOR Minimax
ユーザー takumi152takumi152
提出日時 2020-01-11 01:47:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 859 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 93,508 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-03 02:08:54
合計ジャッジ時間 3,081 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 91 ms
6,944 KB
testcase_05 AC 97 ms
6,944 KB
testcase_06 AC 119 ms
6,944 KB
testcase_07 WA -
testcase_08 AC 113 ms
6,940 KB
testcase_09 AC 16 ms
6,944 KB
testcase_10 AC 26 ms
6,944 KB
testcase_11 WA -
testcase_12 AC 8 ms
6,940 KB
testcase_13 AC 83 ms
6,940 KB
testcase_14 AC 101 ms
6,948 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 65 ms
6,944 KB
testcase_17 AC 68 ms
6,940 KB
testcase_18 AC 75 ms
6,940 KB
testcase_19 AC 98 ms
6,944 KB
testcase_20 AC 39 ms
6,940 KB
testcase_21 AC 99 ms
6,940 KB
testcase_22 WA -
testcase_23 AC 6 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x: a) cin >> x;

  for (int i = (1 << 30); i > 0; i >>= 1) {
    sort(a.rbegin(), a.rend());
    vector<int> flipV = a;
    for (auto &x: flipV) x ^= i;
    sort(flipV.rbegin(), flipV.rend());
    bool shouldFlip = false;
    for (int j = 0; j < n; j++) {
      if (a[j] < flipV[j]) break;
      else if (a[j] > flipV[j]) {
        shouldFlip = true;
        break;
      }
    }
    if (shouldFlip) a = flipV;
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > ans) ans = a[i];
  }

  cout << ans << endl;

  return 0;
}
0