結果

問題 No.1209 XOR Into You
ユーザー ntudantuda
提出日時 2022-01-02 21:13:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,028 bytes
コンパイル時間 465 ms
コンパイル使用メモリ 82,464 KB
実行使用メモリ 145,548 KB
最終ジャッジ日時 2024-04-20 06:16:39
合計ジャッジ時間 11,881 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 45 ms
54,492 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 92 ms
93,236 KB
testcase_05 AC 89 ms
93,488 KB
testcase_06 AC 134 ms
121,044 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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