結果

問題 No.1245 ANDORゲーム(calc)
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-10-02 22:07:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 309 ms / 2,000 ms
コード長 942 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 102,236 KB
最終ジャッジ日時 2023-09-24 12:38:05
合計ジャッジ時間 8,496 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,236 KB
testcase_01 AC 67 ms
71,188 KB
testcase_02 AC 66 ms
70,980 KB
testcase_03 AC 65 ms
71,196 KB
testcase_04 AC 68 ms
71,220 KB
testcase_05 AC 65 ms
71,064 KB
testcase_06 AC 64 ms
71,200 KB
testcase_07 AC 92 ms
76,588 KB
testcase_08 AC 84 ms
76,812 KB
testcase_09 AC 92 ms
76,752 KB
testcase_10 AC 92 ms
76,812 KB
testcase_11 AC 291 ms
101,716 KB
testcase_12 AC 297 ms
102,236 KB
testcase_13 AC 305 ms
101,928 KB
testcase_14 AC 309 ms
101,960 KB
testcase_15 AC 292 ms
102,192 KB
testcase_16 AC 301 ms
101,748 KB
testcase_17 AC 285 ms
102,048 KB
testcase_18 AC 271 ms
102,144 KB
testcase_19 AC 274 ms
101,916 KB
testcase_20 AC 281 ms
101,812 KB
testcase_21 AC 276 ms
101,928 KB
testcase_22 AC 278 ms
102,116 KB
testcase_23 AC 290 ms
101,972 KB
testcase_24 AC 297 ms
101,936 KB
testcase_25 AC 217 ms
98,464 KB
testcase_26 AC 228 ms
98,916 KB
testcase_27 AC 253 ms
101,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/1245

各桁ごとに1の場合、0の場合で最後いくつになるかを計算しておけばいい

"""

from sys import stdin
import sys

N,Q = map(int,stdin.readline().split())

A = list(map(int,stdin.readline().split()))
S = stdin.readline()[:-1]

t = list(map(int,stdin.readline().split()))

d = [ [0,0] for i in range(32) ]

for x in range(30):

    fil = 2**x
    
    for y in range(2):

        now = fil * y
        ans = 0

        for i in range(N):

            if S[i] == "0":
                nex = (now & A[i]) & fil
            else:
                nex = (now | A[i]) & fil
            ans += abs(nex-now)
            now = nex

        d[x][y] = ans

#print (d)

ANS = []
for nt in t:

    now = 0
    for x in range(32):
        if (2**x) & nt > 0:
            now += d[x][1]
        else:
            now += d[x][0]
    ANS.append(now)

print ("\n".join(map(str,ANS)))
        

0