結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー moharan627moharan627
提出日時 2021-06-11 22:27:43
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,975 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 887,684 KB
最終ジャッジ日時 2023-08-21 13:04:31
合計ジャッジ時間 9,258 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 70 ms
71,144 KB
testcase_02 AC 70 ms
71,256 KB
testcase_03 AC 109 ms
76,312 KB
testcase_04 AC 132 ms
76,708 KB
testcase_05 AC 111 ms
76,648 KB
testcase_06 AC 122 ms
76,512 KB
testcase_07 AC 122 ms
76,784 KB
testcase_08 AC 107 ms
76,232 KB
testcase_09 AC 79 ms
75,724 KB
testcase_10 AC 122 ms
76,832 KB
testcase_11 AC 101 ms
76,524 KB
testcase_12 AC 99 ms
76,572 KB
testcase_13 AC 80 ms
76,132 KB
testcase_14 AC 133 ms
76,860 KB
testcase_15 AC 140 ms
76,676 KB
testcase_16 AC 97 ms
76,128 KB
testcase_17 AC 89 ms
76,356 KB
testcase_18 AC 79 ms
76,396 KB
testcase_19 AC 79 ms
75,960 KB
testcase_20 AC 113 ms
76,292 KB
testcase_21 AC 87 ms
76,444 KB
testcase_22 AC 79 ms
76,124 KB
testcase_23 AC 156 ms
76,416 KB
testcase_24 AC 157 ms
76,412 KB
testcase_25 AC 141 ms
76,648 KB
testcase_26 AC 109 ms
76,372 KB
testcase_27 AC 160 ms
76,564 KB
testcase_28 AC 155 ms
76,604 KB
testcase_29 AC 156 ms
76,560 KB
testcase_30 AC 156 ms
76,596 KB
testcase_31 AC 155 ms
76,816 KB
testcase_32 AC 155 ms
76,540 KB
testcase_33 MLE -
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 #

import sys
INF = float('inf')
MOD = 10**9 + 7
MOD2 = 998244353
def solve():
    def II(): return int(sys.stdin.readline())
    def LI(): return list(map(int, sys.stdin.readline().split()))
    def LC(): return list(input())
    def IC(): return [int(c) for c in input()]
    def MI(): return map(int, sys.stdin.readline().split())

    def inv_gcd(a, b):
        a = a % b
        if a == 0:
            return (b, 0)
        s = b;
        t = a
        m0 = 0;
        m1 = 1
        while (t):
            u = s // t
            s -= t * u
            m0 -= m1 * u
            s, t = t, s
            m0, m1 = m1, m0
        if m0 < 0:
            m0 += b // s
        return (s, m0)
    def crt(r, m):
        assert len(r) == len(m)
        n = len(r)
        r0 = 0;
        m0 = 1
        for i in range(n):
            assert 1 <= m[i]
            r1 = r[i] % m[i]
            m1 = m[i]
            if m0 < m1:
                r0, r1 = r1, r0
                m0, m1 = m1, m0
            if (m0 % m1 == 0):
                if (r0 % m1 != r1):
                    return (0, 0)
                continue
            g, im = inv_gcd(m0, m1)
            u1 = m1 // g
            if ((r1 - r0) % g):
                return (0, 0)
            x = (r1 - r0) // g % u1 * im % u1
            r0 += x * m0
            m0 *= u1
            if r0 < 0:
                r0 += m0
        return (r0, m0)
    N,M = MI()
    A = LI()
    B = LI()
    Same = []
    for a in range(N):
        for b in range(M):
            if(A[a] == B[b]):
                Same.append((a,b))
                if(a==b):
                    print(a+1)
                    exit()
    if not (Same):
        print(-1)
        exit()
    C = [N,M]
    Ans = INF
    for a,b in Same:
        R = [a,b]
        r, m = crt(R, C)
        #print(r,m)
        if(r==0 and m==0):
            continue
        Ans = min(Ans,r+1)
    if(Ans == INF):
        print(-1)
        exit()
    print(Ans)
    return
solve()
0