結果

問題 No.187 中華風 (Hard)
ユーザー rpy3cpprpy3cpp
提出日時 2015-09-18 20:11:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 846 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 81,132 KB
最終ジャッジ日時 2023-09-26 12:26:32
合計ジャッジ時間 8,142 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
75,168 KB
testcase_01 AC 85 ms
75,648 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 WA -
testcase_14 WA -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 71 ms
71,416 KB
testcase_18 AC 83 ms
75,680 KB
testcase_19 AC 72 ms
71,324 KB
testcase_20 RE -
testcase_21 WA -
testcase_22 RE -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    N = int(input())
    xy = []
    for n in range(N):
        x, y = map(int, input().split())
        xy.append((x, y))
    return N, xy


def gcd_ext(m, n):
    x, y, u, v = 1, 0, 0, 1
    while n:
        k, m = divmod(m, n)
        m, n = n, m
        x, y, u, v = u, v, x - u * k, y - v * k
    return m, x, y


def solve2(x1, y1, x2, y2):
    gcd, a, b = gcd_ext(y1, y2)
    lcm = y1 * y2 // gcd
    k, r = divmod(x1 - x2, gcd)
    if r != 0:
        return -1, lcm
    z = (x1 - k * a * y1) % lcm
    return z, lcm


def solve(N, xy):
    x0, y0 = xy[0]
    if N == 1:
        return x0 if x0 else y0
    mod = 10 ** 9 + 7
    for x1, y1 in xy[1:]:
        x0, y0 = solve2(x0, y0, x1, y1)
        if x0 == -1:
            return -1
        # x0 %= mod
    return x0 if x0 else y0

N, xy = read_data()
print(solve(N, xy))
0