結果

問題 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
コンパイル時間 251 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 18,464 KB
最終ジャッジ日時 2024-05-08 17:03:58
合計ジャッジ時間 26,993 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
16,640 KB
testcase_01 AC 29 ms
11,008 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 895 ms
11,392 KB
testcase_04 TLE -
testcase_05 AC 1,327 ms
11,392 KB
testcase_06 AC 1,808 ms
11,520 KB
testcase_07 AC 1,688 ms
11,392 KB
testcase_08 AC 1,085 ms
11,392 KB
testcase_09 AC 148 ms
11,520 KB
testcase_10 AC 1,706 ms
11,392 KB
testcase_11 AC 1,027 ms
11,392 KB
testcase_12 AC 847 ms
11,392 KB
testcase_13 AC 150 ms
11,392 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 AC 836 ms
11,264 KB
testcase_17 AC 494 ms
11,136 KB
testcase_18 AC 131 ms
11,008 KB
testcase_19 AC 219 ms
11,008 KB
testcase_20 TLE -
testcase_21 AC 426 ms
11,264 KB
testcase_22 AC 160 ms
11,136 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