結果
| 問題 | No.60 魔法少女 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2014-11-09 21:12:48 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 228 ms / 5,000 ms | 
| コード長 | 1,439 bytes | 
| コンパイル時間 | 728 ms | 
| コンパイル使用メモリ | 56,008 KB | 
| 実行使用メモリ | 20,556 KB | 
| 最終ジャッジ日時 | 2024-12-31 08:54:00 | 
| 合計ジャッジ時間 | 3,781 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 10 | 
ソースコード
#include <iostream>
using namespace std;
void rc(int v,int mn,int mx){if(v<mn||mx<v){cerr<<"error"<<endl;exit(1);}}
const int OFFSET = 500;
const int SIZE = 1555;
int h[SIZE][SIZE];
int d[SIZE][SIZE];
int main(){
    int N, K;
    cin >> N >> K;
    rc(N, 1, 100000);
    rc(K, 1, 100000);
    
    for(int i=0;i<N;i++){
        int X, Y, H;
        cin >> X >> Y >> H;
        rc(X, -500, 500);
        rc(Y, -500, 500);
        rc(H, 1, 10000);
        
        X += OFFSET;
        Y += OFFSET;
        
        h[Y][X] = H;
    }
    
    for(int i=0;i<K;i++){
        int AX, AY, W, H, D;
        cin >> AX >> AY >> W >> H >> D;
        
        rc(AX, -500, 500);
        rc(AY, -500, 500);
        rc(W, 1, 500);
        rc(H, 1, 500);
        rc(D, 1, 10000);
        AX += OFFSET;
        AY += OFFSET;
        
        d[AY][AX] += D;
        d[AY][AX+W+1] -= D;
        d[AY+H+1][AX] -= D;
        d[AY+H+1][AX+W+1] += D;
    }
    
    for(int Y=0;Y<SIZE;Y++){
        for(int X=1;X<SIZE;X++){
            d[Y][X] += d[Y][X-1];
        }
    }
    
    for(int X=0;X<SIZE;X++){
        for(int Y=1;Y<SIZE;Y++){
            d[Y][X] += d[Y-1][X];
        }
    }
    
    int res = 0;
    for(int Y=0;Y<SIZE;Y++)for(int X=0;X<SIZE;X++){
        int rest = h[Y][X] - d[Y][X];
        if(rest > 0)res += rest;
    }
    cout << res << endl;
    return 0;
}
            
            
            
        