結果
問題 | No.187 中華風 (Hard) |
ユーザー | proribone |
提出日時 | 2024-02-17 01:22:20 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,357 bytes |
コンパイル時間 | 495 ms |
コンパイル使用メモリ | 81,700 KB |
実行使用メモリ | 77,376 KB |
最終ジャッジ日時 | 2024-02-17 01:22:33 |
合計ジャッジ時間 | 12,547 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
63,196 KB |
testcase_01 | AC | 58 ms
63,196 KB |
testcase_02 | AC | 632 ms
76,364 KB |
testcase_03 | AC | 552 ms
76,356 KB |
testcase_04 | AC | 787 ms
76,336 KB |
testcase_05 | AC | 782 ms
76,208 KB |
testcase_06 | AC | 763 ms
76,208 KB |
testcase_07 | AC | 770 ms
76,208 KB |
testcase_08 | AC | 544 ms
76,604 KB |
testcase_09 | AC | 559 ms
76,604 KB |
testcase_10 | AC | 536 ms
76,604 KB |
testcase_11 | AC | 776 ms
76,336 KB |
testcase_12 | AC | 597 ms
76,584 KB |
testcase_13 | AC | 157 ms
75,752 KB |
testcase_14 | AC | 166 ms
76,132 KB |
testcase_15 | AC | 683 ms
76,720 KB |
testcase_16 | AC | 719 ms
77,376 KB |
testcase_17 | AC | 39 ms
53,588 KB |
testcase_18 | AC | 50 ms
61,096 KB |
testcase_19 | AC | 39 ms
53,588 KB |
testcase_20 | AC | 494 ms
76,464 KB |
testcase_21 | AC | 39 ms
53,588 KB |
testcase_22 | AC | 754 ms
76,464 KB |
testcase_23 | WA | - |
testcase_24 | AC | 38 ms
53,588 KB |
ソースコード
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], coeffs[-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: res,l=garner(X,Y,10**9+7) if res==0: print(l) else: print(res)