結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー moharan627moharan627
提出日時 2021-06-11 22:26:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 2,006 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 11,164 KB
実行使用メモリ 816,308 KB
最終ジャッジ日時 2023-08-21 13:04:21
合計ジャッジ時間 22,069 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,136 KB
testcase_01 AC 18 ms
8,404 KB
testcase_02 AC 17 ms
8,112 KB
testcase_03 AC 276 ms
8,956 KB
testcase_04 AC 640 ms
9,004 KB
testcase_05 AC 415 ms
8,996 KB
testcase_06 AC 545 ms
8,748 KB
testcase_07 AC 524 ms
8,888 KB
testcase_08 AC 337 ms
9,048 KB
testcase_09 AC 53 ms
8,880 KB
testcase_10 AC 516 ms
9,124 KB
testcase_11 AC 310 ms
8,868 KB
testcase_12 AC 268 ms
8,800 KB
testcase_13 AC 48 ms
8,824 KB
testcase_14 AC 704 ms
8,892 KB
testcase_15 AC 831 ms
9,128 KB
testcase_16 AC 257 ms
8,944 KB
testcase_17 AC 157 ms
8,592 KB
testcase_18 AC 44 ms
8,536 KB
testcase_19 AC 72 ms
8,708 KB
testcase_20 AC 605 ms
9,056 KB
testcase_21 AC 137 ms
8,748 KB
testcase_22 AC 54 ms
8,688 KB
testcase_23 AC 1,119 ms
9,156 KB
testcase_24 AC 1,124 ms
9,344 KB
testcase_25 AC 1,062 ms
9,164 KB
testcase_26 AC 537 ms
9,136 KB
testcase_27 AC 1,123 ms
9,132 KB
testcase_28 AC 1,116 ms
9,192 KB
testcase_29 AC 1,119 ms
9,324 KB
testcase_30 AC 1,118 ms
9,276 KB
testcase_31 AC 1,111 ms
9,148 KB
testcase_32 AC 1,113 ms
9,344 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
sys.setrecursionlimit(10 ** 6)
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