結果

問題 No.186 中華風 (Easy)
ユーザー cielciel
提出日時 2015-04-20 17:44:05
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 2,417 ms
コンパイル使用メモリ 77,464 KB
実行使用メモリ 77,700 KB
最終ジャッジ日時 2023-09-27 00:45:34
合計ジャッジ時間 3,616 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
77,140 KB
testcase_01 AC 81 ms
77,264 KB
testcase_02 AC 79 ms
77,268 KB
testcase_03 AC 80 ms
77,260 KB
testcase_04 AC 77 ms
77,660 KB
testcase_05 AC 78 ms
77,300 KB
testcase_06 AC 79 ms
77,400 KB
testcase_07 AC 78 ms
77,272 KB
testcase_08 AC 79 ms
77,300 KB
testcase_09 AC 80 ms
77,672 KB
testcase_10 AC 80 ms
77,336 KB
testcase_11 AC 79 ms
77,500 KB
testcase_12 AC 78 ms
77,152 KB
testcase_13 AC 79 ms
77,484 KB
testcase_14 AC 78 ms
77,144 KB
testcase_15 AC 78 ms
77,660 KB
testcase_16 AC 79 ms
77,448 KB
testcase_17 AC 79 ms
77,652 KB
testcase_18 AC 79 ms
77,700 KB
testcase_19 AC 79 ms
77,420 KB
testcase_20 AC 79 ms
77,424 KB
testcase_21 AC 79 ms
77,416 KB
testcase_22 AC 79 ms
77,420 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(3):
	a.append(tuple(int(e) for e in raw_input().split()))
r=chinese(a)
print(r[not r[0]] if r else -1)
0