結果

問題 No.1245 ANDORゲーム(calc)
ユーザー wolgnikwolgnik
提出日時 2020-10-02 22:43:10
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 364 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 1,590 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 99,732 KB
最終ジャッジ日時 2023-09-24 22:06:26
合計ジャッジ時間 9,137 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,560 KB
testcase_01 AC 74 ms
71,224 KB
testcase_02 AC 72 ms
71,300 KB
testcase_03 AC 74 ms
71,136 KB
testcase_04 AC 72 ms
71,416 KB
testcase_05 AC 72 ms
71,532 KB
testcase_06 AC 73 ms
71,184 KB
testcase_07 AC 115 ms
77,996 KB
testcase_08 AC 99 ms
77,116 KB
testcase_09 AC 112 ms
78,052 KB
testcase_10 AC 110 ms
78,268 KB
testcase_11 AC 363 ms
97,524 KB
testcase_12 AC 364 ms
97,860 KB
testcase_13 AC 355 ms
97,660 KB
testcase_14 AC 364 ms
98,004 KB
testcase_15 AC 364 ms
97,956 KB
testcase_16 AC 361 ms
97,732 KB
testcase_17 AC 327 ms
97,816 KB
testcase_18 AC 315 ms
97,500 KB
testcase_19 AC 310 ms
97,600 KB
testcase_20 AC 331 ms
97,696 KB
testcase_21 AC 329 ms
97,484 KB
testcase_22 AC 310 ms
97,868 KB
testcase_23 AC 356 ms
97,484 KB
testcase_24 AC 339 ms
97,644 KB
testcase_25 AC 239 ms
99,608 KB
testcase_26 AC 241 ms
99,732 KB
testcase_27 AC 294 ms
97,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
a = list(map(int, input().split()))
S = list(input())[: -1]
t = list(map(int, input().split()))
table = [1 << i for i in range(31)]
table2 = [0] * 31
res = [0] * 31
res2 = [0] * 31
for i in range(31):
  x = 1 << i
  for k in range(N):
    old = table[i]
    if S[k] == "0": table[i] &= a[k] & x
    else: table[i] |= a[k] & x
    res[i] += abs(table[i] - old)
  for k in range(N):
    old = table2[i]
    if S[k] == "0": table2[i] &= a[k] & x
    else: table2[i] |= a[k] & x
    res2[i] += abs(table2[i] - old)

for q in t:
  resq = 0
  for i in range(31):
    x = 1 << i
    if q & x: resq += res[i]
    else: resq += res2[i]
  print(resq)
0