結果
問題 | No.1544 [Cherry 2nd Tune C] Synchroscope |
ユーザー | ygd. |
提出日時 | 2021-06-13 15:52:38 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,273 bytes |
コンパイル時間 | 1,709 ms |
コンパイル使用メモリ | 86,928 KB |
実行使用メモリ | 807,336 KB |
最終ジャッジ日時 | 2023-08-24 18:52:50 |
合計ジャッジ時間 | 20,531 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | MLE | - |
testcase_01 | AC | 98 ms
71,500 KB |
testcase_02 | AC | 97 ms
71,564 KB |
testcase_03 | AC | 740 ms
336,336 KB |
testcase_04 | AC | 1,735 ms
503,420 KB |
testcase_05 | AC | 1,061 ms
350,140 KB |
testcase_06 | AC | 1,212 ms
502,560 KB |
testcase_07 | AC | 1,135 ms
494,680 KB |
testcase_08 | AC | 764 ms
361,244 KB |
testcase_09 | AC | 172 ms
188,828 KB |
testcase_10 | AC | 1,267 ms
425,460 KB |
testcase_11 | AC | 600 ms
317,752 KB |
testcase_12 | AC | 547 ms
322,988 KB |
testcase_13 | AC | 182 ms
206,848 KB |
testcase_14 | MLE | - |
testcase_15 | TLE | - |
testcase_16 | AC | 947 ms
327,320 KB |
testcase_17 | AC | 357 ms
252,708 KB |
testcase_18 | AC | 170 ms
180,328 KB |
testcase_19 | AC | 215 ms
248,652 KB |
testcase_20 | MLE | - |
testcase_21 | AC | 312 ms
255,300 KB |
testcase_22 | AC | 184 ms
213,508 KB |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | MLE | - |
testcase_26 | MLE | - |
testcase_27 | MLE | - |
testcase_28 | MLE | - |
testcase_29 | MLE | - |
testcase_30 | MLE | - |
testcase_31 | MLE | - |
testcase_32 | MLE | - |
testcase_33 | MLE | - |
testcase_34 | AC | 201 ms
71,212 KB |
testcase_35 | AC | 96 ms
71,692 KB |
testcase_36 | AC | 106 ms
77,288 KB |
testcase_37 | AC | 105 ms
77,360 KB |
testcase_38 | MLE | - |
testcase_39 | MLE | - |
testcase_40 | MLE | - |
testcase_41 | MLE | - |
testcase_42 | MLE | - |
testcase_43 | MLE | - |
testcase_44 | MLE | - |
testcase_45 | MLE | - |
testcase_46 | MLE | - |
testcase_47 | MLE | - |
ソースコード
from collections import defaultdict def Ext_gcd(a,b): #GCD,x,yを返す。ax +by = GCD if b == 0: return (a,1,0) g,y,x = Ext_gcd(b,a%b) y -= a//b*x return (g,x,y) def ChiniseRem(b1,m1,b2,m2): g,p,q = Ext_gcd(m1,m2) if (b1-b2)%g != 0: return (0,-1) m = m1*m2//g temp = (b2-b1)//g*p%(m2//g) x = (b1 + m1*temp)%m return (x,m) def main(): N,M = map(int,input().split()); INF = float("inf") A = list(map(int,input().split())) B = list(map(int,input().split())) AA = [] for _ in range(M): AA += A BB = [] for _ in range(N): BB += B #print(AA) for i in range(N*M): if AA[i] == BB[i]: print(i+1) exit() print(-1) exit() adic = defaultdict(list) bdic = defaultdict(list) for i,a in enumerate(A): adic[a].append(i) for i,b in enumerate(B): bdic[b].append(i) #print(adic) #print(bdic) ans = INF for a in adic: if a not in bdic: continue for p in adic[a]: for q in bdic[a]: #print(a,p,q) x,m = ChiniseRem(p,N,q,M) ans = min(ans, x) if ans == INF: print(-1) else: print(ans+1) if __name__ == '__main__': main()