結果

問題 No.187 中華風 (Hard)
ユーザー parukiparuki
提出日時 2016-08-27 12:08:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 802 ms / 3,000 ms
コード長 811 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-26 06:14:24
合計ジャッジ時間 9,632 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
11,008 KB
testcase_01 AC 33 ms
10,880 KB
testcase_02 AC 95 ms
11,008 KB
testcase_03 AC 92 ms
11,008 KB
testcase_04 AC 728 ms
11,008 KB
testcase_05 AC 730 ms
11,008 KB
testcase_06 AC 733 ms
11,136 KB
testcase_07 AC 736 ms
11,008 KB
testcase_08 AC 802 ms
11,008 KB
testcase_09 AC 791 ms
11,136 KB
testcase_10 AC 793 ms
11,136 KB
testcase_11 AC 728 ms
11,136 KB
testcase_12 AC 726 ms
11,008 KB
testcase_13 AC 36 ms
11,008 KB
testcase_14 AC 37 ms
10,880 KB
testcase_15 AC 85 ms
11,008 KB
testcase_16 AC 85 ms
10,880 KB
testcase_17 AC 29 ms
11,008 KB
testcase_18 AC 32 ms
11,008 KB
testcase_19 AC 30 ms
10,880 KB
testcase_20 AC 507 ms
11,136 KB
testcase_21 AC 29 ms
11,008 KB
testcase_22 AC 731 ms
11,008 KB
testcase_23 AC 28 ms
11,008 KB
testcase_24 AC 28 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def exgcd(a, b):
    if b==0: return 1,0,a
    r = exgcd(b, a%b)
    return r[1],r[0]-a//b*r[1],r[2]

def crt(a0, m0, a1, m1):
    g = exgcd(m0,m1)[2]
    if a0%g!=a1%g: return -1,-1
    if g > 1:
        m0//=g
        m1//=g
        while True:
            h = exgcd(m0,g)[2]
            if h==1: break
            m0*=h
            g//=h
        m1 *= g
        a0 %= m0
        a1 %= m1
    r = exgcd(m0, m1)
    p,q,g=r[0],r[1],r[2]
    x = a0*q*m1+a1*p*m0
    m=m0*m1
    x%=m
    if x<0: x+=m
    return x,m

MOD = 1000000007
X=[]
Y=[]
N = int(input())

for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)

x, y = X[0], Y[0]
for i in range(1, N):
    x, y = crt(x, y, X[i], Y[i])
    if x==-1:
        print(-1)
        exit()
if x==0: print(y%MOD)
else: print(x%MOD)
0