結果

問題 No.187 中華風 (Hard)
ユーザー cielciel
提出日時 2015-04-20 17:45:13
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 434 ms / 3,000 ms
コード長 499 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 77,964 KB
実行使用メモリ 81,308 KB
最終ジャッジ日時 2023-09-18 01:23:19
合計ジャッジ時間 7,441 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
79,212 KB
testcase_01 AC 87 ms
78,972 KB
testcase_02 AC 149 ms
80,128 KB
testcase_03 AC 152 ms
81,308 KB
testcase_04 AC 415 ms
81,016 KB
testcase_05 AC 409 ms
80,180 KB
testcase_06 AC 407 ms
80,172 KB
testcase_07 AC 414 ms
81,152 KB
testcase_08 AC 430 ms
80,152 KB
testcase_09 AC 433 ms
80,140 KB
testcase_10 AC 434 ms
80,176 KB
testcase_11 AC 407 ms
80,532 KB
testcase_12 AC 406 ms
80,132 KB
testcase_13 AC 89 ms
79,244 KB
testcase_14 AC 89 ms
79,292 KB
testcase_15 AC 125 ms
80,052 KB
testcase_16 AC 134 ms
80,172 KB
testcase_17 AC 77 ms
76,524 KB
testcase_18 AC 86 ms
79,220 KB
testcase_19 AC 75 ms
76,520 KB
testcase_20 AC 316 ms
80,008 KB
testcase_21 AC 77 ms
76,256 KB
testcase_22 AC 413 ms
80,496 KB
testcase_23 AC 75 ms
76,364 KB
testcase_24 AC 77 ms
76,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
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