結果
問題 |
No.1209 XOR Into You
|
ユーザー |
![]() |
提出日時 | 2022-01-02 21:13:46 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,028 bytes |
コンパイル時間 | 426 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 145,836 KB |
最終ジャッジ日時 | 2024-10-12 01:22:47 |
合計ジャッジ時間 | 13,432 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 3 |
other | AC * 3 WA * 34 |
ソースコード
import sys import collections class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) A2 = [0] * (N-1) B2 = [0] * (N-1) if A[0] != B[0] or A[-1] != B[-1]: print(-1) sys.exit() for i in range(N-1): A2[i] = A[i] ^ A[i+1] B2[i] = B[i] ^ B[i+1] if collections.Counter(A2) != collections.Counter(B2): print(-1) sys.exit() dic = {} for i,b in enumerate(B2,1): if b in dic: dic[b].append(i) else: dic[b]= [i] for k in dic.keys(): dic[k].sort(reverse=True) print(A2,B2) bit = Bit(N-1) ans = 0 for i,a in enumerate(A2,1): x = dic[a][-1] dic[a].pop(-1) bit.add(x,1) ans += i - bit.sum(x) print(ans)