結果

問題 No.187 中華風 (Hard)
ユーザー tjaketjake
提出日時 2017-01-02 16:40:19
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 473 bytes
コンパイル時間 502 ms
コンパイル使用メモリ 6,920 KB
実行使用メモリ 6,444 KB
最終ジャッジ日時 2023-08-22 08:49:17
合計ジャッジ時間 12,838 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 399 ms
6,444 KB
testcase_01 AC 391 ms
6,316 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 800 ms
6,428 KB
testcase_05 AC 796 ms
6,416 KB
testcase_06 AC 798 ms
6,328 KB
testcase_07 AC 800 ms
6,292 KB
testcase_08 AC 872 ms
6,280 KB
testcase_09 AC 872 ms
6,364 KB
testcase_10 AC 871 ms
6,296 KB
testcase_11 AC 801 ms
6,324 KB
testcase_12 AC 800 ms
6,344 KB
testcase_13 AC 16 ms
6,212 KB
testcase_14 AC 16 ms
6,176 KB
testcase_15 AC 37 ms
6,192 KB
testcase_16 AC 38 ms
6,296 KB
testcase_17 AC 11 ms
5,924 KB
testcase_18 AC 264 ms
6,376 KB
testcase_19 AC 12 ms
6,032 KB
testcase_20 AC 547 ms
6,284 KB
testcase_21 AC 11 ms
5,992 KB
testcase_22 AC 795 ms
6,344 KB
testcase_23 AC 11 ms
6,040 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

n = input()
d = 1
x = 0
v = []
for i in xrange(n):
    X, Y = map(int, raw_input().split())
    g, a, b = extgcd(d, Y)
    x, d = (Y / g)*b*x + d*a*X, d*(Y / g)
    x = (x + d) % d
    v.append((X, Y))

for X, Y in v:
    if x % Y != X:
        print -1
        exit(0)
if x == 0:
    print d % (10**9+7)
else:
    print x % (10**9+7)
0