結果
問題 | No.186 中華風 (Easy) |
ユーザー | maspy |
提出日時 | 2020-03-03 21:13:20 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 16 ms / 2,000 ms |
コード長 | 936 bytes |
コンパイル時間 | 87 ms |
コンパイル使用メモリ | 10,876 KB |
実行使用メモリ | 8,252 KB |
最終ジャッジ日時 | 2023-09-27 00:58:56 |
合計ジャッジ時間 | 1,402 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 15 ms
8,164 KB |
testcase_01 | AC | 14 ms
7,784 KB |
testcase_02 | AC | 15 ms
7,788 KB |
testcase_03 | AC | 15 ms
7,776 KB |
testcase_04 | AC | 16 ms
7,756 KB |
testcase_05 | AC | 15 ms
7,908 KB |
testcase_06 | AC | 15 ms
7,776 KB |
testcase_07 | AC | 15 ms
7,748 KB |
testcase_08 | AC | 15 ms
7,760 KB |
testcase_09 | AC | 15 ms
7,836 KB |
testcase_10 | AC | 14 ms
8,240 KB |
testcase_11 | AC | 15 ms
7,920 KB |
testcase_12 | AC | 15 ms
7,780 KB |
testcase_13 | AC | 15 ms
7,712 KB |
testcase_14 | AC | 15 ms
7,836 KB |
testcase_15 | AC | 15 ms
7,872 KB |
testcase_16 | AC | 15 ms
7,872 KB |
testcase_17 | AC | 14 ms
7,756 KB |
testcase_18 | AC | 15 ms
7,796 KB |
testcase_19 | AC | 14 ms
8,124 KB |
testcase_20 | AC | 15 ms
8,252 KB |
testcase_21 | AC | 16 ms
8,124 KB |
testcase_22 | AC | 15 ms
8,128 KB |
ソースコード
#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% m = map(int, read().split()) XY = zip(m, m) X, Y = zip(*XY) # %% class NotFoundError(Exception): pass def extgcd(a, b): """return x,y,d such that ax + by = d > 0""" x, y, u, v, s, t = 1, 0, 0, 1, a, b while t: k = s // t s, t = t, s - k * t x, u = u, x - k * u y, v = v, y - k * v return x, y, s def CRT(a, n, b, m): """find (c, mod) where x = a (n), x = b (m) iff x = c (mod)""" p, q, d = extgcd(n, m) if (a - b) % d != 0: raise NotFoundError mod = n * (m // d) a += n * ((b - a) // d * p % (m // d)) return a, mod # %% x, n = 0, 1 for y, m in zip(X, Y): try: x, n = CRT(x, n, y, m) except NotFoundError: print(-1) exit() x %= n if not x: x = n print(x)