結果

問題 No.187 中華風 (Hard)
ユーザー snukesnuke
提出日時 2015-04-20 16:11:33
言語 Python2
(2.7.18)
結果
AC  
実行時間 880 ms / 3,000 ms
コード長 368 bytes
コンパイル時間 66 ms
コンパイル使用メモリ 6,600 KB
実行使用メモリ 6,224 KB
最終ジャッジ日時 2023-09-18 01:15:48
合計ジャッジ時間 10,348 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,052 KB
testcase_01 AC 11 ms
6,004 KB
testcase_02 AC 44 ms
6,044 KB
testcase_03 AC 44 ms
6,056 KB
testcase_04 AC 806 ms
6,220 KB
testcase_05 AC 797 ms
6,080 KB
testcase_06 AC 803 ms
6,084 KB
testcase_07 AC 801 ms
6,084 KB
testcase_08 AC 872 ms
6,216 KB
testcase_09 AC 880 ms
6,224 KB
testcase_10 AC 874 ms
6,064 KB
testcase_11 AC 808 ms
6,224 KB
testcase_12 AC 797 ms
6,084 KB
testcase_13 AC 15 ms
5,908 KB
testcase_14 AC 14 ms
5,960 KB
testcase_15 AC 37 ms
6,052 KB
testcase_16 AC 38 ms
6,032 KB
testcase_17 AC 11 ms
5,832 KB
testcase_18 AC 11 ms
5,832 KB
testcase_19 AC 11 ms
5,908 KB
testcase_20 AC 548 ms
6,132 KB
testcase_21 AC 11 ms
6,004 KB
testcase_22 AC 800 ms
6,200 KB
testcase_23 AC 11 ms
5,828 KB
testcase_24 AC 12 ms
5,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def extgcd(x,y):
  if y == 0: return (x,1,0)
  g,a,b = extgcd(y,x%y);
  return (g,b,a-x//y*b)

def solve():
  n = int(raw_input())
  a = 0
  b = 1
  for i in xrange(n):
    na,nb = map(int,raw_input().split())
    g,x,y = extgcd(b,nb)
    if a%g != na%g: return -1
    l = b/g*nb
    a,b = ((a+(na-a)/g*x*b)%l,l)
  if a == 0: a = b
  return a%1000000007
print solve()
0