結果

問題 No.60 魔法少女
ユーザー PachicobuePachicobue
提出日時 2017-07-16 23:41:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 211 ms / 5,000 ms
コード長 2,812 bytes
コンパイル時間 1,562 ms
コンパイル使用メモリ 167,072 KB
実行使用メモリ 21,340 KB
最終ジャッジ日時 2024-04-16 22:40:12
合計ジャッジ時間 3,847 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
11,304 KB
testcase_01 AC 9 ms
11,392 KB
testcase_02 AC 7 ms
11,264 KB
testcase_03 AC 9 ms
11,520 KB
testcase_04 AC 116 ms
19,436 KB
testcase_05 AC 129 ms
21,120 KB
testcase_06 AC 207 ms
21,004 KB
testcase_07 AC 149 ms
20,480 KB
testcase_08 AC 105 ms
20,224 KB
testcase_09 AC 53 ms
19,328 KB
testcase_10 AC 191 ms
21,120 KB
testcase_11 AC 28 ms
13,692 KB
testcase_12 AC 90 ms
20,584 KB
testcase_13 AC 211 ms
21,340 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);
        //// 1次元imos
        // for (ll y = starty; y <= endy; y++) {
        //     imos[y][startx] += d;
        //     if (endx < MAX) {
        //         imos[y][endx + 1] -= d;
        //     }
        // }

        // 2次元imos
        imos[starty][startx] += d;
        if (endx < MAX) {
            imos[starty][endx + 1] -= d;
        }
        if (endy < MAX) {
            imos[endy + 1][startx] -= d;
            if (endx < MAX) {
                imos[endy + 1][endx + 1] += d;
            }
        }
    }

    //// i次元imos
    // 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];
    //     }
    // }

    // 二次元imos
    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];
        }
    }
    for (ll x = 0; x <= MAX; x++) {
        for (ll y = 1; y <= MAX; y++) {
            sum[y][x] += sum[y - 1][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