結果

問題 No.61 リベリオン
ユーザー te-shte-sh
提出日時 2016-09-05 14:35:29
言語 D
(dmd 2.106.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,723 bytes
コンパイル時間 952 ms
コンパイル使用メモリ 102,696 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 21:55:55
合計ジャッジ時間 1,746 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

struct point {
  int x, y;

  point opBinary(string op)(point rhs) {
    static if (op == "+") return point(x + rhs.x, y + rhs.y);
    else static if (op == "-") return point(x - rhs.x, y - rhs.y);
  }
}

void main()
{
  auto q = readln.chomp.to!int;

  foreach (_; 0..q) {
    auto rd = readln.split.map!(to!int);
    auto w = rd[0], h = rd[1], d = rd[2];
    auto pm = point(rd[3], rd[4]), ph = point(rd[5], rd[6]), pv = point(rd[7], rd[8]);

    if (pv.x < 0) {
      pm = point(w - pm.x, pm.y);
      ph = point(w - ph.x, ph.y);
      pv = point(-pv.x, pv.y);
    }
    if (pv.y < 0) {
      pm = point(pm.x, h - pm.y);
      ph = point(ph.x, h - ph.y);
      pv = point(pv.x, -pv.y);
    }

    auto hw = h * w / gcd(h, w);
    auto buf = new bool[][](2 * h, 2 * w);
    auto vg = gcd(pv.x, pv.y);

    foreach (t; 1..min(d, 2 * hw) + 1) {
      if (pv.x == 0 || pv.y == 0 || pv.x == pv.y) {
        foreach (u; 0..max(pv.x, pv.y)) {
          auto x = (ph.x + pv.x * t + u * (pv.x == 0 ? 0 : 1)) % (2 * w);
          auto y = (ph.y + pv.y * t + u * (pv.y == 0 ? 0 : 1)) % (2 * h);
          buf[y][x] = true;
        }
      } else {
        foreach (u; 1..vg + 1) {
          auto x = (ph.x + pv.x * t + pv.x / vg * u) % (2 * w);
          auto y = (ph.y + pv.y * t + pv.y / vg * u) % (2 * h);
          buf[y][x] = true;
        }
      }
    }

    auto rx = 2 * w - pm.x;
    auto ry = 2 * h - pm.y;
    auto r = buf[pm.y][pm.x] || buf[ry][pm.x] || buf[pm.y][rx] || buf[ry][rx];

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