結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー brthyyjpbrthyyjp
提出日時 2021-06-11 21:33:12
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,278 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 11,128 KB
実行使用メモリ 14,128 KB
最終ジャッジ日時 2023-08-21 11:42:48
合計ジャッジ時間 22,861 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,820 KB
testcase_01 AC 20 ms
8,964 KB
testcase_02 AC 20 ms
8,912 KB
testcase_03 AC 749 ms
9,420 KB
testcase_04 AC 1,727 ms
9,360 KB
testcase_05 AC 1,139 ms
9,496 KB
testcase_06 AC 1,495 ms
9,612 KB
testcase_07 AC 1,398 ms
9,284 KB
testcase_08 AC 904 ms
9,412 KB
testcase_09 AC 120 ms
9,400 KB
testcase_10 AC 1,389 ms
9,640 KB
testcase_11 AC 835 ms
9,288 KB
testcase_12 AC 708 ms
9,340 KB
testcase_13 AC 121 ms
9,232 KB
testcase_14 AC 1,889 ms
9,564 KB
testcase_15 TLE -
testcase_16 AC 673 ms
9,444 KB
testcase_17 AC 409 ms
9,288 KB
testcase_18 AC 101 ms
9,112 KB
testcase_19 AC 180 ms
8,964 KB
testcase_20 AC 1,875 ms
9,448 KB
testcase_21 AC 359 ms
9,408 KB
testcase_22 AC 130 ms
9,128 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
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