結果

問題 No.187 中華風 (Hard)
ユーザー cielciel
提出日時 2015-04-20 17:43:31
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 439 ms / 3,000 ms
コード長 583 bytes
コンパイル時間 1,733 ms
コンパイル使用メモリ 77,424 KB
実行使用メモリ 81,968 KB
最終ジャッジ日時 2023-09-18 01:21:42
合計ジャッジ時間 8,943 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
78,940 KB
testcase_01 AC 88 ms
78,740 KB
testcase_02 AC 151 ms
80,004 KB
testcase_03 AC 154 ms
80,412 KB
testcase_04 AC 417 ms
80,892 KB
testcase_05 AC 412 ms
80,152 KB
testcase_06 AC 423 ms
80,032 KB
testcase_07 AC 417 ms
81,968 KB
testcase_08 AC 435 ms
80,244 KB
testcase_09 AC 435 ms
80,076 KB
testcase_10 AC 439 ms
80,084 KB
testcase_11 AC 408 ms
79,972 KB
testcase_12 AC 407 ms
80,176 KB
testcase_13 AC 94 ms
79,100 KB
testcase_14 AC 96 ms
78,832 KB
testcase_15 AC 130 ms
79,876 KB
testcase_16 AC 134 ms
79,860 KB
testcase_17 AC 77 ms
77,588 KB
testcase_18 AC 89 ms
78,800 KB
testcase_19 AC 81 ms
77,252 KB
testcase_20 AC 316 ms
80,108 KB
testcase_21 AC 81 ms
77,536 KB
testcase_22 AC 420 ms
80,168 KB
testcase_23 AC 80 ms
77,596 KB
testcase_24 AC 82 ms
77,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
from functools import reduce
import sys
if sys.version_info[0]>=3: raw_input=input

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

def perform(a1,m1,a2,m2):
	g,x,y=egcd(m1,m2)
	if (a2-a1)%g: raise ValueError
	l=m1//g*m2
	return ((a1+(a2-a1)//g*x*m1)%l,l)

def chinese(a):
	if not a: return None
	try:
		return reduce(lambda x,y:perform(*(x+y)),a)
	except ValueError:
		return None

a=[]
for _ in range(int(raw_input())):
	a.append(tuple(int(e) for e in raw_input().split()))
r=chinese(a)
print(r[not r[0]]%(10**9+7) if r else -1)
0