結果

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

テストケース

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

ソースコード

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

md = 10 ** 9 + 7
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 - 1) % md + 1
        y1 = lcm(y1, y2)
    ans = (x1 - 1) % y1 + 1
    print(ans % md)

main()
0