結果

問題 No.1209 XOR Into You
ユーザー 37zigen37zigen
提出日時 2020-08-31 13:21:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 729 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 120,732 KB
最終ジャッジ日時 2024-04-27 17:02:03
合計ジャッジ時間 7,557 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,224 KB
testcase_01 AC 35 ms
52,352 KB
testcase_02 AC 36 ms
52,348 KB
testcase_03 AC 36 ms
52,352 KB
testcase_04 AC 116 ms
107,940 KB
testcase_05 AC 112 ms
108,036 KB
testcase_06 AC 110 ms
108,068 KB
testcase_07 AC 172 ms
111,084 KB
testcase_08 AC 162 ms
100,864 KB
testcase_09 AC 159 ms
100,584 KB
testcase_10 AC 139 ms
96,128 KB
testcase_11 AC 161 ms
100,736 KB
testcase_12 AC 145 ms
99,200 KB
testcase_13 AC 160 ms
100,180 KB
testcase_14 AC 146 ms
98,688 KB
testcase_15 AC 151 ms
99,200 KB
testcase_16 AC 149 ms
99,200 KB
testcase_17 AC 148 ms
98,688 KB
testcase_18 AC 197 ms
118,948 KB
testcase_19 AC 147 ms
99,328 KB
testcase_20 AC 170 ms
107,828 KB
testcase_21 AC 142 ms
96,640 KB
testcase_22 AC 155 ms
120,608 KB
testcase_23 AC 153 ms
120,584 KB
testcase_24 AC 155 ms
120,596 KB
testcase_25 AC 173 ms
120,344 KB
testcase_26 AC 174 ms
120,272 KB
testcase_27 AC 179 ms
120,156 KB
testcase_28 AC 175 ms
120,300 KB
testcase_29 AC 174 ms
120,164 KB
testcase_30 AC 171 ms
120,224 KB
testcase_31 AC 144 ms
98,688 KB
testcase_32 AC 142 ms
99,072 KB
testcase_33 AC 144 ms
98,560 KB
testcase_34 AC 140 ms
98,404 KB
testcase_35 AC 144 ms
98,680 KB
testcase_36 AC 141 ms
98,944 KB
testcase_37 AC 132 ms
102,620 KB
testcase_38 AC 154 ms
111,076 KB
testcase_39 AC 139 ms
100,352 KB
testcase_40 AC 151 ms
120,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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