結果

問題 No.1209 XOR Into You
ユーザー salmon0852salmon0852
提出日時 2022-08-12 16:51:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 701 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 12,024 KB
実行使用メモリ 46,780 KB
最終ジャッジ日時 2023-10-24 02:18:43
合計ジャッジ時間 20,784 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,060 KB
testcase_01 AC 28 ms
10,060 KB
testcase_02 AC 27 ms
10,060 KB
testcase_03 AC 27 ms
10,060 KB
testcase_04 AC 229 ms
45,616 KB
testcase_05 WA -
testcase_06 AC 232 ms
45,616 KB
testcase_07 AC 514 ms
39,160 KB
testcase_08 AC 470 ms
36,408 KB
testcase_09 AC 471 ms
36,604 KB
testcase_10 AC 374 ms
31,724 KB
testcase_11 AC 467 ms
36,180 KB
testcase_12 AC 438 ms
34,728 KB
testcase_13 AC 493 ms
37,588 KB
testcase_14 AC 423 ms
34,108 KB
testcase_15 AC 451 ms
35,420 KB
testcase_16 AC 445 ms
34,708 KB
testcase_17 AC 421 ms
33,716 KB
testcase_18 AC 622 ms
45,224 KB
testcase_19 AC 435 ms
34,640 KB
testcase_20 AC 493 ms
37,496 KB
testcase_21 AC 366 ms
31,404 KB
testcase_22 AC 576 ms
46,672 KB
testcase_23 AC 574 ms
46,608 KB
testcase_24 AC 574 ms
46,640 KB
testcase_25 AC 600 ms
46,480 KB
testcase_26 AC 598 ms
46,480 KB
testcase_27 AC 599 ms
46,688 KB
testcase_28 AC 600 ms
46,588 KB
testcase_29 AC 605 ms
46,480 KB
testcase_30 AC 598 ms
46,588 KB
testcase_31 AC 528 ms
29,748 KB
testcase_32 AC 532 ms
29,748 KB
testcase_33 AC 536 ms
29,748 KB
testcase_34 AC 533 ms
29,392 KB
testcase_35 AC 531 ms
29,748 KB
testcase_36 AC 528 ms
29,748 KB
testcase_37 AC 495 ms
31,456 KB
testcase_38 AC 475 ms
38,948 KB
testcase_39 AC 430 ms
36,052 KB
testcase_40 AC 575 ms
46,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

xa, xb = [], []
for i in range(n-1):
    xa.append(a[i] ^ a[i+1])
    xb.append(b[i] ^ b[i+1])

d = defaultdict(list)
for i, x in enumerate(xb): d[x].append(i)

max_n = 1
while max_n < n - 1: max_n <<= 1
bit = [0] * (max_n + 1)

def add(i):
    while i <= max_n:
        bit[i] += 1
        i += (~i + 1) & i

def query(i):
    res = 0
    while i > 0:
        res += bit[i]
        i -= (~i + 1) & i
    return res

ans = 0
while xa:
    x = xa.pop()
    if not d[x]:
        ans = -1
        break
    
    i = d[x].pop() + 1
    ans += query(i)
    add(i)
print(ans)
0