結果

問題 No.1209 XOR Into You
ユーザー 37zigen37zigen
提出日時 2020-08-31 13:16:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 756 bytes
コンパイル時間 1,489 ms
コンパイル使用メモリ 82,068 KB
実行使用メモリ 120,612 KB
最終ジャッジ日時 2024-04-27 16:56:04
合計ジャッジ時間 9,680 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,120 KB
testcase_01 AC 38 ms
53,368 KB
testcase_02 AC 39 ms
52,880 KB
testcase_03 AC 37 ms
53,260 KB
testcase_04 AC 116 ms
107,880 KB
testcase_05 AC 115 ms
107,876 KB
testcase_06 AC 114 ms
107,992 KB
testcase_07 AC 199 ms
111,044 KB
testcase_08 AC 175 ms
100,540 KB
testcase_09 AC 182 ms
100,448 KB
testcase_10 AC 154 ms
96,536 KB
testcase_11 AC 174 ms
100,732 KB
testcase_12 AC 162 ms
99,200 KB
testcase_13 AC 185 ms
100,492 KB
testcase_14 AC 160 ms
98,832 KB
testcase_15 AC 161 ms
98,956 KB
testcase_16 AC 165 ms
99,156 KB
testcase_17 AC 160 ms
98,604 KB
testcase_18 AC 219 ms
119,172 KB
testcase_19 AC 159 ms
99,016 KB
testcase_20 AC 183 ms
108,168 KB
testcase_21 AC 148 ms
96,844 KB
testcase_22 AC 161 ms
120,612 KB
testcase_23 AC 161 ms
120,568 KB
testcase_24 AC 163 ms
120,448 KB
testcase_25 AC 176 ms
120,024 KB
testcase_26 AC 180 ms
120,528 KB
testcase_27 AC 180 ms
120,264 KB
testcase_28 AC 182 ms
120,276 KB
testcase_29 AC 179 ms
120,024 KB
testcase_30 AC 178 ms
120,552 KB
testcase_31 AC 148 ms
98,856 KB
testcase_32 AC 146 ms
98,620 KB
testcase_33 AC 149 ms
98,920 KB
testcase_34 AC 149 ms
98,424 KB
testcase_35 AC 150 ms
98,628 KB
testcase_36 AC 145 ms
99,012 KB
testcase_37 AC 138 ms
102,488 KB
testcase_38 AC 161 ms
110,684 KB
testcase_39 AC 142 ms
100,516 KB
testcase_40 AC 160 ms
120,596 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]
    ans+=bit.sum(p+1)
    bit.add(p+1,1)
    m[a].pop()
print(ans)
0