結果
問題 | No.62 リベリオン(Extra) |
ユーザー |
![]() |
提出日時 | 2015-04-08 20:46:24 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 401 ms / 5,000 ms |
コード長 | 2,197 bytes |
コンパイル時間 | 487 ms |
コンパイル使用メモリ | 7,040 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2024-07-04 13:19:24 |
合計ジャッジ時間 | 1,483 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 3 |
ソースコード
def extgcd(a, b):if b == 0:return (a, 1, 0)(g, y, x) = extgcd(b, a % b)return (g, x, y - (a // b) * x)def easy(M, H, V, HW, OM, OH, D):if OM != OH:return "Miss"if H >= M:if(HW - M <= D * V):return "Hit"else:return "Miss"else:if(HW * 2 - H - M <= D * V):return "Hit"else:return "Miss"def solve(TY, H, W, D, MY):TY -= MYif TY < 0:TY += (TY / (2 * H)) * (2 * H)while TY < 0:TY += 2 * HA = 2 * HB = 2 * Wgcd, mb, ma = extgcd(B, A)if TY % gcd != 0:return Falseloop = A * B / gcdma *= TY / gcd;mb *= TY / gcd;step = (2 * W) * mbstep %= loopwhile step < 0:step += loopreturn step <= Ddef check(P, W):P %= W * 2;if P <= W:return Pelse:return (2*W) - P;def calc(W, H, D, HX, HY, MX, MY, VX, VY):if VY == 0:return easy(MX, HX, VX, W, MY, HY, D)if VX == 0:return easy(MY, HY, VY, H, MX, HX, D)mulX = VXmulY = VYH *= mulXMY *= mulXHY *= mulXW *= mulYMX *= mulYHX *= mulYD *= mulY;D *= mulX;move = 0flag = Falseif MX <= HX:move = HX - MXflag = Trueelse:move = W + W - HX - MXMX += moveMY += moveD-= moveif solve(HY, H, W, D, MY) or solve(H + H - HY, H, W, D, MY):return "Hit"else:if flag:move = 2 * (W - HX)else:move = 2 * HXMX += moveMY += moveD-= moveif solve(HY, H, W, D, MY) or solve(H + H - HY, H, W, D, MY):return "Hit"else:return "Miss"Q = int(raw_input())W = H = D = MX = MY = HX = HY = VX = VY = 0while Q > 0:Q -= 1W, H, D, MX, MY, HX, HY, VX, VY = map(int,raw_input().strip().split())if VY < 0:MY = H - MYHY = H - HYVY = -VYif VX < 0:MX = W - MXHX = W - HXVX = -VXprint(calc(W, H, D, MX, MY, HX, HY, VX, VY))