結果

問題 No.187 中華風 (Hard)
ユーザー fmhrfmhr
提出日時 2015-04-20 07:25:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 689 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 10,748 KB
実行使用メモリ 9,108 KB
最終ジャッジ日時 2023-09-17 23:41:34
合計ジャッジ時間 9,687 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
8,844 KB
testcase_01 AC 23 ms
8,676 KB
testcase_02 AC 51 ms
8,888 KB
testcase_03 AC 49 ms
9,012 KB
testcase_04 AC 740 ms
9,060 KB
testcase_05 AC 735 ms
8,920 KB
testcase_06 AC 732 ms
8,988 KB
testcase_07 AC 738 ms
8,956 KB
testcase_08 AC 802 ms
8,976 KB
testcase_09 AC 803 ms
9,092 KB
testcase_10 AC 806 ms
9,108 KB
testcase_11 AC 739 ms
9,060 KB
testcase_12 AC 737 ms
8,916 KB
testcase_13 AC 25 ms
8,876 KB
testcase_14 AC 25 ms
8,856 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 20 ms
8,588 KB
testcase_18 AC 23 ms
8,812 KB
testcase_19 AC 20 ms
8,648 KB
testcase_20 AC 506 ms
9,088 KB
testcase_21 AC 20 ms
8,568 KB
testcase_22 AC 735 ms
9,016 KB
testcase_23 AC 20 ms
8,692 KB
testcase_24 AC 21 ms
8,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python

import sys
from functools import reduce

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

def crt(p, m, q, n):
	a, d, r = egcd(p, q)
	if (n - m) % a != 0:
		return (-1, -1)
	mod = p * (q // a)
	a = (d * ((n - m) // a) * p + m) % mod
	return (a, mod)

def chinese_remainder(items):
	xx = 0
	yy = 1
	for x, y in items:
		xx, yy = crt(y, x, yy, xx)
		if xx == -1:
			print(-1)
			sys.exit(0)
	if xx == 0: xx == yy
	return xx
	
#print(chinese_remainder([(10, 20), (10, 30), (10, 40)]))
n = int(input())
x = [0] * n
for i in range(n):
	x[i] = tuple(map(int, input().split()))
print(chinese_remainder(x) % (10**9+7))
0