結果
| 問題 |
No.1245 ANDORゲーム(calc)
|
| コンテスト | |
| ユーザー |
tamato
|
| 提出日時 | 2020-10-02 22:41:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 314 ms / 2,000 ms |
| コード長 | 1,332 bytes |
| コンパイル時間 | 138 ms |
| コンパイル使用メモリ | 82,812 KB |
| 実行使用メモリ | 99,940 KB |
| 最終ジャッジ日時 | 2024-07-17 22:25:38 |
| 合計ジャッジ時間 | 6,972 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
mod = 1000000007
eps = 10**-9
def main():
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
A = list(map(int, input().split()))
S = input().rstrip('\n')
T = list(map(int, input().split()))
zero = [0] * 31
one = [0] * 31
# zero start
cur = [0] * 31
for i in range(N):
a = A[i]
for j in range(31):
aj = a >> j & 1
if S[i] == "0":
if cur[j] == 1 and aj == 0:
zero[j] += 1 << j
cur[j] = cur[j] & aj
else:
if cur[j] == 0 and aj == 1:
zero[j] += 1 << j
cur[j] = cur[j] | aj
# one start
cur = [1] * 31
for i in range(N):
a = A[i]
for j in range(31):
aj = a >> j & 1
if S[i] == "0":
if cur[j] == 1 and aj == 0:
one[j] += 1 << j
cur[j] = cur[j] & aj
else:
if cur[j] == 0 and aj == 1:
one[j] += 1 << j
cur[j] = cur[j] | aj
for t in T:
ans = 0
for j in range(31):
if t >> j & 1:
ans += one[j]
else:
ans += zero[j]
print(ans)
if __name__ == '__main__':
main()
tamato