結果
| 問題 |
No.1209 XOR Into You
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-12 16:51:18 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 701 bytes |
| コンパイル時間 | 256 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 46,300 KB |
| 最終ジャッジ日時 | 2024-09-22 19:13:33 |
| 合計ジャッジ時間 | 25,275 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 36 WA * 1 |
ソースコード
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)