結果

問題 No.60 魔法少女
ユーザー bin101bin101
提出日時 2020-03-26 08:49:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 5,000 ms
コード長 1,672 bytes
コンパイル時間 1,780 ms
コンパイル使用メモリ 174,680 KB
実行使用メモリ 20,804 KB
最終ジャッジ日時 2023-08-30 12:08:58
合計ジャッジ時間 3,747 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
20,708 KB
testcase_01 AC 23 ms
20,672 KB
testcase_02 AC 23 ms
20,760 KB
testcase_03 AC 24 ms
20,656 KB
testcase_04 AC 69 ms
20,736 KB
testcase_05 AC 73 ms
20,800 KB
testcase_06 AC 106 ms
20,656 KB
testcase_07 AC 83 ms
20,672 KB
testcase_08 AC 62 ms
20,740 KB
testcase_09 AC 39 ms
20,696 KB
testcase_10 AC 101 ms
20,740 KB
testcase_11 AC 32 ms
20,804 KB
testcase_12 AC 58 ms
20,804 KB
testcase_13 AC 110 ms
20,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
2次元
参考:
https://imoz.jp/algorithms/imos_method.html
verify:
https://atcoder.jp/contests/abc036/tasks/abc036_c
*/
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;


template<class T>
struct IMOS{
    int H,W;
    bool flag;
    vector<vector<T>> table;

    IMOS(int H,int W):H(H),W(W),flag(false){
        table.resize(H+1,vector<T>(W+1,0));
    }
    inline void add(int sh,int sw,int gh,int gw,const T x){
        flag=false;
        table[sh][sw]+=x;
        table[sh][gw+1]-=x;
        table[gh+1][sw]-=x;
        table[gh+1][gw+1]+=x;
    }
    void build(){
        flag=true;
        for(int i=0;i<=H;i++){
            for(int j=0;j<=W;j++){
                if(i==0 && j==0) continue; 
                if(i==0) table[i][j]+=table[i][j-1];
                else if(j==0) table[i][j]+=table[i-1][j];
                else table[i][j]+=table[i][j-1]+table[i-1][j]-table[i-1][j-1];
            }
        }
    }
    inline T query(int h,int w){
        assert(flag);
        return table[h][w];
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); 
    cout<<fixed<<setprecision(20);
    int N,K;
    cin>>N>>K;
    IMOS<ll> imos(1501,1501);
    for(int i=0;i<N;i++){
        int x,y,hp;
        cin>>x>>y>>hp;
        x+=500;y+=500;
        imos.add(x,y,x,y,-hp);
    }
    for(int i=0;i<K;i++){
        int x,y,w,h;
        ll d;
        cin>>x>>y>>w>>h>>d;
        x+=500;y+=500;
        imos.add(x,y,x+w,y+h,d);
    }
    imos.build();
    ll ret=0;
    for(int i=0;i<=1500;i++){
        for(int j=0;j<=1500;j++){
            if(imos.query(i,j)<0) ret-=imos.query(i,j);
        }
    }
    cout<<ret<<endl;
}
0