結果
| 問題 |
No.1544 [Cherry 2nd Tune C] Synchroscope
|
| コンテスト | |
| ユーザー |
kozy
|
| 提出日時 | 2021-06-11 21:25:22 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 740 bytes |
| コンパイル時間 | 410 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 23,168 KB |
| 最終ジャッジ日時 | 2024-12-14 22:17:54 |
| 合計ジャッジ時間 | 87,906 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 TLE * 25 |
ソースコード
import math
INF=float('inf')
def lcm(a,b):
return a*b//math.gcd(a,b)
def two_crt(mod1,mod2,i,j):
g=math.gcd(mod1,mod2)
if i%g!=j%g:
return INF
else:
INV=pow(mod1//g,-1,mod2//g)
return (i+(((j-i)//g)*mod1*INV))%lcm(mod1,mod2)
def crt(L):
thismod=L[0][0]
thisnum=L[0][1]
for i in range(1,len(L)):
thisnum=two_crt(thismod,L[i][0],thisnum,L[i][1])
thismod=lcm(thismod,L[i][0])
return thisnum,thismod
N,M=map(int,input().split())
L=list(map(int,input().split()))
R=list(map(int,input().split()))
ans=10**10
for i in range(N):
for j in range(M):
if L[i]==R[j]:
a=two_crt(N,M,i,j)
if a==INF:
continue
else:
ans=min(ans,a)
if ans==10**10:
print(-1)
else:
print(ans+1)
kozy