結果

問題 No.187 中華風 (Hard)
ユーザー fmhrfmhr
提出日時 2015-04-20 07:38:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 800 ms / 3,000 ms
コード長 689 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 10,708 KB
実行使用メモリ 8,568 KB
最終ジャッジ日時 2023-09-18 00:11:15
合計ジャッジ時間 9,563 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,404 KB
testcase_01 AC 19 ms
8,264 KB
testcase_02 AC 44 ms
8,532 KB
testcase_03 AC 42 ms
8,236 KB
testcase_04 AC 732 ms
8,432 KB
testcase_05 AC 728 ms
8,412 KB
testcase_06 AC 725 ms
8,564 KB
testcase_07 AC 730 ms
8,560 KB
testcase_08 AC 800 ms
8,568 KB
testcase_09 AC 800 ms
8,496 KB
testcase_10 AC 800 ms
8,504 KB
testcase_11 AC 733 ms
8,408 KB
testcase_12 AC 732 ms
8,560 KB
testcase_13 AC 20 ms
8,384 KB
testcase_14 AC 19 ms
8,420 KB
testcase_15 AC 37 ms
8,176 KB
testcase_16 AC 38 ms
8,200 KB
testcase_17 AC 16 ms
7,808 KB
testcase_18 AC 18 ms
8,268 KB
testcase_19 AC 16 ms
7,748 KB
testcase_20 AC 500 ms
8,548 KB
testcase_21 AC 15 ms
7,864 KB
testcase_22 AC 729 ms
8,472 KB
testcase_23 AC 16 ms
7,804 KB
testcase_24 AC 16 ms
7,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding=utf-8

import sys

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

def crt(p, m, q, n):
    a, d, r = egcd(p, q)
    if (n - m) % a != 0:
        return (-1, -1)
    mod = p * (q // a)
    a = (d * ((n - m) // a) * p + m) % mod
    return (a, mod)

def chinese_remainder(items):
    xx = 0
    yy = 1
    for x, y in items:
        xx, yy = crt(y, x, yy, xx)
        if xx == -1:
            print(-1)
            sys.exit(0)
    if xx == 0:
        xx = yy
    return xx

n = int(input())
x = [0] * n
for i in range(n):
    x[i] = tuple(map(int, input().split()))
print(chinese_remainder(x) % (10**9+7))
0