結果

問題 No.60 魔法少女
ユーザー legosukelegosuke
提出日時 2021-05-04 01:32:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 288 ms / 5,000 ms
コード長 1,855 bytes
コンパイル時間 2,033 ms
コンパイル使用メモリ 203,480 KB
実行使用メモリ 34,900 KB
最終ジャッジ日時 2023-09-29 21:34:09
合計ジャッジ時間 6,695 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
34,612 KB
testcase_01 AC 96 ms
34,780 KB
testcase_02 AC 97 ms
34,664 KB
testcase_03 AC 98 ms
34,680 KB
testcase_04 AC 200 ms
34,760 KB
testcase_05 AC 206 ms
34,608 KB
testcase_06 AC 280 ms
34,556 KB
testcase_07 AC 232 ms
34,756 KB
testcase_08 AC 182 ms
34,732 KB
testcase_09 AC 134 ms
34,728 KB
testcase_10 AC 270 ms
34,676 KB
testcase_11 AC 116 ms
34,668 KB
testcase_12 AC 175 ms
34,680 KB
testcase_13 AC 288 ms
34,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

/**
 * @brief いもす法 (2D)
 */
template <typename T>
class imos_2d {
public:
    /**
     * @note field is [0, N) × [0, M)
     */
    imos_2d(std::uint32_t N, std::uint32_t M) : N(N), M(M), data(N + 1, std::vector<T>(M + 1, 0)) {}

    void build() {
        for (std::uint32_t i = 0; i < N; ++i) {
            for (std::uint32_t j = 0; j < M; ++j) {
                data[i][j + 1] += data[i][j];
            }
        }
        for (std::uint32_t j = 0; j < M; ++j) {
            for (std::uint32_t i = 0; i < N; ++i) {
                data[i + 1][j] += data[i][j];
            }
        }
    }

    const std::vector<T>& operator [] (std::uint32_t i) const {
        return (data.at(i));
    }
    std::vector<T>& operator [] (std::uint32_t i) {
        return (data.at(i));
    }

    /**
     * @note add val to [y1, y2) × [x1, x2)
     */
    void add(std::uint32_t y1, std::uint32_t x1, std::uint32_t y2, std::uint32_t x2, const T& val) {
        data[y1][x1] += val;
        data[y1][x2] -= val;
        data[y2][x1] -= val;
        data[y2][x2] += val;
    }

private:
    const std::uint32_t N, M;
    std::vector<std::vector<T>> data;
};

signed main() {
    int N, K;
    cin >> N >> K;
    auto hp = imos_2d<int>(2010, 2010);
    for (int i = 0; i < N; ++i) {
        int X, Y, HP;
        cin >> X >> Y >> HP;
        X += 500; Y += 500;
        hp.add(Y, X, Y + 1, X + 1, HP);
    }
    for (int i = 0; i < K; ++i) {
        int AX, AY, W, H, D;
        cin >> AX >> AY >> W >> H >> D;
        AX += 500; AY += 500;
        hp.add(AY, AX, AY + H + 1, AX + W + 1, -D);
    }
    hp.build();
    int ans = 0;
    for (int i = 0; i < 2010; ++i) {
        for (int j = 0; j < 2010; ++j) {
            ans += max(0L, hp[i][j]);
        }
    }
    cout << ans << endl;
}
0