結果

問題 No.1245 ANDORゲーム(calc)
ユーザー 👑 tamatotamato
提出日時 2020-10-02 22:41:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 371 ms / 2,000 ms
コード長 1,332 bytes
コンパイル時間 1,568 ms
コンパイル使用メモリ 86,820 KB
実行使用メモリ 98,448 KB
最終ジャッジ日時 2023-09-24 22:03:18
合計ジャッジ時間 9,433 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,580 KB
testcase_01 AC 71 ms
71,572 KB
testcase_02 AC 71 ms
71,444 KB
testcase_03 AC 72 ms
71,804 KB
testcase_04 AC 72 ms
71,736 KB
testcase_05 AC 72 ms
71,616 KB
testcase_06 AC 71 ms
71,832 KB
testcase_07 AC 119 ms
78,420 KB
testcase_08 AC 113 ms
77,948 KB
testcase_09 AC 117 ms
78,112 KB
testcase_10 AC 118 ms
78,512 KB
testcase_11 AC 332 ms
96,400 KB
testcase_12 AC 332 ms
96,440 KB
testcase_13 AC 371 ms
96,248 KB
testcase_14 AC 331 ms
96,404 KB
testcase_15 AC 360 ms
96,476 KB
testcase_16 AC 333 ms
96,416 KB
testcase_17 AC 305 ms
96,280 KB
testcase_18 AC 297 ms
96,268 KB
testcase_19 AC 300 ms
96,300 KB
testcase_20 AC 325 ms
96,304 KB
testcase_21 AC 301 ms
96,348 KB
testcase_22 AC 301 ms
96,240 KB
testcase_23 AC 316 ms
96,164 KB
testcase_24 AC 307 ms
96,584 KB
testcase_25 AC 206 ms
98,448 KB
testcase_26 AC 209 ms
98,340 KB
testcase_27 AC 293 ms
95,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0