結果

問題 No.60 魔法少女
ユーザー kyunakyuna
提出日時 2019-08-31 14:41:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 186 ms / 5,000 ms
コード長 1,471 bytes
コンパイル時間 957 ms
コンパイル使用メモリ 75,920 KB
実行使用メモリ 8,312 KB
最終ジャッジ日時 2023-08-16 06:21:11
合計ジャッジ時間 4,323 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,296 KB
testcase_01 AC 6 ms
7,332 KB
testcase_02 AC 5 ms
7,448 KB
testcase_03 AC 6 ms
7,340 KB
testcase_04 AC 98 ms
7,516 KB
testcase_05 AC 104 ms
8,044 KB
testcase_06 AC 171 ms
8,312 KB
testcase_07 AC 125 ms
7,852 KB
testcase_08 AC 82 ms
7,508 KB
testcase_09 AC 38 ms
7,564 KB
testcase_10 AC 162 ms
8,004 KB
testcase_11 AC 22 ms
7,672 KB
testcase_12 AC 74 ms
7,844 KB
testcase_13 AC 186 ms
8,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

template<typename T>
struct Imos2D {
    vector<vector<T>> imos;
    Imos2D(int h = 0, int w = 0) : imos(h + 2, vector<T>(w + 2)) { }
    void add(int i, int j, T x) { imos[i + 1][j + 1] += x; }
    void add_rect(int i1, int j1, int i2, int j2, T x = 1) {
        add(i1, j1, +x); add(i1, j2, -x); add(i2, j1, -x); add(i2, j2, +x);
    }
    void build() {
        int H = imos.size(), W = imos[0].size();
        for (int i = 1; i < H; i++) for (int j = 1; j < W; j++) {
            imos[i][j] += imos[i][j - 1] + imos[i - 1][j] - imos[i - 1][j - 1];
        }
    }
    T get(int i, int j) { return imos[i + 1][j + 1]; }
    T diff(int si, int sj, int ti, int tj) {        // [si, ti) x [sj, tj)
        return imos[ti][tj] - imos[ti][sj] - imos[si][tj] + imos[si][sj];
    }
};

int main() {
    const int OFS = 500;
    Imos2D<int> imos(1001, 1001);
    int n, k; cin >> n >> k;
    vector<int> x(n), y(n), hp(n);
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> hp[i];
    while (k--) {
        int i, j, w, h, d; cin >> i >> j >> w >> h >> d;
        i += OFS, j += OFS;
        int i2 = min(1000, i + w);
        int j2 = min(1000, j + h);
        imos.add_rect(i, j, i2 + 1, j2 + 1, d);
    }
    imos.build();
    int rest = 0;
    for (int i = 0; i < n; i++) {
        rest += max(0, hp[i] - imos.get(x[i] + OFS, y[i] + OFS));
    }
    cout << rest << endl;
    return 0;
}
0