結果

問題 No.1245 ANDORゲーム(calc)
ユーザー marroncastlemarroncastle
提出日時 2020-10-02 23:40:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 333 ms / 2,000 ms
コード長 698 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 100,740 KB
最終ジャッジ日時 2023-09-25 00:02:01
合計ジャッジ時間 8,890 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,212 KB
testcase_01 AC 72 ms
71,336 KB
testcase_02 AC 72 ms
71,380 KB
testcase_03 AC 73 ms
71,268 KB
testcase_04 AC 72 ms
71,088 KB
testcase_05 AC 72 ms
71,248 KB
testcase_06 AC 73 ms
71,172 KB
testcase_07 AC 113 ms
77,888 KB
testcase_08 AC 94 ms
76,960 KB
testcase_09 AC 113 ms
77,692 KB
testcase_10 AC 111 ms
77,680 KB
testcase_11 AC 328 ms
94,468 KB
testcase_12 AC 331 ms
96,204 KB
testcase_13 AC 330 ms
96,204 KB
testcase_14 AC 323 ms
96,852 KB
testcase_15 AC 332 ms
96,072 KB
testcase_16 AC 333 ms
96,240 KB
testcase_17 AC 304 ms
94,756 KB
testcase_18 AC 301 ms
95,148 KB
testcase_19 AC 294 ms
94,688 KB
testcase_20 AC 313 ms
94,856 KB
testcase_21 AC 316 ms
94,964 KB
testcase_22 AC 297 ms
96,520 KB
testcase_23 AC 323 ms
96,240 KB
testcase_24 AC 323 ms
94,768 KB
testcase_25 AC 236 ms
98,824 KB
testcase_26 AC 249 ms
100,740 KB
testcase_27 AC 288 ms
96,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, Q = map(int, input().split())
A = list(map(int, input().split()))
S = input()
lis = [[0]*31 for _ in range(2)]
q = 1
for p in range(31):
  score = 0
  r = q
  for i in range(N):
    u = A[i]&(1<<p)
    if S[i]=='0':
      s = r&u
    else:
      s = r|u
    score += abs(s-r)
    r = s
  lis[1][p] = score
  score = 0
  r = 0
  for i in range(N):
    u = A[i]&(1<<p)
    if S[i]=='0':
      s = r&u
    else:
      s = r|u
    score += abs(s-r)
    r = s
  lis[0][p] = score
  q <<= 1
ans = [0]*Q
T = list(map(int, input().split()))
for i in range(Q):
  t = T[i]
  for p in range(31):
    if t&(1<<p):
      ans[i] += lis[1][p]
    else:
      ans[i] += lis[0][p]
print(*ans, sep='\n')
    
    
0