結果

問題 No.1490 スライムと爆弾
ユーザー m_tsubasam_tsubasa
提出日時 2021-04-23 22:40:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 1,476 bytes
コンパイル時間 2,828 ms
コンパイル使用メモリ 207,496 KB
実行使用メモリ 38,584 KB
最終ジャッジ日時 2023-09-17 12:43:43
合計ジャッジ時間 6,787 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 123 ms
18,412 KB
testcase_14 AC 148 ms
24,288 KB
testcase_15 AC 79 ms
19,188 KB
testcase_16 AC 110 ms
14,216 KB
testcase_17 AC 67 ms
22,024 KB
testcase_18 AC 154 ms
24,220 KB
testcase_19 AC 132 ms
22,168 KB
testcase_20 AC 96 ms
18,208 KB
testcase_21 AC 59 ms
16,956 KB
testcase_22 AC 129 ms
16,168 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 180 ms
38,584 KB
testcase_26 AC 182 ms
38,388 KB
testcase_27 AC 183 ms
38,280 KB
testcase_28 AC 135 ms
34,396 KB
testcase_29 AC 139 ms
34,524 KB
testcase_30 AC 278 ms
38,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct slime {
  long long t, u, l, r, a;
  slime(long long _t = 0, long long _u = 0, long long _l = 0, long long _r = 0,
        long long _a = 0)
      : t(_t), u(_u), l(_l), r(_r), a(_a) {}
};

long long h, w, n, m;
vector<slime> v;
vector<vector<long long>> sum;

int solve();

int main() {
  cin >> h >> w >> n >> m;
  v.resize(n);
  for (auto &[t, u, l, r, a] : v)
    cin >> t >> u >> l >> r >> a, --t, --l, --u, --r;
  sum.assign(h + 1, vector<long long>(w + 1, 0));
  for (int i = 0; i < m; ++i) {
    long long x, y, b, c, t, u, l, r;
    cin >> x >> y >> b >> c, --x, --y;
    t = max(0LL, x - b), u = min(h, x + b + 1);
    l = max(0LL, y - b), r = min(w, y + b + 1);
    sum[t][l] += c, sum[t][r] -= c, sum[u][l] -= c, sum[u][r] += c;
  }
  cout << solve() << endl;
  return 0;
}

int solve() {
  int res = 0;
  for (int i = 0; i <= h; ++i)
    for (int j = 1; j <= w; ++j) sum[i][j] += sum[i][j - 1];
  for (int i = 1; i <= h; ++i)
    for (int j = 0; j <= w; ++j) sum[i][j] += sum[i - 1][j];
  for (int i = 0; i <= h; ++i)
    for (int j = 0; j <= w; ++j) {
      if (j) sum[i][j] += sum[i][j - 1];
      if (i) sum[i][j] += sum[i - 1][j];
      if (i && j) sum[i][j] -= sum[i - 1][j - 1];
    }

  for (auto [t, u, l, r, a] : v) {
    long long now = sum[u][r];
    if (t) now -= sum[t - 1][r];
    if (l) now -= sum[u][l - 1];
    if (t && l) now += sum[t - 1][l - 1];
    if (now < a) ++res;
  }
  return res;
}
0