結果

問題 No.1245 ANDORゲーム(calc)
ユーザー tktk_snsntktk_snsn
提出日時 2020-10-02 22:28:20
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 412 ms / 2,000 ms
コード長 895 bytes
コンパイル時間 716 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 116,292 KB
最終ジャッジ日時 2023-09-24 21:34:22
合計ジャッジ時間 10,317 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,352 KB
testcase_01 AC 73 ms
71,320 KB
testcase_02 AC 72 ms
71,220 KB
testcase_03 AC 70 ms
71,316 KB
testcase_04 AC 73 ms
71,300 KB
testcase_05 AC 73 ms
71,516 KB
testcase_06 AC 73 ms
71,448 KB
testcase_07 AC 120 ms
77,936 KB
testcase_08 AC 106 ms
78,128 KB
testcase_09 AC 120 ms
77,684 KB
testcase_10 AC 115 ms
77,704 KB
testcase_11 AC 412 ms
102,348 KB
testcase_12 AC 392 ms
101,680 KB
testcase_13 AC 394 ms
101,540 KB
testcase_14 AC 407 ms
100,808 KB
testcase_15 AC 394 ms
101,504 KB
testcase_16 AC 392 ms
101,232 KB
testcase_17 AC 369 ms
101,388 KB
testcase_18 AC 353 ms
101,520 KB
testcase_19 AC 351 ms
100,980 KB
testcase_20 AC 371 ms
101,456 KB
testcase_21 AC 360 ms
101,668 KB
testcase_22 AC 352 ms
101,560 KB
testcase_23 AC 383 ms
100,652 KB
testcase_24 AC 386 ms
101,520 KB
testcase_25 AC 235 ms
116,292 KB
testcase_26 AC 285 ms
100,812 KB
testcase_27 AC 333 ms
101,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, q = map(int, input().split())
A = list(map(int, input().split()))
S = input()
T = list(map(int, input().split()))

memo0 = []
memo1 = []

for i in range(32):
    vals = [(a >> i) & 1 for a in A]
    weight = 1 << i
    # i番目のbitが0のとき
    x = 0
    score = 0
    for s, v in zip(S, vals):
        if s == "0":
            xx = x & v
        else:
            xx = x | v
        if xx != x:
            score += weight
            x = xx
    memo0.append(score)

    # i番目のbitが1のとき
    x = 1
    score = 0
    for s, v in zip(S, vals):
        if s == "0":
            xx = x & v
        else:
            xx = x | v
        if xx != x:
            score += weight
            x = xx
    memo1.append(score)

for t in T:
    ans = 0
    for i in range(32):
        if (t >> i) & 1:
            ans += memo1[i]
        else:
            ans += memo0[i]
    print(ans)
0