結果

問題 No.61 リベリオン
ユーザー Mao-betaMao-beta
提出日時 2024-03-03 14:52:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 379 ms / 5,000 ms
コード長 1,820 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 78,648 KB
最終ジャッジ日時 2024-03-03 14:52:55
合計ジャッジ時間 1,980 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
55,744 KB
testcase_01 AC 46 ms
57,828 KB
testcase_02 AC 47 ms
57,828 KB
testcase_03 AC 375 ms
78,648 KB
testcase_04 AC 379 ms
78,264 KB
testcase_05 AC 45 ms
55,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353

input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
EI = lambda m: [NLI() for _ in range(m)]


def main():
    Q = NI()
    for qi in range(Q):
        # print("#", qi)
        W, H, D, Mx, My, Hx, Hy, Vx, Vy = NMI()
        XY = [[0]*(H+1) for _ in range(W+1)]
        XY[Hx][Hy] = 1
        g = math.gcd(Vx, Vy)
        if Vx == 0:
            D *= abs(Vy)
            Vy //= abs(Vy)
        elif Vy == 0:
            D *= abs(Vx)
            Vx //= abs(Vx)
        else:
            Vx //= g
            Vy //= g

        nx, ny = Hx, Hy
        while D > 0:
            nx += Vx
            ny += Vy
            D = min(D, 4*(H+1)*(W+1))
            while True:
                if nx < 0:
                    nx = -nx
                    Vx = -Vx
                if nx > W:
                    nx = 2*W - nx
                    Vx = -Vx
                if ny < 0:
                    ny = -ny
                    Vy = -Vy
                if ny > H:
                    ny = 2*H - ny
                    Vy = -Vy
                if 0 <= nx <= W and 0 <= ny <= H:
                    break

            XY[nx][ny] = 1
            D -= 1
            # print(nx, ny)
            # print(*XY, sep="\n")
            # print()
        if XY[Mx][My]:
            print("Hit")
        else:
            print("Miss")



if __name__ == "__main__":
    main()
0