結果

問題 No.187 中華風 (Hard)
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-20 00:12:05
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 167 ms / 3,000 ms
コード長 687 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 77,764 KB
実行使用メモリ 81,092 KB
最終ジャッジ日時 2023-09-18 02:14:16
合計ジャッジ時間 4,365 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
76,384 KB
testcase_01 AC 75 ms
76,448 KB
testcase_02 AC 142 ms
80,836 KB
testcase_03 AC 143 ms
80,280 KB
testcase_04 AC 163 ms
80,804 KB
testcase_05 AC 157 ms
80,092 KB
testcase_06 AC 155 ms
79,972 KB
testcase_07 AC 161 ms
81,092 KB
testcase_08 AC 155 ms
79,840 KB
testcase_09 AC 157 ms
79,912 KB
testcase_10 AC 156 ms
79,992 KB
testcase_11 AC 156 ms
80,076 KB
testcase_12 AC 154 ms
79,868 KB
testcase_13 AC 95 ms
79,156 KB
testcase_14 AC 91 ms
78,984 KB
testcase_15 AC 124 ms
79,980 KB
testcase_16 AC 133 ms
79,960 KB
testcase_17 AC 74 ms
76,556 KB
testcase_18 AC 75 ms
76,316 KB
testcase_19 AC 76 ms
76,656 KB
testcase_20 AC 143 ms
79,936 KB
testcase_21 AC 75 ms
76,316 KB
testcase_22 AC 167 ms
80,164 KB
testcase_23 AC 74 ms
76,804 KB
testcase_24 AC 79 ms
76,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


N = int(raw_input()) - 1
ans, add = map(int,raw_input().strip().split());
if ans == 0:
    ans = ans + add

while N > 0:
    N = N - 1
    X, Y = map(int,raw_input().strip().split())

    g, a, b = extgcd(add, Y)
    now = ans % Y
    need = X - now
    if need < 0:
        need = need + Y
    if need % g != 0:
        ans = -1
        break
    need = need / g
    ans = ans + (add * a) * need
    add = add * (Y / g)
    ans = ans % add
    if ans < 0:
        ans = ans + add

if ans == 0:
    ans = add
if ans >= 0:
    ans = ans % 1000000007
print ans
0