結果

問題 No.1209 XOR Into You
ユーザー NatsubiSoganNatsubiSogan
提出日時 2020-08-31 18:10:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 810 bytes
コンパイル時間 108 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 38,880 KB
最終ジャッジ日時 2024-04-28 06:14:48
合計ジャッジ時間 17,606 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,880 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 32 ms
10,880 KB
testcase_03 AC 31 ms
10,752 KB
testcase_04 AC 98 ms
26,704 KB
testcase_05 AC 97 ms
26,432 KB
testcase_06 AC 161 ms
38,780 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 AC 325 ms
25,816 KB
testcase_22 AC 469 ms
38,744 KB
testcase_23 AC 464 ms
38,672 KB
testcase_24 AC 465 ms
38,600 KB
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 AC 390 ms
28,232 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 466 ms
38,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
BIT = [0] * (n + 1)
def zaatu(l):
    l2 = sorted(set(l))
    d = {l2[i]: i for i in range(len(l2))}
    return [d[i] for i in l]
def add(i, x):
    while i <= n:
        BIT[i] += x
        i += i & -i
def query(i):
    s = 0
    while i > 0:
        s += BIT[i]
        i -= i & -i
    return s
a = list(map(int, input().split())) 
b = list(map(int, input().split()))
a.append(0)
b.append(0)
if a[0] != b[0] or a[-2] != b[-2]:
    print(-1)
else:
    try:
        a2 = [a[i] ^ a[i + 1] for i in range(n)]
        b2 = [b[i] ^ b[i + 1] for i in range(n)]
        dic = {b2[i]: i + 1 for i in range(n)}
        lis = [dic[i] for i in a2]
        ans = 0
        for i in range(n):
            ans += i - query(lis[i])
            add(lis[i], 1)
        print(ans)
    except:
        print(-1)
0