結果

問題 No.187 中華風 (Hard)
ユーザー cielciel
提出日時 2015-04-20 17:43:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 467 ms / 3,000 ms
コード長 583 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 80,672 KB
最終ジャッジ日時 2023-09-18 01:22:19
合計ジャッジ時間 8,885 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
77,364 KB
testcase_01 AC 127 ms
77,592 KB
testcase_02 AC 169 ms
78,472 KB
testcase_03 AC 180 ms
80,140 KB
testcase_04 AC 444 ms
79,312 KB
testcase_05 AC 447 ms
78,452 KB
testcase_06 AC 436 ms
78,472 KB
testcase_07 AC 456 ms
80,672 KB
testcase_08 AC 464 ms
79,416 KB
testcase_09 AC 467 ms
79,296 KB
testcase_10 AC 463 ms
79,432 KB
testcase_11 AC 443 ms
78,596 KB
testcase_12 AC 443 ms
78,612 KB
testcase_13 AC 128 ms
77,440 KB
testcase_14 AC 132 ms
77,664 KB
testcase_15 AC 163 ms
78,572 KB
testcase_16 AC 171 ms
78,544 KB
testcase_17 AC 113 ms
72,604 KB
testcase_18 AC 124 ms
77,620 KB
testcase_19 AC 109 ms
72,380 KB
testcase_20 AC 349 ms
78,372 KB
testcase_21 AC 108 ms
72,384 KB
testcase_22 AC 438 ms
78,544 KB
testcase_23 AC 109 ms
72,492 KB
testcase_24 AC 106 ms
72,648 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