結果

問題 No.60 魔法少女
ユーザー cormoran
提出日時 2016-09-29 21:44:07
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 1,469 bytes
コンパイル時間 1,318 ms
コンパイル使用メモリ 165,500 KB
実行使用メモリ 12,160 KB
最終ジャッジ日時 2024-11-21 10:40:07
合計ジャッジ時間 2,670 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)

template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }

class Solver {
  public:
    bool solve() {
        int N, K; cin >> N >> K;
        vector<vector<ll>> G(1001, vector<ll>(1001, 0));
        vector<int> X(N), Y(N), HP(N);
        rep(i, N) {
            cin >> X[i] >> Y[i] >> HP[i];
            X[i] += 500;
            Y[i] += 500;
            assert(0 <= X[i] and X[i] <= 1000);
            assert(0 <= Y[i] and Y[i] <= 1000);
        }

        rep(i, K) {
            int ax, ay, w, h, d; cin >> ax >> ay >> w >> h >> d;            
            ax += 500;
            ay += 500;
            G[ay][ax] += d;
            int ex = ax + w + 1;
            int ey = ay + h + 1;
            if(ex <= 1000) G[ay][ex] -= d;
            if(ey <= 1000) G[ey][ax] -= d;
            if(ex <= 1000 and ey <= 1000) G[ey][ex] += d;
        }

        rep(y, 1001) rep(x, 1001 -1) G[y][x + 1] += G[y][x];
        rep(x, 1001) rep(y, 1001 - 1) G[y + 1][x] += G[y][x];

        ll ans = 0;
        rep(i, N) {
            ans += max(0LL, HP[i] - G[Y[i]][X[i]]);
        }
        cout << ans << endl;
        
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0