結果

問題 No.187 中華風 (Hard)
ユーザー tora3kuma3tora3kuma3
提出日時 2015-05-02 20:43:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 545 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 10,792 KB
実行使用メモリ 8,648 KB
最終ジャッジ日時 2023-09-19 05:05:39
合計ジャッジ時間 9,903 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 41 ms
8,204 KB
testcase_03 AC 40 ms
8,404 KB
testcase_04 AC 727 ms
8,648 KB
testcase_05 AC 728 ms
8,480 KB
testcase_06 AC 724 ms
8,440 KB
testcase_07 AC 724 ms
8,488 KB
testcase_08 AC 789 ms
8,320 KB
testcase_09 AC 790 ms
8,488 KB
testcase_10 AC 794 ms
8,512 KB
testcase_11 AC 724 ms
8,648 KB
testcase_12 AC 725 ms
8,612 KB
testcase_13 AC 19 ms
8,308 KB
testcase_14 AC 19 ms
8,324 KB
testcase_15 AC 35 ms
8,288 KB
testcase_16 AC 36 ms
8,276 KB
testcase_17 AC 16 ms
7,848 KB
testcase_18 WA -
testcase_19 AC 16 ms
7,792 KB
testcase_20 AC 496 ms
8,492 KB
testcase_21 AC 16 ms
7,776 KB
testcase_22 AC 726 ms
8,568 KB
testcase_23 AC 16 ms
7,888 KB
testcase_24 AC 16 ms
7,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
readline = stdin.readline


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


def chinese(xy):
    xx, yy = 0, 1

    for x, y in xy:
        a, b, c = extended_gcd(yy, y)
        d, m = divmod(xx - x, c)
        if m:
            return -1
        yy = yy * y // c
        xx = (y * d * b + x) % yy
    return xx if xx else yy

n = int(readline())
xy = [list(map(int, readline().split())) for _ in range(n)]
print(chinese(xy) % 1000000007)
0