結果

問題 No.60 魔法少女
ユーザー te-shte-sh
提出日時 2017-01-20 15:55:45
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 182 ms / 5,000 ms
コード長 1,098 bytes
コンパイル時間 628 ms
コンパイル使用メモリ 90,092 KB
実行使用メモリ 14,448 KB
最終ジャッジ日時 2023-09-03 00:46:47
合計ジャッジ時間 2,860 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
11,308 KB
testcase_01 AC 13 ms
11,316 KB
testcase_02 AC 14 ms
10,592 KB
testcase_03 AC 14 ms
11,304 KB
testcase_04 AC 101 ms
12,172 KB
testcase_05 AC 113 ms
13,176 KB
testcase_06 AC 173 ms
14,448 KB
testcase_07 AC 132 ms
12,904 KB
testcase_08 AC 90 ms
13,160 KB
testcase_09 AC 46 ms
13,388 KB
testcase_10 AC 166 ms
13,220 KB
testcase_11 AC 31 ms
12,432 KB
testcase_12 AC 83 ms
13,636 KB
testcase_13 AC 182 ms
13,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

const auto ofs = 500, maxX = 500 + ofs + 1, maxY = 500 + ofs + 1;

void main()
{
  auto rd1 = readln.split.to!(size_t[]), n = rd1[0], k = rd1[1];
  Monster[] mi = n.iota.map!((_) {
    auto rd2 = readln.split;
    return Monster(rd2[0].to!int + ofs, rd2[1].to!int + ofs, rd2[2].to!long);
  }).array;

  auto fij = new long[][](maxY, maxX);
  foreach (_; k.iota) {
    auto rd3 = readln.split;
    auto x = rd3[0].to!int + ofs, y = rd3[1].to!int + ofs;
    auto w = rd3[2].to!int, h = rd3[3].to!int, d = rd3[4].to!long;

    auto x2 = x + w + 1, y2 = y + h + 1;

    fij[y][x] += d;
    if (x2 < maxX) fij[y][x2] -= d;
    if (y2 < maxY) fij[y2][x] -= d;
    if (x2 < maxX && y2 < maxY) fij[y2][x2] += d;
  }

  foreach (x; 1..maxX)
    foreach (y; 0..maxY)
      fij[y][x] += fij[y][x - 1];
  foreach (y; 1..maxY)
    foreach (x; 0..maxX)
      fij[y][x] += fij[y - 1][x];

  auto r = 0L;
  foreach (m; mi) {
    auto h = m.hp - fij[m.y][m.x];
    if (h > 0) r += h;
  }

  writeln(r);
}

struct Monster {
  int x, y;
  long hp;
}
0