結果

問題 No.1245 ANDORゲーム(calc)
ユーザー tktk_snsn
提出日時 2020-10-02 22:28:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 377 ms / 2,000 ms
コード長 895 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 113,832 KB
最終ジャッジ日時 2024-07-17 21:59:04
合計ジャッジ時間 9,061 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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