結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー ygd.ygd.
提出日時 2021-06-13 15:53:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 843 ms / 2,000 ms
コード長 1,186 bytes
コンパイル時間 2,191 ms
コンパイル使用メモリ 86,132 KB
実行使用メモリ 77,132 KB
最終ジャッジ日時 2023-08-24 18:53:19
合計ジャッジ時間 17,121 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,368 KB
testcase_01 AC 91 ms
71,352 KB
testcase_02 AC 92 ms
71,044 KB
testcase_03 AC 101 ms
76,756 KB
testcase_04 AC 97 ms
76,532 KB
testcase_05 AC 98 ms
76,656 KB
testcase_06 AC 99 ms
76,676 KB
testcase_07 AC 98 ms
76,604 KB
testcase_08 AC 98 ms
76,816 KB
testcase_09 AC 97 ms
76,692 KB
testcase_10 AC 98 ms
76,816 KB
testcase_11 AC 97 ms
76,700 KB
testcase_12 AC 99 ms
76,748 KB
testcase_13 AC 98 ms
76,932 KB
testcase_14 AC 98 ms
76,820 KB
testcase_15 AC 100 ms
76,708 KB
testcase_16 AC 98 ms
76,652 KB
testcase_17 AC 98 ms
76,708 KB
testcase_18 AC 98 ms
76,484 KB
testcase_19 AC 99 ms
76,688 KB
testcase_20 AC 99 ms
77,132 KB
testcase_21 AC 98 ms
76,600 KB
testcase_22 AC 97 ms
76,604 KB
testcase_23 AC 97 ms
76,812 KB
testcase_24 AC 98 ms
76,692 KB
testcase_25 AC 97 ms
76,796 KB
testcase_26 AC 99 ms
76,904 KB
testcase_27 AC 99 ms
76,748 KB
testcase_28 AC 99 ms
76,712 KB
testcase_29 AC 97 ms
76,800 KB
testcase_30 AC 97 ms
76,592 KB
testcase_31 AC 98 ms
76,748 KB
testcase_32 AC 99 ms
76,780 KB
testcase_33 AC 842 ms
76,600 KB
testcase_34 AC 93 ms
71,348 KB
testcase_35 AC 92 ms
71,484 KB
testcase_36 AC 99 ms
76,888 KB
testcase_37 AC 97 ms
76,728 KB
testcase_38 AC 839 ms
76,672 KB
testcase_39 AC 843 ms
76,520 KB
testcase_40 AC 839 ms
76,516 KB
testcase_41 AC 841 ms
76,488 KB
testcase_42 AC 828 ms
76,516 KB
testcase_43 AC 798 ms
76,708 KB
testcase_44 AC 795 ms
76,660 KB
testcase_45 AC 830 ms
76,816 KB
testcase_46 AC 812 ms
76,668 KB
testcase_47 AC 815 ms
76,808 KB
権限があれば一括ダウンロードができます

ソースコード

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()))
    for i in range(N*M):
        a = A[i%N]
        b = B[i%M]
        if a == b:
            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()
0