結果

問題 No.187 中華風 (Hard)
ユーザー proriboneproribone
提出日時 2024-02-16 17:26:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 453 ms / 3,000 ms
コード長 602 bytes
コンパイル時間 1,090 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,612 KB
最終ジャッジ日時 2024-02-16 17:26:48
合計ジャッジ時間 7,820 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
63,192 KB
testcase_01 AC 50 ms
63,192 KB
testcase_02 AC 101 ms
75,212 KB
testcase_03 AC 103 ms
75,344 KB
testcase_04 AC 415 ms
76,464 KB
testcase_05 AC 426 ms
76,464 KB
testcase_06 AC 393 ms
76,104 KB
testcase_07 AC 400 ms
76,336 KB
testcase_08 AC 451 ms
76,612 KB
testcase_09 AC 440 ms
76,484 KB
testcase_10 AC 453 ms
76,612 KB
testcase_11 AC 403 ms
76,208 KB
testcase_12 AC 394 ms
76,232 KB
testcase_13 AC 53 ms
63,192 KB
testcase_14 AC 52 ms
63,192 KB
testcase_15 AC 90 ms
75,208 KB
testcase_16 AC 90 ms
75,340 KB
testcase_17 AC 41 ms
53,460 KB
testcase_18 AC 48 ms
61,092 KB
testcase_19 AC 36 ms
53,460 KB
testcase_20 AC 321 ms
75,824 KB
testcase_21 AC 37 ms
53,460 KB
testcase_22 AC 404 ms
76,336 KB
testcase_23 AC 37 ms
53,460 KB
testcase_24 AC 37 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def crt(r,m):
    def extgcd(a,b):
        if b==0:
            return 1,0,a
        c,x,g=extgcd(b,a%b)
        return x,c-a//b*x,g
    
    r0,m0=0,1
    
    for i in range(len(r)):
        p,q,g=extgcd(m0,m[i])

        if r0%g!=r[i]%g:
            return 0,0

        s=(r[i]-r0)//g

        l=m0//g*m[i]
        x=(s*m0*p+r0)%l

        m0=l
        r0=x
    
    return r0,m0

MOD=10**9+7
N=int(input())
X,Y=[],[]
for _ in range(N):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)

r,m=crt(X,Y)

if r==0 and m==0:
    print(-1)
elif r==0:
    print(m%MOD)
else:
    print(r%MOD)
0