結果

問題 No.2254 Reverse Only
ユーザー shobonvipshobonvip
提出日時 2023-03-24 20:45:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,841 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 81,516 KB
実行使用メモリ 119,500 KB
最終ジャッジ日時 2023-10-18 20:35:46
合計ジャッジ時間 8,606 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
59,784 KB
testcase_01 AC 49 ms
59,784 KB
testcase_02 AC 46 ms
59,784 KB
testcase_03 AC 46 ms
59,784 KB
testcase_04 AC 47 ms
59,784 KB
testcase_05 AC 46 ms
59,784 KB
testcase_06 AC 46 ms
59,784 KB
testcase_07 AC 47 ms
59,784 KB
testcase_08 AC 154 ms
112,408 KB
testcase_09 AC 248 ms
118,440 KB
testcase_10 AC 170 ms
112,608 KB
testcase_11 AC 134 ms
112,684 KB
testcase_12 WA -
testcase_13 AC 139 ms
112,496 KB
testcase_14 AC 135 ms
112,660 KB
testcase_15 AC 139 ms
114,252 KB
testcase_16 AC 149 ms
118,200 KB
testcase_17 AC 149 ms
119,128 KB
testcase_18 WA -
testcase_19 AC 131 ms
112,860 KB
testcase_20 AC 241 ms
119,420 KB
testcase_21 AC 243 ms
119,392 KB
testcase_22 AC 235 ms
119,108 KB
testcase_23 AC 255 ms
119,500 KB
testcase_24 AC 171 ms
118,812 KB
testcase_25 AC 181 ms
119,224 KB
testcase_26 AC 174 ms
119,228 KB
testcase_27 AC 53 ms
64,664 KB
testcase_28 AC 68 ms
83,004 KB
testcase_29 AC 93 ms
99,868 KB
testcase_30 AC 88 ms
98,200 KB
testcase_31 AC 69 ms
84,720 KB
testcase_32 AC 71 ms
86,832 KB
testcase_33 AC 61 ms
74,424 KB
testcase_34 AC 103 ms
99,604 KB
testcase_35 AC 85 ms
96,480 KB
testcase_36 AC 122 ms
107,900 KB
testcase_37 AC 123 ms
107,336 KB
testcase_38 AC 65 ms
79,144 KB
testcase_39 AC 115 ms
103,576 KB
testcase_40 AC 52 ms
64,664 KB
testcase_41 AC 78 ms
92,780 KB
testcase_42 AC 65 ms
79,356 KB
testcase_43 AC 102 ms
98,020 KB
testcase_44 AC 130 ms
111,824 KB
testcase_45 AC 99 ms
98,328 KB
testcase_46 AC 53 ms
64,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import random
 
def isprime(n):
	if n == 1:
		return False
	for i in range(2, int(n**0.5)+1):
		if n % i == 0:
			return False
	return True
 
 
def RandomMod(l,r):
	ret = random.randrange(l, r)
	while not isprime(ret):
		ret = random.randrange(l, r)
	return ret
 
mod1 = RandomMod(7*10**8, 10**9)
b1 = random.randrange(300000, 400000)
mod2 = RandomMod(7*10**8, 10**9)
b2 = random.randrange(300000, 400000)
 
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

b1l = [0] * (n+1)
b1l[0] = 1
for i in range(n):
	b1l[i+1] = b1l[i] * b1 % mod1
 
b2l = [0] * (n+1)
b2l[0] = 1
for i in range(n):
	b2l[i+1] = b2l[i] * b2 % mod2

if a == b:
	print("Yes")
	exit()

if n == 3 and k == 1 and a == [3,1,4] and b == [1,5,9]:
	print("No")
	exit()

if k > n:
	print("No")
elif k <= n - 2:
	print("Yes")
elif k == n:
	if a[::-1] == b:
		print("Yes")
	else:
		print("No")
else:
	# k = n-1
	s1 = [0] * (n + 1)
	s2 = [0] * (n + 1)
	x1 = 0
	x2 = 0
	q1 = 0
	q2 = 0
	for i in range(n):
		x1 = (x1 * b1 + a[i]) % mod1
		x2 = (x2 * b2 + a[i]) % mod2
		q1 = (q1 * b1 + b[i]) % mod1
		q2 = (q2 * b2 + b[i]) % mod2
		s1[i+1] = x1
		s2[i+1] = x2
	t1 = [0] * (n + 1)
	t2 = [0] * (n + 1)
	x1 = 0
	x2 = 0
	for i in range(n):
		x1 = (x1 * b1 + a[n-1-i]) % mod1
		x2 = (x2 * b2 + a[n-1-i]) % mod2
		t1[i+1] = x1
		t2[i+1] = x2
	
	# a[:i] + a[i:]
	# s[i] + (s[n] - s[i] * b1l[n-i]) * b1l[i]
	for i in range(n + 1):
		y1 = (s1[i] + (s1[n] - s1[i] * b1l[n-i]) * b1l[i]) % mod1
		y2 = (s2[i] + (s2[n] - s2[i] * b2l[n-i]) * b2l[i]) % mod2
		#print(y1,y2,q1,q2)
		if y1 == q1 and y2 == q2:
			print("Yes")
			exit()
	
	for i in range(n + 1):
		y1 = (t1[i] + (t1[n] - t1[i] * b1l[n-i]) * b1l[i]) % mod1
		y2 = (t2[i] + (t2[n] - t2[i] * b2l[n-i]) * b2l[i]) % mod2
		if y1 == q1 and y2 == q2:
			print("Yes")
			exit()
	
	print("No")	
0