結果

問題 No.187 中華風 (Hard)
ユーザー tjaketjake
提出日時 2018-09-30 17:50:22
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 804 ms / 3,000 ms
コード長 532 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 10,836 KB
実行使用メモリ 8,676 KB
最終ジャッジ日時 2023-08-02 13:41:00
合計ジャッジ時間 11,547 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 369 ms
8,596 KB
testcase_01 AC 363 ms
8,528 KB
testcase_02 AC 41 ms
8,184 KB
testcase_03 AC 42 ms
8,232 KB
testcase_04 AC 737 ms
8,676 KB
testcase_05 AC 736 ms
8,544 KB
testcase_06 AC 735 ms
8,560 KB
testcase_07 AC 737 ms
8,624 KB
testcase_08 AC 803 ms
8,652 KB
testcase_09 AC 804 ms
8,540 KB
testcase_10 AC 802 ms
8,496 KB
testcase_11 AC 738 ms
8,648 KB
testcase_12 AC 737 ms
8,536 KB
testcase_13 AC 19 ms
8,316 KB
testcase_14 AC 18 ms
8,220 KB
testcase_15 AC 32 ms
8,196 KB
testcase_16 AC 32 ms
8,276 KB
testcase_17 AC 15 ms
7,816 KB
testcase_18 AC 244 ms
8,580 KB
testcase_19 AC 15 ms
7,864 KB
testcase_20 AC 505 ms
8,508 KB
testcase_21 AC 14 ms
7,796 KB
testcase_22 AC 735 ms
8,608 KB
testcase_23 AC 15 ms
7,788 KB
testcase_24 AC 15 ms
7,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def extgcd(a, b):
    if b:
        d, y, x = extgcd(b, a % b)
        y -= (a // b) * x
        return d, x, y
    return a, 1, 0

def remainder(V):
    x = 0; d = 1
    for X, Y in V:
        g, a, b = extgcd(d, Y)
        x, d = (Y*b*x + d*a*X) // g, d*(Y // g)
        x %= d
    return x, d


N = int(input())
V = [list(map(int, input().split())) for i in range(N)]

x, d = remainder(V)

for X, Y in V:
    if x % Y != X:
        print(-1)
        exit(0)
MOD = 10**9 + 7
if x == 0:
    print(d % MOD)
else:
    print(x % MOD)
0