結果

問題 No.187 中華風 (Hard)
ユーザー cielciel
提出日時 2015-04-20 17:45:18
言語 Python2
(2.7.18)
結果
AC  
実行時間 879 ms / 3,000 ms
コード長 499 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 6,768 KB
実行使用メモリ 6,444 KB
最終ジャッジ日時 2023-09-18 01:25:27
合計ジャッジ時間 10,548 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
6,172 KB
testcase_01 AC 15 ms
6,176 KB
testcase_02 AC 45 ms
6,156 KB
testcase_03 AC 45 ms
6,356 KB
testcase_04 AC 807 ms
6,328 KB
testcase_05 AC 805 ms
6,236 KB
testcase_06 AC 804 ms
6,348 KB
testcase_07 AC 804 ms
6,316 KB
testcase_08 AC 879 ms
6,444 KB
testcase_09 AC 877 ms
6,320 KB
testcase_10 AC 872 ms
6,248 KB
testcase_11 AC 797 ms
6,304 KB
testcase_12 AC 795 ms
6,440 KB
testcase_13 AC 16 ms
6,028 KB
testcase_14 AC 16 ms
6,176 KB
testcase_15 AC 39 ms
6,068 KB
testcase_16 AC 39 ms
6,072 KB
testcase_17 AC 11 ms
5,864 KB
testcase_18 AC 15 ms
6,088 KB
testcase_19 AC 12 ms
5,976 KB
testcase_20 AC 585 ms
6,316 KB
testcase_21 AC 12 ms
6,112 KB
testcase_22 AC 798 ms
6,244 KB
testcase_23 AC 12 ms
6,072 KB
testcase_24 AC 12 ms
5,976 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