結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,576 KB
testcase_01 AC 16 ms
8,292 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)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

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