結果

問題 No.187 中華風 (Hard)
ユーザー mkawa2mkawa2
提出日時 2020-01-27 21:46:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 994 ms / 3,000 ms
コード長 1,021 bytes
コンパイル時間 620 ms
コンパイル使用メモリ 11,084 KB
実行使用メモリ 8,652 KB
最終ジャッジ日時 2023-10-12 16:32:54
合計ジャッジ時間 11,809 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,188 KB
testcase_01 AC 16 ms
8,204 KB
testcase_02 AC 42 ms
8,356 KB
testcase_03 AC 41 ms
8,352 KB
testcase_04 AC 910 ms
8,652 KB
testcase_05 AC 909 ms
8,572 KB
testcase_06 AC 913 ms
8,528 KB
testcase_07 AC 914 ms
8,532 KB
testcase_08 AC 994 ms
8,472 KB
testcase_09 AC 994 ms
8,536 KB
testcase_10 AC 993 ms
8,484 KB
testcase_11 AC 912 ms
8,368 KB
testcase_12 AC 914 ms
8,516 KB
testcase_13 AC 17 ms
8,376 KB
testcase_14 AC 17 ms
8,236 KB
testcase_15 AC 34 ms
8,188 KB
testcase_16 AC 34 ms
8,324 KB
testcase_17 AC 15 ms
7,868 KB
testcase_18 AC 16 ms
8,268 KB
testcase_19 AC 15 ms
7,788 KB
testcase_20 AC 630 ms
8,404 KB
testcase_21 AC 15 ms
7,836 KB
testcase_22 AC 910 ms
8,600 KB
testcase_23 AC 15 ms
7,784 KB
testcase_24 AC 16 ms
7,784 KB
権限があれば一括ダウンロードができます

ソースコード

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]

# a % y0 = x0
# a % y1 = x1
# a = y0 * p + x0
# a = y1 * q + x1
# まとめて
# y0 * p + x0 = y1 * q + x1
# y0 * p - y1 * q = x1 - x0

# a = lcm(y0,y1)*r + (y0 * p + x0)

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:
            print(-1)
            exit()
        x1 = y1 * p + x1
        y1 = y1 * y2 // g
        x1 %= y1
    ans = (x1 - 1) % y1 + 1
    print(ans % md)

main()
0