結果

問題 No.60 魔法少女
ユーザー codershifthcodershifth
提出日時 2015-07-29 10:24:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 92 ms / 5,000 ms
コード長 2,631 bytes
コンパイル時間 3,545 ms
コンパイル使用メモリ 157,736 KB
実行使用メモリ 12,240 KB
最終ジャッジ日時 2023-09-24 21:30:33
合計ジャッジ時間 3,905 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
11,224 KB
testcase_01 AC 11 ms
11,068 KB
testcase_02 AC 10 ms
11,208 KB
testcase_03 AC 10 ms
10,892 KB
testcase_04 AC 54 ms
11,220 KB
testcase_05 AC 55 ms
11,956 KB
testcase_06 AC 88 ms
11,976 KB
testcase_07 AC 67 ms
11,812 KB
testcase_08 AC 46 ms
11,568 KB
testcase_09 AC 26 ms
11,096 KB
testcase_10 AC 83 ms
12,116 KB
testcase_11 AC 17 ms
11,388 KB
testcase_12 AC 43 ms
11,684 KB
testcase_13 AC 92 ms
12,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;


class MagicGirl {
public:
    void solve(void) {
            int N,K;
            cin>>N>>K;
            // いもす法
            // 要は遅延評価。最後に全平面をスキャンするときに
            // 評価されるように区間情報を更新しておく

            int offset = 2; // 境界処理用
            int W,H,ox,oy;
            // monster の存在範囲をフィールドサイズとかんがえてよい
            W = H = 1000 + offset;
            ox = W/2;
            oy = H/2;
            vector<tuple<int,int,int>> monster;
            REP(i, N)
            {
                int x,y,hp;
                cin>>x>>y>>hp;
                // 座標を (0,0)-(W-1,H-1) 以内に変換
                x += ox;
                y += oy;
                monster.emplace_back(x,y,hp);
            }
            // いもす法。ダメージ計算の参照点を更新しておく
            // 参照点は範囲の左下と右上+(1,1)
            // メモリは左上分 +1 ひろげて確保しておく
            vector<vector<int>> damage(H+1, vector<int>(W+1, 0));
            REP(i,K)
            {
                int x,y,w,h,d;
                cin>>x>>y>>w>>h>>d;
                x += ox;
                y += oy;
                //   -5      5                0
                // ...*.....*       ..05555555
                //    ://///:         05555555
                //    ://///:    =>   05555555
                // ...5.....*-5     ..05555555
                //    :     :         00000000
                //
                damage[min(y+h+1,H)][min(x+w+1,W)] += d;
                damage[min(y+h+1,H)][x] -= d;
                damage[y][min(x+w+1,W)] -= d;
                damage[y][x] += d;
            }
            vector<vector<int>> sum(H+1, vector<int>(W+1, 0));
            // O(W*H)
            FOR(y,1,H+1)
            FOR(x,1,W+1)
                 sum[y][x] += sum[y][x-1] + sum[y-1][x] - sum[y-1][x-1] + damage[y][x];
            int ans = 0;
            for (auto m : monster)
             {
                int x,y,hp;
                tie(x,y,hp) = m;
                ans += max(0,hp - sum[y][x]);
            }
            cout<<ans<<endl;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new MagicGirl();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0