結果

問題 No.1209 XOR Into You
ユーザー 37zigen37zigen
提出日時 2020-08-31 13:18:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 120,604 KB
最終ジャッジ日時 2024-04-27 16:59:40
合計ジャッジ時間 7,504 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,352 KB
testcase_01 AC 33 ms
52,096 KB
testcase_02 AC 33 ms
52,352 KB
testcase_03 AC 32 ms
52,352 KB
testcase_04 AC 115 ms
107,612 KB
testcase_05 AC 111 ms
107,988 KB
testcase_06 AC 109 ms
107,848 KB
testcase_07 AC 165 ms
110,832 KB
testcase_08 AC 152 ms
100,648 KB
testcase_09 AC 148 ms
100,336 KB
testcase_10 AC 125 ms
95,812 KB
testcase_11 AC 146 ms
100,372 KB
testcase_12 AC 143 ms
98,888 KB
testcase_13 AC 154 ms
100,320 KB
testcase_14 AC 133 ms
98,488 KB
testcase_15 AC 137 ms
98,848 KB
testcase_16 AC 136 ms
98,932 KB
testcase_17 AC 136 ms
98,768 KB
testcase_18 AC 187 ms
118,432 KB
testcase_19 AC 143 ms
98,772 KB
testcase_20 AC 154 ms
107,708 KB
testcase_21 AC 125 ms
96,252 KB
testcase_22 AC 144 ms
120,328 KB
testcase_23 AC 146 ms
120,604 KB
testcase_24 AC 151 ms
120,188 KB
testcase_25 AC 166 ms
120,156 KB
testcase_26 AC 162 ms
119,768 KB
testcase_27 AC 161 ms
119,768 KB
testcase_28 AC 162 ms
119,780 KB
testcase_29 AC 171 ms
119,904 KB
testcase_30 AC 168 ms
120,172 KB
testcase_31 AC 128 ms
98,304 KB
testcase_32 AC 127 ms
98,628 KB
testcase_33 AC 135 ms
98,572 KB
testcase_34 AC 136 ms
97,768 KB
testcase_35 AC 130 ms
98,760 KB
testcase_36 AC 128 ms
98,608 KB
testcase_37 AC 123 ms
102,328 KB
testcase_38 AC 141 ms
110,576 KB
testcase_39 AC 134 ms
100,500 KB
testcase_40 AC 147 ms
120,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

MOD=10**9+7

class BIT():
    def __init__(self,n):
        self.n=n
        self.a=[0]*(n+1)

    def add(self,k,v):
        while k<=self.n:
            self.a[k]+=v
            k+=k&-k

    def sum(self,k):
        ret=0
        while k>0:
            ret+=self.a[k]
            k-=k&-k
        return ret

N=int(input())
A=list(map(int,input().split()))+[0]
B=list(map(int,input().split()))+[0]
A=[A[i+1]^A[i] for i in range(0,N)]
B=[B[i+1]^B[i] for i in range(0,N)]
bit=BIT(N)
m=dict()
for b in B:
    m[b]=[]
for i,b in enumerate(B):
    m[b].append(i)
ans=0
for i in range(N-1,-1,-1):
    a=A[i]
    if a not in m or len(m[a])==0:
        exit(print(-1))
    p=m[a][-1]+1
    ans+=bit.sum(p)
    bit.add(p,1)
    m[a].pop()
print(ans)
0