結果

問題 No.60 魔法少女
ユーザー けーむけーむ
提出日時 2020-08-13 15:05:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 5,000 ms
コード長 2,085 bytes
コンパイル時間 1,784 ms
コンパイル使用メモリ 168,488 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-18 01:31:37
合計ジャッジ時間 2,731 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
11,136 KB
testcase_01 AC 9 ms
11,008 KB
testcase_02 AC 9 ms
11,136 KB
testcase_03 AC 10 ms
11,264 KB
testcase_04 AC 43 ms
11,008 KB
testcase_05 AC 50 ms
11,264 KB
testcase_06 AC 78 ms
11,136 KB
testcase_07 AC 54 ms
11,008 KB
testcase_08 AC 38 ms
11,136 KB
testcase_09 AC 21 ms
11,008 KB
testcase_10 AC 67 ms
11,136 KB
testcase_11 AC 15 ms
11,136 KB
testcase_12 AC 36 ms
11,008 KB
testcase_13 AC 78 ms
11,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

template<typename T>
struct Imos2D {
private:
    int w, h;
    vector<vector<T>> dp;
    
public:
    Imos2D(int _w, int _h) : w(_w), h(_h), dp(_w, vector<T>(_h, 0)) {}
    
    void add(int ax, int ay, int bx, int by, T val) {
        if (ax > bx) swap(ax, bx);
        if (ay > by) swap(ay, by);
        dp[ax][ay] += val;
        if (by < h) dp[ax][by] -= val;
        if (bx < w) dp[bx][ay] -= val;
        if ((by < h) && (bx < w)) dp[bx][by] += val;
    }
    
    void build() {
        for(int x = 0; x < w; x++) {
            for(int y = 0; y < (h - 1); y++) {
                dp[x][y + 1] += dp[x][y];
            }
        }
        for(int y = 0; y < h; y++) {
            for(int x = 0; x < (w - 1); x++) {
                dp[x + 1][y] += dp[x][y];
            }
        }
    }
    
    T query(int x, int y) {
        return dp[x][y];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    Imos2D<ll> imos(1001, 1001);
    rep(i, n) {
        ll x, y, hp;
        cin >> x >> y >> hp;
        x += 500; y += 500;
        imos.add(x, y, x + 1, y + 1, hp);
    }
    rep(i, k) {
        ll ax, ay, w, h, d;
        cin >> ax >> ay >> w >> h >> d;
        ax += 500; ay += 500;
        imos.add(ax, ay, ax + w + 1, ay + h + 1, -d);
    }
    imos.build();
    ll ans = 0;
    rep(i, 1001) {
        rep(j, 1001) {
            ll val = imos.query(i, j);
            if (val > 0) {
                ans += val;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0