結果
問題 | No.187 中華風 (Hard) |
ユーザー | onexisan |
提出日時 | 2015-05-21 00:33:21 |
言語 | Python2 (2.7.18) |
結果 |
WA
|
実行時間 | - |
コード長 | 598 bytes |
コンパイル時間 | 453 ms |
コンパイル使用メモリ | 6,672 KB |
実行使用メモリ | 7,984 KB |
最終ジャッジ日時 | 2023-09-20 10:27:11 |
合計ジャッジ時間 | 3,257 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 25 ms
7,868 KB |
testcase_01 | AC | 25 ms
7,724 KB |
testcase_02 | WA | - |
testcase_03 | AC | 60 ms
7,864 KB |
testcase_04 | AC | 87 ms
7,788 KB |
testcase_05 | AC | 88 ms
7,784 KB |
testcase_06 | AC | 90 ms
7,816 KB |
testcase_07 | AC | 90 ms
7,900 KB |
testcase_08 | AC | 91 ms
7,828 KB |
testcase_09 | AC | 92 ms
7,984 KB |
testcase_10 | AC | 94 ms
7,860 KB |
testcase_11 | AC | 87 ms
7,828 KB |
testcase_12 | AC | 87 ms
7,984 KB |
testcase_13 | AC | 28 ms
7,848 KB |
testcase_14 | AC | 29 ms
7,868 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 23 ms
7,668 KB |
testcase_18 | AC | 25 ms
7,888 KB |
testcase_19 | AC | 22 ms
7,692 KB |
testcase_20 | AC | 73 ms
7,804 KB |
testcase_21 | AC | 22 ms
7,620 KB |
testcase_22 | AC | 90 ms
7,896 KB |
testcase_23 | AC | 23 ms
7,660 KB |
testcase_24 | AC | 22 ms
7,732 KB |
ソースコード
from fractions import gcd def inv(a, m): b, x, y = m, 1, 0 while b != 0: t = a // b a, b = b, a - t * b x, y = y, x - t * y pass return x % m def CRT(congs): x, m = 0, 1 for y, n in congs: g = gcd(m, n) if x % g != y % g: return -1, -1 m //= g; n *= m; m *= gcd(m, g); n //= m x %= m; x += (y - x % n + n) * inv(m, n) % n * m; m *= n pass return x, m mod = 10 ** 9 + 7 n = input() congs = [map(int, raw_input().split()) for _ in xrange(n)] ans = CRT(congs)[0] print -1 if ans == -1 else ans % mod