結果

問題 No.60 魔法少女
コンテスト
ユーザー hogeover30
提出日時 2015-03-05 20:07:14
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 84 ms / 5,000 ms
コード長 1,161 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,420 ms
コンパイル使用メモリ 175,208 KB
実行使用メモリ 9,144 KB
最終ジャッジ日時 2026-03-08 16:01:52
合計ジャッジ時間 2,865 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |             int x, y, hp; scanf("%d%d%d", &x, &y, &hp);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
main.cpp:21:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |             int x, y, w, h, d; scanf("%d%d%d%d%d", &x, &y, &w, &h, &d);
      |                                ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxx=1001, maxy=1001;
int b[maxx+2][maxy+2];

int main()
{
    int n, k;
    while (~scanf("%d%d", &n, &k)) {
        memset(b, 0, sizeof(b));
        vector<tuple<int, int, int>> v;
        while (n--) {
            int x, y, hp; scanf("%d%d%d", &x, &y, &hp);
            x+=500, y+=500;
            v.emplace_back(x, y, hp);
        }
        while (k--) {
            int x, y, w, h, d; scanf("%d%d%d%d%d", &x, &y, &w, &h, &d);
            x+=500, y+=500;
#define min(a, b) (a<b?a:b)
            int xx=min(x+w+1, maxx), yy=min(y+h+1, maxy);
            b[x][y]-=d;
            b[x][yy]+=d;
            b[xx][y]+=d;
            b[xx][yy]-=d;
        }

        for(int x=0;x<maxx;++x)
            for(int y=1;y<maxy;++y)
                b[x][y]+=b[x][y-1];
        for(int x=1;x<maxx;++x)
            for(int y=0;y<maxy;++y)
                b[x][y]+=b[x-1][y];

        int res=0;
        for(auto& p: v) {
            int x, y, hp;
            tie(x, y, hp)=p;
            if (hp+b[x][y]>0)
            res+=hp+b[x][y];
        }
        printf("%d\n", res);
    }
}
0