結果

問題 No.187 中華風 (Hard)
ユーザー tjaketjake
提出日時 2018-09-30 17:50:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 728 ms / 3,000 ms
コード長 532 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-20 13:43:56
合計ジャッジ時間 10,187 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 378 ms
11,136 KB
testcase_01 AC 338 ms
11,136 KB
testcase_02 AC 52 ms
10,880 KB
testcase_03 AC 52 ms
10,880 KB
testcase_04 AC 671 ms
11,008 KB
testcase_05 AC 691 ms
11,136 KB
testcase_06 AC 673 ms
11,136 KB
testcase_07 AC 661 ms
11,136 KB
testcase_08 AC 724 ms
11,136 KB
testcase_09 AC 723 ms
11,136 KB
testcase_10 AC 728 ms
11,264 KB
testcase_11 AC 685 ms
11,136 KB
testcase_12 AC 682 ms
11,136 KB
testcase_13 AC 34 ms
10,880 KB
testcase_14 AC 34 ms
10,880 KB
testcase_15 AC 45 ms
11,008 KB
testcase_16 AC 48 ms
11,008 KB
testcase_17 AC 26 ms
10,752 KB
testcase_18 AC 240 ms
11,008 KB
testcase_19 AC 27 ms
10,752 KB
testcase_20 AC 482 ms
11,008 KB
testcase_21 AC 27 ms
10,624 KB
testcase_22 AC 691 ms
11,136 KB
testcase_23 AC 27 ms
10,752 KB
testcase_24 AC 27 ms
10,752 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