結果
問題 | No.187 中華風 (Hard) |
ユーザー | rpy3cpp |
提出日時 | 2015-09-18 20:10:23 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 844 bytes |
コンパイル時間 | 268 ms |
コンパイル使用メモリ | 87,192 KB |
実行使用メモリ | 81,120 KB |
最終ジャッジ日時 | 2023-09-26 12:26:23 |
合計ジャッジ時間 | 4,584 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 85 ms
75,488 KB |
testcase_01 | AC | 88 ms
75,640 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | AC | 72 ms
71,284 KB |
testcase_18 | AC | 84 ms
75,212 KB |
testcase_19 | AC | 72 ms
71,448 KB |
testcase_20 | WA | - |
testcase_21 | AC | 73 ms
71,360 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 73 ms
71,200 KB |
ソースコード
def read_data(): N = int(input()) xy = [] for n in range(N): x, y = map(int, input().split()) xy.append((x, y)) return N, xy def gcd_ext(m, n): x, y, u, v = 1, 0, 0, 1 while n: k, m = divmod(m, n) m, n = n, m x, y, u, v = u, v, x - u * k, y - v * k return m, x, y def solve2(x1, y1, x2, y2): gcd, a, b = gcd_ext(y1, y2) lcm = y1 * y2 // gcd k, r = divmod(x1 - x2, gcd) if r != 0: return -1, lcm z = (x1 - k * a * y1) % lcm return z, lcm def solve(N, xy): x0, y0 = xy[0] if N == 1: return x0 if x0 else y0 mod = 10 ** 9 + 7 for x1, y1 in xy[1:]: x0, y0 = solve2(x0, y0, x1, y1) if x0 == -1: return -1 x0 %= mod return x0 if x0 else y0 N, xy = read_data() print(solve(N, xy))