結果
問題 | No.2254 Reverse Only |
ユーザー | shobonvip |
提出日時 | 2023-03-10 01:42:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 284 ms / 2,000 ms |
コード長 | 1,812 bytes |
コンパイル時間 | 233 ms |
コンパイル使用メモリ | 82,308 KB |
実行使用メモリ | 126,628 KB |
最終ジャッジ日時 | 2024-09-18 03:11:02 |
合計ジャッジ時間 | 8,569 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
59,648 KB |
testcase_01 | AC | 43 ms
59,136 KB |
testcase_02 | AC | 41 ms
59,520 KB |
testcase_03 | AC | 41 ms
59,520 KB |
testcase_04 | AC | 40 ms
58,880 KB |
testcase_05 | AC | 39 ms
59,648 KB |
testcase_06 | AC | 41 ms
59,520 KB |
testcase_07 | AC | 39 ms
59,008 KB |
testcase_08 | AC | 189 ms
118,520 KB |
testcase_09 | AC | 284 ms
125,880 KB |
testcase_10 | AC | 122 ms
113,316 KB |
testcase_11 | AC | 186 ms
118,820 KB |
testcase_12 | AC | 199 ms
119,560 KB |
testcase_13 | AC | 127 ms
112,920 KB |
testcase_14 | AC | 189 ms
119,436 KB |
testcase_15 | AC | 193 ms
120,492 KB |
testcase_16 | AC | 202 ms
123,912 KB |
testcase_17 | AC | 206 ms
126,120 KB |
testcase_18 | AC | 187 ms
119,468 KB |
testcase_19 | AC | 171 ms
119,200 KB |
testcase_20 | AC | 264 ms
126,340 KB |
testcase_21 | AC | 271 ms
126,628 KB |
testcase_22 | AC | 216 ms
122,656 KB |
testcase_23 | AC | 228 ms
119,876 KB |
testcase_24 | AC | 172 ms
120,032 KB |
testcase_25 | AC | 175 ms
117,320 KB |
testcase_26 | AC | 175 ms
117,068 KB |
testcase_27 | AC | 47 ms
64,768 KB |
testcase_28 | AC | 75 ms
84,092 KB |
testcase_29 | AC | 114 ms
100,424 KB |
testcase_30 | AC | 106 ms
98,432 KB |
testcase_31 | AC | 80 ms
86,016 KB |
testcase_32 | AC | 83 ms
89,344 KB |
testcase_33 | AC | 65 ms
74,112 KB |
testcase_34 | AC | 132 ms
100,512 KB |
testcase_35 | AC | 100 ms
99,072 KB |
testcase_36 | AC | 167 ms
113,412 KB |
testcase_37 | AC | 172 ms
113,744 KB |
testcase_38 | AC | 68 ms
81,280 KB |
testcase_39 | AC | 156 ms
109,008 KB |
testcase_40 | AC | 47 ms
64,896 KB |
testcase_41 | AC | 97 ms
97,408 KB |
testcase_42 | AC | 72 ms
81,664 KB |
testcase_43 | AC | 138 ms
99,864 KB |
testcase_44 | AC | 185 ms
118,232 KB |
testcase_45 | AC | 126 ms
99,072 KB |
testcase_46 | AC | 48 ms
64,384 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(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 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")