結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,284 KB
testcase_01 AC 14 ms
6,024 KB
testcase_02 AC 56 ms
6,168 KB
testcase_03 AC 54 ms
6,308 KB
testcase_04 AC 812 ms
6,344 KB
testcase_05 AC 810 ms
6,296 KB
testcase_06 AC 814 ms
6,236 KB
testcase_07 AC 812 ms
6,232 KB
testcase_08 AC 878 ms
6,432 KB
testcase_09 AC 888 ms
6,440 KB
testcase_10 AC 891 ms
6,324 KB
testcase_11 AC 814 ms
6,276 KB
testcase_12 AC 808 ms
6,368 KB
testcase_13 AC 16 ms
6,176 KB
testcase_14 AC 15 ms
5,988 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 11 ms
6,032 KB
testcase_18 AC 13 ms
6,060 KB
testcase_19 AC 12 ms
6,032 KB
testcase_20 AC 560 ms
6,432 KB
testcase_21 AC 12 ms
6,132 KB
testcase_22 AC 809 ms
6,444 KB
testcase_23 AC 11 ms
6,064 KB
testcase_24 AC 11 ms
6,076 KB
権限があれば一括ダウンロードができます

ソースコード

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 + 7
print X[0] % MOD
0