結果

問題 No.60 魔法少女
コンテスト
ユーザー te-sh
提出日時 2017-01-20 15:13:20
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 1,019 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 103,984 KB
実行使用メモリ 32,316 KB
最終ジャッジ日時 2024-06-12 06:31:13
合計ジャッジ時間 2,811 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 1 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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;

    fij[y][x] += d;
    fij[y][x + w + 1] -= d;
    fij[y + h + 1][x] -= d;
    fij[y + h + 1][x + w + 1] += d;
  }

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

  auto r = 0;
  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