結果
問題 | No.187 中華風 (Hard) |
ユーザー | hly1204 |
提出日時 | 2021-05-08 09:38:08 |
言語 | Python3 (3.11.6 + numpy 1.26.0 + scipy 1.11.3) |
結果 |
WA
|
実行時間 | - |
コード長 | 826 bytes |
コンパイル時間 | 104 ms |
コンパイル使用メモリ | 10,864 KB |
実行使用メモリ | 8,364 KB |
最終ジャッジ日時 | 2023-10-14 12:38:15 |
合計ジャッジ時間 | 2,894 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 18 ms
7,892 KB |
testcase_01 | AC | 18 ms
7,804 KB |
testcase_02 | AC | 43 ms
8,356 KB |
testcase_03 | AC | 43 ms
8,228 KB |
testcase_04 | AC | 78 ms
8,276 KB |
testcase_05 | AC | 78 ms
8,356 KB |
testcase_06 | AC | 78 ms
8,192 KB |
testcase_07 | AC | 79 ms
8,216 KB |
testcase_08 | AC | 82 ms
8,212 KB |
testcase_09 | AC | 82 ms
8,332 KB |
testcase_10 | AC | 83 ms
8,192 KB |
testcase_11 | AC | 78 ms
8,208 KB |
testcase_12 | AC | 79 ms
8,232 KB |
testcase_13 | AC | 20 ms
7,812 KB |
testcase_14 | AC | 20 ms
7,848 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 16 ms
7,844 KB |
testcase_18 | AC | 16 ms
7,864 KB |
testcase_19 | AC | 16 ms
7,784 KB |
testcase_20 | AC | 65 ms
8,316 KB |
testcase_21 | AC | 17 ms
7,880 KB |
testcase_22 | AC | 81 ms
8,276 KB |
testcase_23 | AC | 16 ms
7,904 KB |
testcase_24 | AC | 17 ms
7,872 KB |
ソースコード
# -*- coding: UTF-8 -*- def exgcd(a: int, b: int) -> (int, int, int): # 返回 (gcd(a,b), x, y) 满足 gcd(a,b)=ax+by x1, x2, x3, x4 = 1, 0, 0, 1 while b != 0: q = a // b x1, x2, x3, x4, a, b = x3, x4, x1 - x3 * q, x2 - x4 * q, b, a - b * q return a, x1, x2 def gcrt2(a: int, m1: int, b: int, m2: int) -> (int, int): d, x, y = exgcd(m1, m2) bma = b - a if bma % d != 0: return -1, -1 t, y = m2 // d, bma // d res = x * y % t if res < 0: res += t return res * m1 + a, m1 * t if __name__ == '__main__': n = int(input()) ans, m0 = 0, 1 for _ in range(0, n): c, d = (int(i) for i in input().split(' ')) ans, m0 = gcrt2(ans, m0, c, d) if ans == -1: break print(-1 if ans == -1 else ans % 1000000007)