結果

問題 No.186 中華風 (Easy)
ユーザー proriboneproribone
提出日時 2020-12-22 15:53:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 563 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 11,872 KB
実行使用メモリ 10,120 KB
最終ジャッジ日時 2023-10-21 12:58:52
合計ジャッジ時間 1,729 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,120 KB
testcase_01 AC 32 ms
10,120 KB
testcase_02 AC 31 ms
10,120 KB
testcase_03 AC 32 ms
10,120 KB
testcase_04 AC 29 ms
10,120 KB
testcase_05 AC 28 ms
10,120 KB
testcase_06 AC 28 ms
10,120 KB
testcase_07 AC 33 ms
10,120 KB
testcase_08 AC 28 ms
10,120 KB
testcase_09 AC 28 ms
10,120 KB
testcase_10 AC 29 ms
10,120 KB
testcase_11 AC 28 ms
10,120 KB
testcase_12 AC 28 ms
10,120 KB
testcase_13 AC 30 ms
10,120 KB
testcase_14 AC 28 ms
10,120 KB
testcase_15 AC 28 ms
10,120 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 31 ms
10,120 KB
testcase_19 AC 29 ms
10,120 KB
testcase_20 AC 28 ms
10,120 KB
testcase_21 AC 30 ms
10,120 KB
testcase_22 AC 30 ms
10,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def extgcd(a,b):
    if b==0:
        return a,1,0
    else:
        r,p=a//b,a%b
        g,x,y=extgcd(b,p)
        return g,y,x-r*y

def crt(B,M):
    r,z=0,1
    for b,m in zip(B,M):
        b1,m1=r,z
        b2,m2=b,m
        g,x,y=extgcd(m1,m2)
        x,y=(b2-b1)//g*x,(b2-b1)//g*y
        if b1%g!=b2%g:
            return (0,0)
        a=(m1*x+b1)%(m1*m2//g)
        r,z=a,m1*m2//g
    return r,z

b,m=[],[]
for _ in range(3):
    x,y=map(int,input().split())
    b.append(x)
    m.append(y)

r,z=crt(b,m)
if r==0 and z==0:
    print(-1)
else:
    print(r)
0