結果

問題 No.61 リベリオン
ユーザー nebukuro09nebukuro09
提出日時 2017-03-09 15:15:24
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 2,736 bytes
コンパイル時間 889 ms
コンパイル使用メモリ 104,580 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 01:47:20
合計ジャッジ時間 2,022 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 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;

void main() {
    int Q = readln.chomp.to!int;
    
    foreach (i; 0..Q) {
        auto s = readln.split.map!(to!int);
        int W, H, D, mx, my, hx, hy, vx, vy;
        W = s[0], H = s[1], D = s[2], mx = s[3], my = s[4];
        hx = s[5], hy = s[6], vx = s[7], vy = s[8];

        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;
                
                if (hx > W) {
                    int p = (hx - W) / W;
                    int q = (hx - W) % W;
                    if (p % 2 == 1) {
                        hx = W - q;
                        vx = -abs(vx);
                    }
                    else {
                        hx = q;
                        vx = abs(vx);
                    }
                }
                else if (hx < 0) {
                    int p = (-hx) / W;
                    int q = (-hx) % W;
                    if (p % 2 == 0) {
                        hx = W - q;
                        vx = -abs(vx);
                    }
                    else {
                        hx = q;
                        vx = abs(vx);
                    }
                }

                if (hy > H) {
                    int p = (hy - H) / H;
                    int q = (hy - H) % H;
                    if (p % 2 == 1) {
                        hy = H - q;
                        vy = -abs(vy);
                    }
                    else {
                        hy = q;
                        vy = abs(vy);
                    }
                }
                else if (hy < 0) {
                    int p = (-hy) / H;
                    int q = (-hy) % H;
                    if (p % 2 == 0) {
                        hy = H - q;
                        vy = -abs(vy);
                    }
                    else {
                        hy = q;
                        vy = abs(vy);
                    }
                }

                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