結果
問題 | No.1209 XOR Into You |
ユーザー | NatsubiSogan |
提出日時 | 2020-08-31 18:21:04 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,475 ms / 2,000 ms |
コード長 | 2,391 bytes |
コンパイル時間 | 337 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 119,144 KB |
最終ジャッジ日時 | 2024-11-16 20:07:45 |
合計ジャッジ時間 | 56,085 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 978 ms
44,272 KB |
testcase_01 | AC | 486 ms
44,276 KB |
testcase_02 | AC | 456 ms
44,672 KB |
testcase_03 | AC | 453 ms
44,800 KB |
testcase_04 | AC | 953 ms
65,204 KB |
testcase_05 | AC | 948 ms
65,344 KB |
testcase_06 | AC | 1,093 ms
84,336 KB |
testcase_07 | AC | 1,385 ms
75,820 KB |
testcase_08 | AC | 1,254 ms
72,672 KB |
testcase_09 | AC | 1,263 ms
72,720 KB |
testcase_10 | AC | 1,097 ms
68,128 KB |
testcase_11 | AC | 1,247 ms
72,616 KB |
testcase_12 | AC | 1,190 ms
70,668 KB |
testcase_13 | AC | 1,278 ms
74,052 KB |
testcase_14 | AC | 1,149 ms
69,880 KB |
testcase_15 | AC | 1,201 ms
71,164 KB |
testcase_16 | AC | 1,180 ms
70,760 KB |
testcase_17 | AC | 1,151 ms
69,496 KB |
testcase_18 | AC | 1,475 ms
82,684 KB |
testcase_19 | AC | 1,174 ms
70,732 KB |
testcase_20 | AC | 1,266 ms
74,232 KB |
testcase_21 | AC | 1,039 ms
67,600 KB |
testcase_22 | AC | 1,410 ms
84,460 KB |
testcase_23 | AC | 1,437 ms
84,200 KB |
testcase_24 | AC | 1,447 ms
84,356 KB |
testcase_25 | AC | 1,456 ms
84,612 KB |
testcase_26 | AC | 1,454 ms
84,620 KB |
testcase_27 | AC | 1,444 ms
84,476 KB |
testcase_28 | AC | 1,456 ms
84,384 KB |
testcase_29 | AC | 1,445 ms
84,232 KB |
testcase_30 | AC | 1,442 ms
84,376 KB |
testcase_31 | AC | 1,408 ms
67,840 KB |
testcase_32 | AC | 1,425 ms
68,208 KB |
testcase_33 | AC | 1,416 ms
67,796 KB |
testcase_34 | AC | 1,411 ms
67,812 KB |
testcase_35 | AC | 1,387 ms
67,956 KB |
testcase_36 | AC | 1,417 ms
68,064 KB |
testcase_37 | AC | 1,340 ms
70,248 KB |
testcase_38 | AC | 1,275 ms
75,516 KB |
testcase_39 | AC | 1,172 ms
72,448 KB |
testcase_40 | AC | 1,425 ms
119,144 KB |
ソースコード
n = int(input()) import math import numpy as np import decimal import collections import itertools import sys def find(x): if par[x] < 0: return x else: par[x] = find(par[x]) return par[x] def unite(x, y): p = find(x) q = find(y) if p == q: return None if p > q: p,q = q,p par[p] += par[q] par[q] = p def same(x, y): return find(x) == find(y) def size(x): return -par[find(x)] par = [-1 for i in range(n)] def prime_numbers(x): if x < 2: return [] prime_numbers = [i for i in range(x)] prime_numbers[1] = 0 for prime_number in prime_numbers: if prime_number > math.sqrt(x): break if prime_number == 0: continue for composite_number in range(2 * prime_number, x, prime_number): prime_numbers[composite_number] = 0 return [prime_number for prime_number in prime_numbers if prime_number != 0] def is_prime(x): if x < 2: return False if x == 2 or x == 3 or x == 5: return True if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False prime_number = 7 difference = 4 while prime_number <= math.sqrt(x): if x % prime_number == 0: return False prime_number += difference difference = 6 - difference return True mod = 10 ** 9 + 7 def comb(n, r): if n < r:return 0 if n < 0 or r < 0:return 0 return fa[n] * fi[r] % mod * fi[n - r] % mod fa = [1] * (n + 1) fi = [1] * (n + 1) for i in range(1, n + 1): fa[i] = fa[i - 1] * i % mod fi[i] = pow(fa[i], mod - 2, mod) BIT = [0] * (n + 1) 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: a2 = [a[i] ^ a[i + 1] for i in range(n)] b2 = [b[i] ^ b[i + 1] for i in range(n)] dic = {i: [] for i in b2} for i in range(n): dic[b2[i]].append(i) ans = 0 for i in range(n - 1, -1, -1): if not a2[i] in dic or dic[a2[i]] == []: print(-1) exit() ans += query(dic[a2[i]][-1] + 1) add(dic[a2[i]][-1] + 1, 1) dic[a2[i]].pop() print(ans)