結果

問題 No.60 魔法少女
ユーザー PachicobuePachicobue
提出日時 2017-07-14 20:15:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 352 ms / 5,000 ms
コード長 2,046 bytes
コンパイル時間 2,957 ms
コンパイル使用メモリ 166,048 KB
実行使用メモリ 21,248 KB
最終ジャッジ日時 2024-04-16 19:52:27
合計ジャッジ時間 5,279 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
11,392 KB
testcase_01 AC 10 ms
11,392 KB
testcase_02 AC 10 ms
11,392 KB
testcase_03 AC 13 ms
18,048 KB
testcase_04 AC 228 ms
19,312 KB
testcase_05 AC 176 ms
21,120 KB
testcase_06 AC 351 ms
21,120 KB
testcase_07 AC 257 ms
20,480 KB
testcase_08 AC 158 ms
20,224 KB
testcase_09 AC 78 ms
19,328 KB
testcase_10 AC 326 ms
21,248 KB
testcase_11 AC 32 ms
19,456 KB
testcase_12 AC 124 ms
20,608 KB
testcase_13 AC 352 ms
21,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

constexpr ll HALF = 500;
constexpr ll MAX = HALF * 2;
ll imos[MAX + 1][MAX + 1];
ll sum[MAX + 1][MAX + 1];


struct Enemy {
    Enemy() = default;
    Enemy(ll hp, ll x, ll y) : hp(hp), x(x), y(y) {}
    ll hp;
    ll x;
    ll y;
};

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<Enemy> enemy(N);
    for (ll i = 0; i < N; i++) {
        ll x, y, hp;
        cin >> x >> y >> hp;
        enemy[i] = Enemy{hp, x + HALF, y + HALF};
    }
    for (ll i = 0; i < K; i++) {
        ll ax, ay, w, h, d;
        cin >> ax >> ay >> w >> h >> d;
        const ll starty = ay + HALF;
        const ll endy = min(ay + h + HALF, MAX);
        const ll startx = ax + HALF;
        const ll endx = min(ax + w + HALF, MAX);
        for (ll y = starty; y <= endy; y++) {
            imos[y][startx] += d;
            if (endx < MAX) {
                imos[y][endx + 1] -= d;
            }
        }
    }

    for (ll y = 0; y <= MAX; y++) {
        sum[y][0] = imos[y][0];
    }
    for (ll y = 0; y <= MAX; y++) {
        for (ll x = 1; x <= MAX; x++) {
            sum[y][x] = sum[y][x - 1] + imos[y][x];
        }
    }
    ll res = 0;
    for (ll i = 0; i < N; i++) {
        const ll hp = enemy[i].hp;
        const ll y = enemy[i].y;
        const ll x = enemy[i].x;
        if (sum[y][x] < hp) {
            res += (hp - sum[y][x]);
        }
    }
    cout << res << endl;

    return 0;
}
0