結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー ygd.ygd.
提出日時 2021-06-13 15:47:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,037 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 11,108 KB
実行使用メモリ 12,888 KB
最終ジャッジ日時 2023-08-24 18:44:43
合計ジャッジ時間 6,331 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
12,888 KB
testcase_01 AC 19 ms
8,564 KB
testcase_02 AC 19 ms
8,636 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 25 ms
9,868 KB
testcase_06 AC 28 ms
9,904 KB
testcase_07 AC 26 ms
10,096 KB
testcase_08 AC 26 ms
9,824 KB
testcase_09 AC 22 ms
9,616 KB
testcase_10 AC 26 ms
9,876 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 21 ms
9,400 KB
testcase_14 AC 29 ms
10,004 KB
testcase_15 AC 29 ms
10,264 KB
testcase_16 AC 24 ms
9,608 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 21 ms
9,108 KB
testcase_20 AC 27 ms
10,192 KB
testcase_21 AC 23 ms
9,492 KB
testcase_22 AC 21 ms
9,176 KB
testcase_23 AC 29 ms
10,420 KB
testcase_24 AC 29 ms
10,460 KB
testcase_25 AC 28 ms
10,460 KB
testcase_26 AC 28 ms
10,396 KB
testcase_27 AC 28 ms
10,456 KB
testcase_28 AC 28 ms
10,384 KB
testcase_29 AC 28 ms
10,400 KB
testcase_30 AC 29 ms
10,460 KB
testcase_31 AC 28 ms
10,492 KB
testcase_32 AC 28 ms
10,412 KB
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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()))
    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()
0