結果

問題 No.187 中華風 (Hard)
ユーザー pekempeypekempey
提出日時 2015-08-30 17:08:29
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 597 bytes
コンパイル時間 521 ms
コンパイル使用メモリ 6,504 KB
実行使用メモリ 6,516 KB
最終ジャッジ日時 2023-09-25 19:50:15
合計ジャッジ時間 11,172 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,128 KB
testcase_01 AC 14 ms
6,100 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 12 ms
6,048 KB
testcase_18 AC 13 ms
6,108 KB
testcase_19 AC 12 ms
6,196 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def gcd(a, b):
	if b == 0: return a
	return gcd(b, a % b)

def solve(a1, m1, a2, m2):
	g = gcd(m1, m2)
	l = m1 / g * m2
	p, q = extgcd(m1, m2)
	if (a2 - a1) % g != 0:
		return (0, -1)
	p *= (a2 - a1) / g
	x = p * m1 + a1
	x %= l
	x += l
	x %= l
	return (x, l)

N = input()
X = [0] * N
Y = [0] * N
for i in xrange(N):
	X[i], Y[i] = map(int, raw_input().split())

for i in xrange(1, N):
	X[0], Y[0] = solve(X[0], Y[0], X[i], Y[i])
	if Y[0] == -1:
		print -1
		exit()

MOD = 10 ** 9 + 9
print X[0] % MOD
0