結果

問題 No.1296 OR or NOR
ユーザー Kiri8128Kiri8128
提出日時 2020-06-25 23:50:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 679 ms / 3,000 ms
コード長 762 bytes
コンパイル時間 960 ms
コンパイル使用メモリ 86,648 KB
実行使用メモリ 131,840 KB
最終ジャッジ日時 2023-09-02 14:18:04
合計ジャッジ時間 19,078 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
70,868 KB
testcase_01 AC 86 ms
71,192 KB
testcase_02 AC 294 ms
105,256 KB
testcase_03 AC 298 ms
115,156 KB
testcase_04 AC 427 ms
106,064 KB
testcase_05 AC 409 ms
105,988 KB
testcase_06 AC 366 ms
131,476 KB
testcase_07 AC 633 ms
131,840 KB
testcase_08 AC 323 ms
122,364 KB
testcase_09 AC 330 ms
113,024 KB
testcase_10 AC 335 ms
114,604 KB
testcase_11 AC 295 ms
104,604 KB
testcase_12 AC 290 ms
104,340 KB
testcase_13 AC 313 ms
110,592 KB
testcase_14 AC 679 ms
114,680 KB
testcase_15 AC 493 ms
106,012 KB
testcase_16 AC 408 ms
106,152 KB
testcase_17 AC 287 ms
122,212 KB
testcase_18 AC 299 ms
122,812 KB
testcase_19 AC 317 ms
122,528 KB
testcase_20 AC 258 ms
102,316 KB
testcase_21 AC 255 ms
102,956 KB
testcase_22 AC 155 ms
103,080 KB
testcase_23 AC 167 ms
103,036 KB
testcase_24 AC 230 ms
102,876 KB
testcase_25 AC 233 ms
103,104 KB
testcase_26 AC 265 ms
103,248 KB
testcase_27 AC 268 ms
102,880 KB
testcase_28 AC 254 ms
103,268 KB
testcase_29 AC 243 ms
102,108 KB
testcase_30 AC 575 ms
106,104 KB
testcase_31 AC 577 ms
106,136 KB
testcase_32 AC 594 ms
105,992 KB
testcase_33 AC 448 ms
116,020 KB
testcase_34 AC 451 ms
116,108 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