結果

問題 No.61 リベリオン
ユーザー MisterMister
提出日時 2020-08-22 09:32:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 5,000 ms
コード長 1,072 bytes
コンパイル時間 937 ms
コンパイル使用メモリ 79,772 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 06:59:53
合計ジャッジ時間 1,427 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 22 ms
5,376 KB
testcase_04 AC 22 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <numeric>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

void next(int& x, int& vx, int h) {
    x += vx;
    while (true) {
        if (x < 0) {
            x = -x;
        } else if (x > h) {
            x = h * 2 - x;
        } else {
            break;
        }
        vx = -vx;
    }
}

void solve() {
    int h, w, d, gx, gy, sx, sy, vx, vy;
    std::cin >> h >> w >> d >>
        gx >> gy >> sx >> sy >> vx >> vy;

    int g = std::abs(std::gcd(vx, vy));
    d *= g, vx /= g, vy /= g;

    auto visited = vec(h + 1, vec(w + 1, 0));

    for (int t = 0; t <= d; ++t) {
        if (sx == gx && sy == gy) {
            std::cout << "Hit\n";
            return;
        }

        if (visited[sx][sy] == 4) break;
        ++visited[sx][sy];

        next(sx, vx, h), next(sy, vy, w);
    }

    std::cout << "Miss\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int q;
    std::cin >> q;
    while (q--) solve();

    return 0;
}
0