結果
| 問題 |
No.1245 ANDORゲーム(calc)
|
| コンテスト | |
| ユーザー |
👑 SPD_9X2
|
| 提出日時 | 2020-10-02 22:07:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 292 ms / 2,000 ms |
| コード長 | 942 bytes |
| コンパイル時間 | 148 ms |
| コンパイル使用メモリ | 82,364 KB |
| 実行使用メモリ | 100,768 KB |
| 最終ジャッジ日時 | 2024-07-17 13:33:08 |
| 合計ジャッジ時間 | 7,524 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
"""
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)))
SPD_9X2