結果

問題 No.1296 OR or NOR
コンテスト
ユーザー Kiri8128
提出日時 2020-06-25 23:50:08
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 538 ms / 3,000 ms
コード長 762 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 166 ms
コンパイル使用メモリ 85,480 KB
実行使用メモリ 123,800 KB
最終ジャッジ日時 2026-03-05 03:03:09
合計ジャッジ時間 13,312 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def calc(n, adj=0):
    ret = 0
    f = adj
    for e in E:
        if n ^ e < n:
            n ^= e
            ret += f
            f = 0
        else:
            ret += f ^ 1
            f = 1
    ret += f
    return 100 if n else ret

N = int(input())
A = [int(a) for a in input().split()]

m = (1 << 60) - 1
s = m
E = []
for a in A[1:][::-1]:
    t = s & a
    for e in E:
        t = min(t, t ^ e)
    if t: E.append(t)
    s &= a ^ m

s &= A[0]
Q = int(input())
L = [int(a) for a in input().split()]
for b in L:
    t = min(calc(b ^ s), calc(b ^ s ^ m, 1))
    print(-1 if t > 99 else t)

assert 1 <= N <= 200000
assert len(A) == N
for a in A:
    assert 0 <= a < 1 << 60
assert 1 <= Q <= 200000
assert len(L) == Q
for b in L:
    assert 0 <= b < 1 << 60
0