結果

問題 No.1245 ANDORゲーム(calc)
ユーザー tktk_snsntktk_snsn
提出日時 2020-10-02 22:25:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 895 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 15,328 KB
最終ジャッジ日時 2023-09-24 21:26:59
合計ジャッジ時間 5,131 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,284 KB
testcase_01 AC 17 ms
7,788 KB
testcase_02 AC 17 ms
7,744 KB
testcase_03 AC 17 ms
7,912 KB
testcase_04 AC 18 ms
7,768 KB
testcase_05 AC 17 ms
7,852 KB
testcase_06 AC 17 ms
7,808 KB
testcase_07 AC 92 ms
8,596 KB
testcase_08 AC 38 ms
8,292 KB
testcase_09 AC 83 ms
8,588 KB
testcase_10 AC 81 ms
8,544 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

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が0のとき
    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