結果

問題 No.61 リベリオン
ユーザー ytftytft
提出日時 2022-11-07 02:59:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 859 ms / 5,000 ms
コード長 1,663 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 86,432 KB
実行使用メモリ 85,888 KB
最終ジャッジ日時 2023-09-27 18:38:27
合計ジャッジ時間 3,202 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
70,944 KB
testcase_01 AC 78 ms
70,948 KB
testcase_02 AC 73 ms
71,216 KB
testcase_03 AC 859 ms
85,888 KB
testcase_04 AC 757 ms
85,704 KB
testcase_05 AC 74 ms
71,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda:sys.stdin.readline().rstrip()
def gcd(a,b):
	return gcd(a%b,b%a) if min(a,b,abs(a-b)) else max(a,b)
def lcm(a,b):
	return a*b//gcd(a,b)
def euclid(a,b,c):
    if a==b==0:
        return [[1,1],-1][c!=0]
    if a<0 or b<0:
        temp=euclid(abs(a),abs(b),c)
        return -1 if temp==-1 else [[1,-1][a<0]*temp[0],[1,-1][b<0]*temp[1]]
    if a==0:
        return -1 if c%b else [0,c//b]
    if b==0:
        return -1 if c%a else [c//a,0]
    if b>a:
        temp=euclid(a,b%a,c)
        return -1 if temp==-1 else [temp[0]-(b//a)*temp[1],temp[1]]
    else:
        temp=euclid(a%b,b,c)
        return -1 if temp==-1 else [temp[0],temp[1]-(a//b)*temp[0]]
def calc(a,b,ma,mb,ra,rb):
	#print(a,b,ma,mb,ra,rb)
	a%=ma
	b%=mb
	ra%=ma
	rb%=mb
	#print(a,b,ma,mb,ra,rb)
	k=[euclid(a,-ma,ra),euclid(b,-mb,rb)]
	#print(k[0][0],k[1][0])
	if -1 in k:
		return float('inf')
	#print(ma//gcd(ma,a),-mb//gcd(mb,b),k[1][0]-k[0][0])
	l=euclid(ma//gcd(ma,a),-mb//gcd(mb,b),k[1][0]-k[0][0])
	#print(l)
	if l==-1:
		return float('inf')
	ret=l[0]*a//gcd(ma,a)+k[0][0]
	#print(a//gcd(ma,a),b//gcd(mb,b))
	#print(ret,lcm(a//gcd(ma,a),b//gcd(mb,b)))
	if a*b!=0:
		ret%=lcm(a//gcd(ma,a),b//gcd(mb,b))
	#print(ret)
	return ret
def solve():
	temp=list(map(int,input().split()))
	g=gcd(abs(temp[7]),abs(temp[8]))
	temp[2]*=g
	temp[7]//=g
	temp[8]//=g
	test=[[temp[3]-temp[5],2*temp[0]-temp[3]-temp[5]],[temp[4]-temp[6],2*temp[1]-temp[4]-temp[6]]]
	flg=0
	for i in range(4):
		cur=[test[0][i//2],test[1][i%2]]
		flg|=(calc(temp[7],temp[8],2*temp[0],2*temp[1],*cur)<=temp[2])
	print(["Miss","Hit"][flg])
#print(euclid(9,10,9))
N=int(input())
for i in range(N):
	solve()
0