結果

問題 No.3249 AND
ユーザー areik
提出日時 2025-08-29 23:48:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,262 bytes
コンパイル時間 3,433 ms
コンパイル使用メモリ 251,632 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-30 00:01:16
合計ジャッジ時間 5,275 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;

using i32 = int;
using i64 = long long;
using f64 = double;
using p2 = pair<i64, i64>;
using el = tuple<i64, i64, i64>;
using mint = atcoder::modint998244353;

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

i64 pow(i64 x, i64 n) {
  i64 res = 1;
  i64 t = x;
  while (n > 0) {
    if (n & 1) res *= t;
    t *= t;
    n >>= 1;
  }
  return res;
}
void _main() {
  i64 n;
  cin >> n;
  vector<i64> a(30, 1);
  bool ok = true;
  for (i64 i = 1; i <= n; i++) {
    i64 b;
    cin >> b;
    for (i64 j = 0; j < 30; j++) {
      i64 x = b >> j & 1, y = i >> j & 1;
      if (x == 1 && y == 0) ok = false;
      else if (x == 1 && y == 1) {
        if (a[j] == 0) ok = false;
        a[j] = 2;
      } else if (x == 0 && y == 1) {
        if (a[j] == 2) ok = false;
        a[j] = 0;
      }
    }
  }
  if (!ok) {
    cout << "-1\n";
    return;
  }
  i64 ans = 0;
  for (i64 i = 0; i < 30; i++) {
    if (a[i] == 2) ans |= 1ll << i;
  }
  if (ans == 0) {
    for (i64 i = 0; i < 30; i++) {
      if (a[i] == 1) {
        ans = 1ll << i;
        break;
      }
    }
    if (ans == 0) {
      cout << "-1\n";
      return;
    }
  }
  cout << ans << "\n";
}
0