結果

問題 No.187 中華風 (Hard)
ユーザー mkawa2mkawa2
提出日時 2020-01-27 13:34:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 684 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 10,792 KB
実行使用メモリ 15,892 KB
最終ジャッジ日時 2023-10-12 12:55:35
合計ジャッジ時間 4,801 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
12,576 KB
testcase_01 AC 16 ms
8,184 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())

def gcd(a, b):
    while b: a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

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

def main():
    n = II()
    x1, y1 = MI()
    for _ in range(n - 1):
        x2, y2 = MI()
        p, q, g = extgcd(y1, -y2, x2 - x1)
        if (x2 - x1) % g > 0:
            print(-1)
            exit()
        x1 = y1 * p + x1
        y1 = lcm(y1, y2)
    ans = (x1 - 1) % y1 + 1
    print(ans)

main()
0