結果
問題 |
No.3249 AND
|
ユーザー |
![]() |
提出日時 | 2025-08-29 22:43:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 198 ms / 2,000 ms |
コード長 | 749 bytes |
コンパイル時間 | 257 ms |
コンパイル使用メモリ | 82,088 KB |
実行使用メモリ | 110,948 KB |
最終ジャッジ日時 | 2025-09-05 11:40:06 |
合計ジャッジ時間 | 5,382 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 23 |
ソースコード
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)