結果

問題 No.187 中華風 (Hard)
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-06-22 12:56:36
言語 Python2
(2.7.18)
結果
AC  
実行時間 99 ms / 3,000 ms
コード長 777 bytes
コンパイル時間 862 ms
コンパイル使用メモリ 6,540 KB
実行使用メモリ 8,204 KB
最終ジャッジ日時 2023-09-21 23:14:58
合計ジャッジ時間 3,845 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
7,944 KB
testcase_01 AC 25 ms
7,896 KB
testcase_02 AC 58 ms
8,028 KB
testcase_03 AC 57 ms
8,028 KB
testcase_04 AC 96 ms
8,004 KB
testcase_05 AC 95 ms
8,204 KB
testcase_06 AC 95 ms
8,000 KB
testcase_07 AC 95 ms
8,052 KB
testcase_08 AC 98 ms
7,996 KB
testcase_09 AC 99 ms
7,992 KB
testcase_10 AC 98 ms
8,060 KB
testcase_11 AC 95 ms
8,008 KB
testcase_12 AC 96 ms
8,136 KB
testcase_13 AC 26 ms
7,720 KB
testcase_14 AC 26 ms
7,724 KB
testcase_15 AC 56 ms
8,000 KB
testcase_16 AC 57 ms
8,024 KB
testcase_17 AC 22 ms
7,668 KB
testcase_18 AC 24 ms
7,776 KB
testcase_19 AC 21 ms
7,752 KB
testcase_20 AC 79 ms
7,908 KB
testcase_21 AC 22 ms
7,684 KB
testcase_22 AC 94 ms
8,076 KB
testcase_23 AC 20 ms
7,632 KB
testcase_24 AC 21 ms
7,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
from fractions import gcd

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

def mod_inv(a, div):
    x, y, d = extgcd(a, div)
    return x % div if d==1 else None

def linear_congruence(A, B, M):
    x, m = 0, 1
    for i in xrange(len(A)):
        a, b = A[i] * m, B[i] - A[i] * x
        d = gcd(M[i], a)
        if(b % d != 0):
            return 0, -1
        t = b / d * mod_inv(a/d, M[i]/d) % (M[i] / d)
        x = x + m * t
        m *= M[i] / d
    return x % m, m

N = int(raw_input())
xys = [map(int, raw_input().split()) for _ in xrange(N)]
zipped = zip(*xys)
res = linear_congruence([1] * N, *(zipped))
if res[1] == -1:
    print -1
else:
    print (res[0] or res[1]) % (int(1e9) + 7)
0