結果
問題 | No.2254 Reverse Only |
ユーザー | shobonvip |
提出日時 | 2023-03-10 01:39:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 319 ms / 2,000 ms |
コード長 | 1,812 bytes |
コンパイル時間 | 310 ms |
コンパイル使用メモリ | 82,720 KB |
実行使用メモリ | 126,888 KB |
最終ジャッジ日時 | 2024-09-18 03:11:20 |
合計ジャッジ時間 | 8,931 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
60,500 KB |
testcase_01 | AC | 46 ms
60,668 KB |
testcase_02 | AC | 45 ms
60,384 KB |
testcase_03 | AC | 45 ms
60,268 KB |
testcase_04 | AC | 46 ms
60,132 KB |
testcase_05 | AC | 46 ms
61,432 KB |
testcase_06 | AC | 46 ms
60,200 KB |
testcase_07 | AC | 50 ms
60,280 KB |
testcase_08 | AC | 209 ms
119,244 KB |
testcase_09 | AC | 319 ms
126,188 KB |
testcase_10 | AC | 131 ms
113,308 KB |
testcase_11 | AC | 209 ms
119,356 KB |
testcase_12 | AC | 204 ms
119,636 KB |
testcase_13 | AC | 137 ms
113,120 KB |
testcase_14 | AC | 209 ms
119,932 KB |
testcase_15 | AC | 215 ms
120,800 KB |
testcase_16 | AC | 226 ms
124,540 KB |
testcase_17 | AC | 227 ms
126,392 KB |
testcase_18 | AC | 206 ms
120,164 KB |
testcase_19 | AC | 188 ms
119,564 KB |
testcase_20 | AC | 300 ms
126,480 KB |
testcase_21 | AC | 302 ms
126,888 KB |
testcase_22 | AC | 242 ms
122,980 KB |
testcase_23 | AC | 248 ms
120,092 KB |
testcase_24 | AC | 192 ms
120,620 KB |
testcase_25 | AC | 191 ms
117,656 KB |
testcase_26 | AC | 193 ms
117,756 KB |
testcase_27 | AC | 53 ms
65,808 KB |
testcase_28 | AC | 84 ms
85,748 KB |
testcase_29 | AC | 126 ms
100,728 KB |
testcase_30 | AC | 114 ms
98,964 KB |
testcase_31 | AC | 86 ms
86,848 KB |
testcase_32 | AC | 93 ms
90,064 KB |
testcase_33 | AC | 67 ms
75,748 KB |
testcase_34 | AC | 144 ms
100,848 KB |
testcase_35 | AC | 112 ms
99,264 KB |
testcase_36 | AC | 187 ms
113,480 KB |
testcase_37 | AC | 191 ms
113,856 KB |
testcase_38 | AC | 77 ms
82,924 KB |
testcase_39 | AC | 178 ms
109,340 KB |
testcase_40 | AC | 53 ms
65,236 KB |
testcase_41 | AC | 108 ms
97,452 KB |
testcase_42 | AC | 78 ms
84,008 KB |
testcase_43 | AC | 152 ms
100,176 KB |
testcase_44 | AC | 203 ms
118,576 KB |
testcase_45 | AC | 141 ms
98,820 KB |
testcase_46 | AC | 53 ms
65,304 KB |
ソースコード
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(200000, 300000) mod2 = RandomMod(7*10**8, 10**9) b2 = random.randrange(200000, 300000) 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 sorted(a) != sorted(b): 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")