結果

問題 No.187 中華風 (Hard)
ユーザー fmhrfmhr
提出日時 2015-04-20 07:37:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 691 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 8,636 KB
最終ジャッジ日時 2023-09-18 00:08:55
合計ジャッジ時間 9,758 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,360 KB
testcase_01 AC 19 ms
8,288 KB
testcase_02 AC 42 ms
8,592 KB
testcase_03 AC 43 ms
8,548 KB
testcase_04 AC 735 ms
8,636 KB
testcase_05 AC 728 ms
8,612 KB
testcase_06 AC 730 ms
8,588 KB
testcase_07 AC 729 ms
8,632 KB
testcase_08 AC 801 ms
8,400 KB
testcase_09 AC 799 ms
8,392 KB
testcase_10 AC 798 ms
8,452 KB
testcase_11 AC 731 ms
8,576 KB
testcase_12 AC 732 ms
8,448 KB
testcase_13 AC 19 ms
8,216 KB
testcase_14 AC 19 ms
8,240 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 15 ms
7,784 KB
testcase_18 AC 18 ms
8,456 KB
testcase_19 AC 16 ms
7,856 KB
testcase_20 AC 501 ms
8,424 KB
testcase_21 AC 15 ms
7,844 KB
testcase_22 AC 731 ms
8,456 KB
testcase_23 AC 16 ms
7,960 KB
testcase_24 AC 16 ms
7,776 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