結果

問題 No.187 中華風 (Hard)
ユーザー proriboneproribone
提出日時 2024-02-16 16:23:28
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 604 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 78,020 KB
最終ジャッジ日時 2024-02-16 16:23:36
合計ジャッジ時間 7,725 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
63,064 KB
testcase_01 AC 52 ms
63,064 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 WA -
testcase_14 WA -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 37 ms
53,460 KB
testcase_18 AC 49 ms
60,964 KB
testcase_19 AC 37 ms
53,460 KB
testcase_20 RE -
testcase_21 WA -
testcase_22 RE -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def crt(r,m):
    def extgcd(a,b):
        if b==0:
            return 1,0,a
        else:
            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

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)
else:
    print(r)
0