結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー O2MT
提出日時 2021-06-11 23:06:29
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 419 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 139,648 KB
最終ジャッジ日時 2024-12-15 02:07:12
合計ジャッジ時間 10,166 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 47 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
flg = False
p = []
ans = float('inf')
for i in range(N):
  for j in range(M):
    if A[i] == B[j]:
      flg = True
      num = 0
      while num*N+i+1 < N*M+1:
        m = (num*N+i-j)/M
        if m.is_integer():
          break
        num += 1
      ans = min(ans,num*N+i+1)

if flg:
  print(ans)
else:
  print(-1)
0