結果

問題 No.61 リベリオン
ユーザー commycommy
提出日時 2018-08-11 01:22:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 2,991 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 80,648 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 17:21:07
合計ジャッジ時間 1,666 ms
ジャッジサーバーID
(参考情報)
judge1 / 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 138 ms
5,376 KB
testcase_04 AC 139 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int sign(int n) {
    if (n > 0) {
        return 1;
    } else if (n < 0) {
        return -1;
    } else {
        return 0;
    }
}

int main() {
    int Q;
    cin >> Q;
    while (Q--) {
        int W, H, D, Mx, My, Hx, Hy, Vx, Vy;
        cin >> W >> H >> D >> Mx >> My >> Hx >> Hy >> Vx >> Vy;
        auto used = make_v(H + 1, W + 1, 9, false);
        int g = gcd(abs(Vx), abs(Vy));
        Vx /= g;
        Vy /= g;
        int Bx = Hx, By = Hy;
        int dx = sign(Vx), dy = sign(Vy);
        Vx = abs(Vx);
        Vy = abs(Vy);
        bool ok = false, end = false;
        REP(i, 0, D) {
            REP(j, 0, g) {
                Bx += dx * Vx;
                By += dy * Vy;
                REP(_, 0, 11) {
                    if (Bx <= 0) {
                        Bx = -Bx;
                        dx = -dx;
                    }
                    if (Bx >= W) {
                        Bx = 2 * W - Bx;
                        dx = -dx;
                    }
                }
                if (Bx == 0) {
                    dx = 1;
                }
                if (Bx == W) {
                    dx = -1;
                }
                REP(_, 0, 11) {
                    if (By <= 0) {
                        By = -By;
                        dy = -dy;
                    }
                    if (By >= H) {
                        By = 2 * H - By;
                        dy = -dy;
                    }
                }
                if (By == 0) {
                    dy = 1;
                }
                if (By == H) {
                    dy = -1;
                }
                int direc = 3 * (dx + 1) + (dy + 1);
                //cout << Bx << "(" << dx << ") " << By << "(" << dy << ") " << used[By][Bx][direc] << endl;
                if (Bx < 0 || Bx > W || By < 0 || By > H) {
                    end = true;
                    break;
                }
                if (By == My && Bx == Mx) {
                    ok = true;
                    end = true;
                    break;
                }
                if (used[By][Bx][direc]) {
                    end = true;
                    break;
                }
                used[By][Bx][direc] = true;
            }
            if (end) {
                break;
            }
        }
        cout << (ok ? "Hit" : "Miss") << endl;
    }
    return 0;
}
0