結果

問題 No.60 魔法少女
ユーザー MisterMister
提出日時 2020-08-22 08:28:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 5,000 ms
コード長 1,252 bytes
コンパイル時間 604 ms
コンパイル使用メモリ 79,136 KB
実行使用メモリ 66,048 KB
最終ジャッジ日時 2024-04-23 06:58:46
合計ジャッジ時間 2,707 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
66,048 KB
testcase_01 AC 56 ms
66,048 KB
testcase_02 AC 57 ms
66,048 KB
testcase_03 AC 56 ms
65,920 KB
testcase_04 AC 98 ms
65,920 KB
testcase_05 AC 102 ms
66,048 KB
testcase_06 AC 132 ms
65,920 KB
testcase_07 AC 113 ms
65,920 KB
testcase_08 AC 92 ms
65,920 KB
testcase_09 AC 72 ms
66,048 KB
testcase_10 AC 126 ms
66,048 KB
testcase_11 AC 64 ms
66,048 KB
testcase_12 AC 87 ms
65,920 KB
testcase_13 AC 136 ms
66,048 KB
権限があれば一括ダウンロードができます

ソースコード

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