結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー brthyyjpbrthyyjp
提出日時 2021-06-11 21:31:15
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,278 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 86,836 KB
実行使用メモリ 808,884 KB
最終ジャッジ日時 2023-08-21 11:38:21
合計ジャッジ時間 10,402 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
72,432 KB
testcase_01 AC 107 ms
72,164 KB
testcase_02 AC 100 ms
72,192 KB
testcase_03 AC 132 ms
77,272 KB
testcase_04 AC 159 ms
78,944 KB
testcase_05 AC 147 ms
79,108 KB
testcase_06 AC 154 ms
78,592 KB
testcase_07 AC 161 ms
79,716 KB
testcase_08 AC 146 ms
79,444 KB
testcase_09 AC 109 ms
77,176 KB
testcase_10 AC 157 ms
79,596 KB
testcase_11 AC 128 ms
77,380 KB
testcase_12 AC 129 ms
77,668 KB
testcase_13 AC 106 ms
76,960 KB
testcase_14 AC 161 ms
78,764 KB
testcase_15 AC 167 ms
79,404 KB
testcase_16 AC 126 ms
77,484 KB
testcase_17 AC 122 ms
77,532 KB
testcase_18 AC 109 ms
77,256 KB
testcase_19 AC 111 ms
77,232 KB
testcase_20 AC 159 ms
78,568 KB
testcase_21 AC 122 ms
77,544 KB
testcase_22 AC 109 ms
77,160 KB
testcase_23 AC 170 ms
78,260 KB
testcase_24 AC 168 ms
78,324 KB
testcase_25 AC 172 ms
78,480 KB
testcase_26 AC 173 ms
78,460 KB
testcase_27 AC 168 ms
78,364 KB
testcase_28 AC 171 ms
78,216 KB
testcase_29 AC 168 ms
78,400 KB
testcase_30 AC 169 ms
78,496 KB
testcase_31 AC 174 ms
78,236 KB
testcase_32 AC 170 ms
78,408 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 #

def extgcd(a, b):
    if b == 0:
        return 1, 0, a
    q, r = divmod(a, b)
    x, y, d = extgcd(b, r)
    s, t = y, x-q*y
    return s, t, d

def MOD(a, m):
    return (a%m + m)%m;

def CRT_list(b, m):
    # b: list
    # m: list
    # x ≡ bi (mod mi)を満たすx ≡ r (mod lcm(m1*m2..*mn))について
    # r, lcm(m1*m2..*mn)をreturn
    # 解無しの場合は0, -1をreturn
    r, M = 0, 1
    for i in range(len(b)):
        p, q, d = extgcd(M, m[i])
        if (b[i]-r)%d != 0:
            return 0, -1
        temp = (b[i]-r)//d * p % (m[i]//d)
        r += M * temp
        M *= m[i]//d
    return MOD(r, M), M

import math
from functools import reduce
def lcm_base(x, y):
  return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

n, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

res = float('inf')
P = []
for i, a in enumerate(A):
    for j, b in enumerate(B):
        if a == b:
            if i == j:
                res = min(res, i)
            else:
                P.append((i, j))

for p in P:
    r, M = CRT_list(p, [n, m])
    if M == -1:
        continue
    else:
        res = min(r, res)
if res != float('inf'):
    print(res+1)
else:
    print(-1)
0