結果

問題 No.187 中華風 (Hard)
ユーザー mkawa2mkawa2
提出日時 2020-01-27 13:49:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 946 bytes
コンパイル時間 1,537 ms
コンパイル使用メモリ 86,540 KB
実行使用メモリ 77,808 KB
最終ジャッジ日時 2023-10-12 12:55:47
合計ジャッジ時間 4,079 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
70,984 KB
testcase_01 AC 70 ms
70,788 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 AC 121 ms
76,152 KB
testcase_16 AC 122 ms
76,476 KB
testcase_17 AC 70 ms
71,092 KB
testcase_18 AC 72 ms
71,112 KB
testcase_19 AC 69 ms
71,036 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) % md
        y1 = lcm(y1, y2)
    ans = (x1 - 1) % y1 + 1
    print(ans % md)

main()
0