結果

問題 No.61 リベリオン
ユーザー nebukuro09nebukuro09
提出日時 2017-03-09 15:16:40
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 281 ms / 5,000 ms
コード長 1,778 bytes
コンパイル時間 1,277 ms
コンパイル使用メモリ 91,864 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-03 01:54:12
合計ジャッジ時間 2,040 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 278 ms
4,388 KB
testcase_04 AC 281 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/dmd2/linux/bin64/../../src/phobos/std/numeric.d(2999): Warning: cannot inline function `std.numeric.gcdImpl!uint.gcdImpl`

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    int Q;
    scanf("%d", &Q);
    
    foreach (i; 0..Q) {
        int W, H, D, mx, my, hx, hy, vx, vy;
        scanf("%d %d %d %d %d %d %d %d %d", &W, &H, &D, &mx, &my, &hx, &hy, &vx, &vy);

        auto g = gcd(abs(vx), abs(vy));
        auto used = new bool[][][][](W+1, H+1, 2, 2);
        bool hit = false;
        bool end = false;
        
        foreach (_; 0..D) {
            foreach (j; 0..g) {
                
                hx += vx/g, hy += vy/g;
                
                while (hx < 0 || hx > W) {
                    if (hx > W) {
                        hx = 2 * W - hx;
                        vx *= -1;
                    }
                    else if (hx < 0) {
                        hx = -hx;
                        vx *= -1;
                    }
                }
                while (hy < 0 || hy > H) {
                    if (hy > H) {
                        hy = 2 * H - hy;
                        vy *= -1;
                    }
                    else if (hy < 0) {
                        hy = -hy;
                        vy *= -1;
                    }
                }

                if (hx == mx && hy == my) {
                    hit = true;
                    end = true;
                    break;
                }
                if (used[hx][hy][vx>0][vy>0]) {
                    end = true;
                    break;
                }

                used[hx][hy][vx>0][vy>0] = true;
            }
            
            if (end) break;
        }

        writeln(hit ? "Hit" : "Miss");
    }
}
0