結果
| 問題 |
No.187 中華風 (Hard)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-05-02 20:56:56 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 784 ms / 3,000 ms |
| コード長 | 574 bytes |
| コンパイル時間 | 75 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2024-07-05 17:33:32 |
| 合計ジャッジ時間 | 9,188 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
ソースコード
from sys import stdin
readline = stdin.readline
def extended_gcd(x, y):
if y == 0:
return 1, 0, x
a, b, c = extended_gcd(y, x % y)
return b, a - x // y * b, c
def chinese(xy):
xx, yy = 0, 1
for x, y in xy:
a, b, c = extended_gcd(yy, y)
d, m = divmod(xx - x, c)
if m:
return -1
yy = yy * y // c
xx = (y * d * b + x) % yy
return xx if xx else yy
n = int(readline())
xy = [list(map(int, readline().split())) for _ in range(n)]
ans = chinese(xy)
print(ans % 1000000007 if 0 < ans else -1)