結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー brthyyjpbrthyyjp
提出日時 2021-06-11 21:32:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,296 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 79,656 KB
最終ジャッジ日時 2023-08-21 11:40:13
合計ジャッジ時間 9,520 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
72,528 KB
testcase_01 AC 106 ms
72,680 KB
testcase_02 AC 103 ms
72,460 KB
testcase_03 AC 134 ms
77,976 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 154 ms
78,664 KB
testcase_07 AC 155 ms
79,616 KB
testcase_08 AC 150 ms
79,584 KB
testcase_09 AC 113 ms
77,592 KB
testcase_10 AC 153 ms
79,632 KB
testcase_11 AC 136 ms
77,852 KB
testcase_12 AC 135 ms
77,872 KB
testcase_13 AC 116 ms
77,380 KB
testcase_14 AC 160 ms
79,048 KB
testcase_15 AC 166 ms
79,656 KB
testcase_16 AC 127 ms
77,688 KB
testcase_17 AC 126 ms
77,644 KB
testcase_18 AC 115 ms
77,448 KB
testcase_19 AC 117 ms
77,500 KB
testcase_20 AC 159 ms
78,876 KB
testcase_21 AC 124 ms
77,480 KB
testcase_22 AC 114 ms
77,452 KB
testcase_23 AC 164 ms
78,716 KB
testcase_24 AC 175 ms
78,692 KB
testcase_25 AC 169 ms
78,676 KB
testcase_26 AC 171 ms
79,424 KB
testcase_27 AC 165 ms
78,364 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 167 ms
78,564 KB
testcase_31 AC 162 ms
78,516 KB
testcase_32 AC 163 ms
78,364 KB
testcase_33 AC 125 ms
77,952 KB
testcase_34 AC 104 ms
72,144 KB
testcase_35 AC 104 ms
72,452 KB
testcase_36 AC 113 ms
77,432 KB
testcase_37 AC 114 ms
77,376 KB
testcase_38 AC 155 ms
77,388 KB
testcase_39 AC 152 ms
77,392 KB
testcase_40 AC 154 ms
77,620 KB
testcase_41 AC 156 ms
77,436 KB
testcase_42 AC 155 ms
77,608 KB
testcase_43 AC 151 ms
77,568 KB
testcase_44 AC 152 ms
77,564 KB
testcase_45 AC 153 ms
77,608 KB
testcase_46 AC 154 ms
77,616 KB
testcase_47 AC 153 ms
77,472 KB
権限があれば一括ダウンロードができます

ソースコード

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))
            break

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