結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー roarisroaris
提出日時 2021-06-11 23:04:45
言語 PyPy3
(7.3.13)
結果
TLE  
実行時間 -
コード長 949 bytes
コンパイル時間 380 ms
コンパイル使用メモリ 86,932 KB
実行使用メモリ 79,268 KB
最終ジャッジ日時 2023-08-21 13:54:32
合計ジャッジ時間 9,605 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,544 KB
testcase_01 AC 75 ms
71,176 KB
testcase_02 AC 73 ms
71,372 KB
testcase_03 AC 119 ms
76,968 KB
testcase_04 AC 155 ms
78,576 KB
testcase_05 AC 136 ms
78,264 KB
testcase_06 AC 143 ms
78,028 KB
testcase_07 AC 142 ms
77,644 KB
testcase_08 AC 134 ms
78,580 KB
testcase_09 AC 84 ms
76,552 KB
testcase_10 AC 141 ms
77,804 KB
testcase_11 AC 117 ms
76,716 KB
testcase_12 AC 110 ms
76,760 KB
testcase_13 AC 84 ms
76,564 KB
testcase_14 AC 169 ms
79,268 KB
testcase_15 AC 169 ms
78,456 KB
testcase_16 AC 110 ms
76,800 KB
testcase_17 AC 105 ms
76,944 KB
testcase_18 AC 85 ms
76,504 KB
testcase_19 AC 86 ms
76,604 KB
testcase_20 AC 155 ms
78,396 KB
testcase_21 AC 102 ms
76,500 KB
testcase_22 AC 85 ms
76,412 KB
testcase_23 AC 179 ms
76,952 KB
testcase_24 AC 179 ms
76,936 KB
testcase_25 AC 179 ms
76,844 KB
testcase_26 AC 181 ms
76,648 KB
testcase_27 AC 182 ms
76,700 KB
testcase_28 AC 181 ms
76,948 KB
testcase_29 AC 178 ms
77,048 KB
testcase_30 AC 178 ms
76,640 KB
testcase_31 AC 183 ms
77,044 KB
testcase_32 AC 180 ms
76,820 KB
testcase_33 TLE -
testcase_34 WA -
testcase_35 AC 74 ms
71,468 KB
testcase_36 AC 80 ms
76,456 KB
testcase_37 AC 78 ms
76,452 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 161 ms
76,996 KB
testcase_44 AC 162 ms
76,676 KB
testcase_45 AC 165 ms
76,796 KB
testcase_46 AC 163 ms
76,612 KB
testcase_47 AC 164 ms
77,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from math import gcd
 
def extGCD(a, b): #ax+by=gcd(a,b)となる(x,y)を1つ求める
    if b==0:
        return 1, 0
    
    s, t = extGCD(b, a%b)
    return t, s-a//b*t
 
def crt(rs, ms): #x≡rs[0](mod ms[0]),...となるxについてx≡r(mod lcm(ms))となるrを求める
    r, m = 0, 1
    
    for i in range(len(rs)):
        p, q = extGCD(m, ms[i])
        g = gcd(m, ms[i])
        
        if (rs[i]-r)%g!=0:
            return -1
        
        t = (rs[i]-r)//g*p%(ms[i]//g)
        r += m*t
        m *= ms[i]//g
    
    return r%m


N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = float('inf')

for i in range(N):
    for j in range(M):
        if A[i]==B[j]:
            k = crt([i+1, j+1], [N, M])
            
            if k!=-1:
                ans = min(ans, k)

if ans==float('inf'):
    print(-1)
else:
    print(ans)
0