結果

問題 No.1245 ANDORゲーム(calc)
ユーザー rlangevin
提出日時 2023-03-22 08:58:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 576 bytes
コンパイル時間 119 ms
コンパイル使用メモリ 82,136 KB
実行使用メモリ 98,972 KB
最終ジャッジ日時 2024-09-18 14:44:40
合計ジャッジ時間 8,303 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

N, Q = map(int, input().split())
A = list(map(int, input().split()))
S = list(input())
S = list(map(int, S))
T = list(map(int, input().split()))

M = 35
L = [[0] * 2 for i in range(M)]
for i in range(M):
    for j in range(2):
        now = j
        for n in range(N):
            a = (A[n] >> i) & 1
            if S[n]:
                nex = now | a
            else:
                nex = now & a
            L[i][j] += nex ^ now
            now = nex

for t in T:
    ans = 0
    for i in range(M):
        ans += (1 << i) * L[i][(t >> i) & 1]
            
    print(ans)
0