結果

問題 No.186 中華風 (Easy)
ユーザー snteasntea
提出日時 2016-10-14 13:04:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 912 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-05-01 22:45:01
合計ジャッジ時間 1,477 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
11,008 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 27 ms
10,880 KB
testcase_05 AC 25 ms
10,880 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 26 ms
10,880 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 26 ms
10,880 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 25 ms
10,880 KB
testcase_20 AC 25 ms
10,880 KB
testcase_21 AC 25 ms
10,880 KB
testcase_22 AC 26 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x%y)


def extgcd(a,b):
	if b == 1:
		return (0,1)
	else:
		t = extgcd(b,a%b)
		return (t[1], t[0]-a//b*t[1])

def solve(x0,y0,x1,y1):
	c = x0-x1
	a = y0
	b = -y1
	if c < 0:
		a = -a
		b = -b
	sm0 = 1
	sm1 = 1
	if a < 0:
		sm0 = -1
	if b < 0:
		sm1 = -1
	g = gcd(sm0*a,sm1*b)
	# print(c)
	if c != 0:
		if c%g != 0:
			return (-1,-1)
		ps = extgcd(sm0*a//g,sm1*b//g)
		# print(ps)
		ps = (ps[0]*sm0*c//g,ps[1]*sm1*c//g)
		# ps[1] = ps[1]*sm1*c//g
		ho = sm1*b//g
		ge = ps[0]
		return (ho*y0, x0+y0*ge)
	else:
		return (y0*sm1*b//g, x0)

if __name__ == '__main__':
	x = []
	y = []
	for i in range(3):
		a,b = map(int,input().split())
		x.append(a)
		y.append(b)
	s1 = solve(x[0],y[0],x[1],y[1])
	# print(s1)
	if s1[0] == -1:
		print(-1)
		exit()
	s2 = solve(s1[1],s1[0],x[2],y[2])
	if s2[0] == -1:
		print(-1)
		exit()
	# print(s2)
	print(s2[1]%s2[0])
0