結果

問題 No.60 魔法少女
ユーザー Mister
提出日時 2020-08-22 08:28:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 187 ms / 5,000 ms
コード長 1,252 bytes
コンパイル時間 899 ms
コンパイル使用メモリ 75,496 KB
最終ジャッジ日時 2025-01-13 06:51:16
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

constexpr int X = 500;
constexpr int W = X * 4 + 1;

using lint = long long;

void solve() {
    int n, m;
    std::cin >> n >> m;

    auto xss = vec(W, vec(W, 0LL));
    while (n--) {
        int x, y;
        std::cin >> x >> y;
        std::cin >> xss[x + X][y + X];
    }

    auto yss = vec(W, vec(W, 0LL));
    while (m--) {
        int x, y, h, w, d;
        std::cin >> x >> y >> h >> w >> d;
        x += X, y += X, ++h, ++w;

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

    for (int x = 0; x < W; ++x) {
        for (int y = 1; y < W; ++y) {
            yss[x][y] += yss[x][y - 1];
        }
    }

    for (int x = 1; x < W; ++x) {
        for (int y = 0; y < W; ++y) {
            yss[x][y] += yss[x - 1][y];
        }
    }

    lint ans = 0;
    for (int x = 0; x < W; ++x) {
        for (int y = 0; y < W; ++y) {
            ans += std::max(0LL, xss[x][y] - yss[x][y]);
        }
    }
    std::cout << ans << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0