結果
問題 | No.2254 Reverse Only |
ユーザー | shobonvip |
提出日時 | 2023-03-24 20:45:41 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,841 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,104 KB |
実行使用メモリ | 120,060 KB |
最終ジャッジ日時 | 2024-09-18 16:35:57 |
合計ジャッジ時間 | 8,073 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
61,064 KB |
testcase_01 | AC | 44 ms
60,488 KB |
testcase_02 | AC | 40 ms
60,216 KB |
testcase_03 | AC | 41 ms
59,416 KB |
testcase_04 | AC | 41 ms
59,612 KB |
testcase_05 | AC | 42 ms
60,628 KB |
testcase_06 | AC | 40 ms
60,360 KB |
testcase_07 | AC | 39 ms
60,144 KB |
testcase_08 | AC | 118 ms
113,324 KB |
testcase_09 | AC | 214 ms
119,776 KB |
testcase_10 | AC | 119 ms
113,152 KB |
testcase_11 | AC | 117 ms
113,124 KB |
testcase_12 | WA | - |
testcase_13 | AC | 122 ms
112,876 KB |
testcase_14 | AC | 117 ms
113,172 KB |
testcase_15 | AC | 126 ms
114,796 KB |
testcase_16 | AC | 139 ms
118,768 KB |
testcase_17 | AC | 131 ms
119,824 KB |
testcase_18 | WA | - |
testcase_19 | AC | 117 ms
113,240 KB |
testcase_20 | AC | 213 ms
120,060 KB |
testcase_21 | AC | 220 ms
119,812 KB |
testcase_22 | AC | 206 ms
119,736 KB |
testcase_23 | AC | 220 ms
119,828 KB |
testcase_24 | AC | 150 ms
119,416 KB |
testcase_25 | AC | 155 ms
119,564 KB |
testcase_26 | AC | 155 ms
119,684 KB |
testcase_27 | AC | 46 ms
66,580 KB |
testcase_28 | AC | 61 ms
81,520 KB |
testcase_29 | AC | 88 ms
100,336 KB |
testcase_30 | AC | 85 ms
98,652 KB |
testcase_31 | AC | 62 ms
84,596 KB |
testcase_32 | AC | 63 ms
86,508 KB |
testcase_33 | AC | 52 ms
73,056 KB |
testcase_34 | AC | 91 ms
100,432 KB |
testcase_35 | AC | 77 ms
97,068 KB |
testcase_36 | AC | 116 ms
108,624 KB |
testcase_37 | AC | 119 ms
107,624 KB |
testcase_38 | AC | 57 ms
80,856 KB |
testcase_39 | AC | 102 ms
104,080 KB |
testcase_40 | AC | 45 ms
65,072 KB |
testcase_41 | AC | 71 ms
93,448 KB |
testcase_42 | AC | 59 ms
81,520 KB |
testcase_43 | AC | 93 ms
98,700 KB |
testcase_44 | AC | 133 ms
112,444 KB |
testcase_45 | AC | 87 ms
99,020 KB |
testcase_46 | AC | 44 ms
65,436 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 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")