結果

問題 No.187 中華風 (Hard)
ユーザー yaoshimaxyaoshimax
提出日時 2015-05-10 22:46:24
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 834 bytes
コンパイル時間 1,595 ms
コンパイル使用メモリ 77,484 KB
実行使用メモリ 81,328 KB
最終ジャッジ日時 2023-09-20 01:46:42
合計ジャッジ時間 6,145 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
76,436 KB
testcase_01 AC 69 ms
76,312 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 185 ms
81,024 KB
testcase_05 AC 183 ms
80,992 KB
testcase_06 AC 157 ms
80,352 KB
testcase_07 AC 187 ms
80,628 KB
testcase_08 AC 179 ms
80,116 KB
testcase_09 AC 184 ms
80,176 KB
testcase_10 AC 180 ms
80,252 KB
testcase_11 AC 166 ms
80,704 KB
testcase_12 AC 174 ms
80,768 KB
testcase_13 AC 88 ms
79,008 KB
testcase_14 AC 87 ms
78,880 KB
testcase_15 WA -
testcase_16 AC 177 ms
79,916 KB
testcase_17 AC 71 ms
76,284 KB
testcase_18 AC 70 ms
76,420 KB
testcase_19 AC 70 ms
76,168 KB
testcase_20 AC 164 ms
79,892 KB
testcase_21 AC 72 ms
76,568 KB
testcase_22 AC 164 ms
79,956 KB
testcase_23 AC 71 ms
76,284 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def extgcd(A,B):
    #return p,q,r such that Ap+Bq=r
    if A>B:
        q,p,r=extgcd(B,A)
        return p,q,r
    if A==0:
        return 0,1,B
    # B=cA+R then Ap+Bq=Ap+(cA+R)q=(cq+p)A+qR
    c=B/A
    R=B%A
    q,cqp,r=extgcd(R,A)
    return cqp-c*q,q,r

def gcd(A,B):
    if B<A:
        return gcd(B,A)
    if B%A==0:
        return A
    return gcd(B%A,A)

N=int(raw_input())
A,B=map(int,raw_input().split())
if A==0: 
    A=B
for i in range(N-1):
    X,Y=map(int,raw_input().split())
    # find smallest A+Bp==X+Yq <=Bp-Yq=X-A
    #print "find ",A,"+",B,"p==",X,"+",Y,"q"
    p,q,r=extgcd(B,Y)
    #print B,"*",p,"+",Y,"*",q,"=",r
    if abs(X-A)%r!=0:
        print -1
        exit()
    #now Bp+Yq=1
    #print A,"+",B*Y,(p*(X-A))%Y 
    A=((p*(X-A)/r)%Y)*B+A
    B*=Y/gcd(Y,B)
    if A<X:
         A=X
print A%1000000007

0