結果

問題 No.1296 OR or NOR
ユーザー 👑 Kiri8128Kiri8128
提出日時 2020-06-25 23:50:08
言語 PyPy3
(7.9.16)
結果
AC  
実行時間 748 ms / 3,000 ms
コード長 762 bytes
コンパイル時間 904 ms
実行使用メモリ 136,892 KB
最終ジャッジ日時 2023-01-18 20:42:27
合計ジャッジ時間 19,351 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
75,732 KB
testcase_01 AC 81 ms
75,764 KB
testcase_02 AC 367 ms
117,360 KB
testcase_03 AC 365 ms
117,468 KB
testcase_04 AC 502 ms
119,832 KB
testcase_05 AC 480 ms
119,760 KB
testcase_06 AC 422 ms
136,684 KB
testcase_07 AC 407 ms
135,748 KB
testcase_08 AC 389 ms
136,324 KB
testcase_09 AC 400 ms
124,444 KB
testcase_10 AC 420 ms
125,276 KB
testcase_11 AC 377 ms
117,356 KB
testcase_12 AC 374 ms
118,248 KB
testcase_13 AC 389 ms
119,564 KB
testcase_14 AC 748 ms
123,692 KB
testcase_15 AC 560 ms
119,532 KB
testcase_16 AC 452 ms
110,516 KB
testcase_17 AC 375 ms
135,552 KB
testcase_18 AC 386 ms
136,892 KB
testcase_19 AC 406 ms
136,224 KB
testcase_20 AC 318 ms
108,152 KB
testcase_21 AC 325 ms
108,344 KB
testcase_22 AC 222 ms
108,424 KB
testcase_23 AC 230 ms
108,392 KB
testcase_24 AC 288 ms
108,144 KB
testcase_25 AC 294 ms
108,308 KB
testcase_26 AC 333 ms
108,192 KB
testcase_27 AC 334 ms
108,080 KB
testcase_28 AC 320 ms
108,120 KB
testcase_29 AC 302 ms
107,892 KB
testcase_30 AC 664 ms
119,424 KB
testcase_31 AC 670 ms
119,660 KB
testcase_32 AC 693 ms
119,832 KB
testcase_33 AC 512 ms
119,984 KB
testcase_34 AC 513 ms
119,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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