結果

問題 No.3249 AND
コンテスト
ユーザー dp_ijk
提出日時 2025-08-29 22:43:35
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 149 ms / 2,000 ms
+ 610µs
コード長 749 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 245 ms
コンパイル使用メモリ 96,360 KB
実行使用メモリ 123,648 KB
最終ジャッジ日時 2026-07-14 14:22:52
合計ジャッジ時間 4,743 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def solve(N, A):
   if all(a == 0 for a in A):
      return 1<<int.bit_length(N)

   def resolve(e):
      I = [(i>>e)&1 for i in range(1, N+1)]
      B = [(a>>e)&1 for a in A]
      ng = [0, 0]
      for i, b in zip(I, B):
         if i == 0 and b == 1:
            ng[0] = ng[1] = 1
         if i == 1 and b == 0:
            ng[1] = 1
         if i == 1 and b == 1:
            ng[0] = 1
      if not ng[0]:
         return 0
      if not ng[1]:
         return 1
      return -1

   maxbitlen = int.bit_length(max(N, max(A))) + 2
   res = 0
   for e in range(maxbitlen):
      x = resolve(e)
      if x == -1:
         return -1
      res |= x<<e
   return res


N = int(input())
A = list(map(int, input().split()))
ans = solve(N, A)
print(ans)
0