結果

問題 No.187 中華風 (Hard)
ユーザー proriboneproribone
提出日時 2024-02-17 01:19:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,285 bytes
コンパイル時間 459 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 77,248 KB
最終ジャッジ日時 2024-02-17 01:20:13
合計ジャッジ時間 11,394 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
63,068 KB
testcase_01 AC 52 ms
63,068 KB
testcase_02 AC 624 ms
76,236 KB
testcase_03 AC 538 ms
76,228 KB
testcase_04 AC 741 ms
76,208 KB
testcase_05 AC 734 ms
76,080 KB
testcase_06 AC 754 ms
76,208 KB
testcase_07 AC 745 ms
76,080 KB
testcase_08 AC 529 ms
76,476 KB
testcase_09 AC 531 ms
76,476 KB
testcase_10 AC 557 ms
76,476 KB
testcase_11 AC 680 ms
76,080 KB
testcase_12 AC 476 ms
76,456 KB
testcase_13 AC 133 ms
75,752 KB
testcase_14 AC 152 ms
76,004 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 32 ms
53,460 KB
testcase_18 AC 42 ms
60,968 KB
testcase_19 AC 33 ms
53,460 KB
testcase_20 AC 404 ms
76,336 KB
testcase_21 AC 37 ms
53,460 KB
testcase_22 AC 783 ms
76,336 KB
testcase_23 AC 39 ms
53,460 KB
testcase_24 AC 41 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def pregarner(r,m):
    def gcd(a,b):
        if b==0:
            return a
        return gcd(b,a%b)
    n=len(m)

    for i in range(n):
        for j in range(i):
            g=gcd(m[i],m[j])
            if (r[i]-r[j])%g!=0:
                return False
            
            m[i]//=g;m[j]//=g
            gi=gcd(m[i],g)
            gj=g//gi

            while gcd(gi,gj)!=1:
                h=gcd(gi,gj)
                gi*=h
                gj//=h
            
            m[i]*=gi
            m[j]*=gj
    
    return True

def garner(r,m,MOD):
    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
    
    def modinv(a,m):
        x,_,_=extgcd(a,m)
        return x%m
    
    n=len(r)
    m.append(MOD)

    constants=[0]*(n+1)
    coeffs=[1]*(n+1)
    
    for k in range(len(r)):
        t=(r[k]-constants[k])*modinv(coeffs[k],m[k])%m[k]
        for i in range(k+1,len(m)):
            constants[i]=(constants[i]+t*coeffs[i])%m[i]
            coeffs[i]=coeffs[i]*m[k]%m[i]

    return constants[-1]

N=int(input())
X,Y=[],[]

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

if not pregarner(X,Y):
    print(-1)
else:
    print(garner(X,Y,10**9+7))
0