結果

問題 No.60 魔法少女
ユーザー assy1028assy1028
提出日時 2015-03-25 23:36:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 96 ms / 5,000 ms
コード長 1,615 bytes
コンパイル時間 1,145 ms
コンパイル使用メモリ 144,528 KB
実行使用メモリ 25,148 KB
最終ジャッジ日時 2023-09-11 10:16:38
合計ジャッジ時間 3,191 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
23,436 KB
testcase_01 AC 16 ms
23,532 KB
testcase_02 AC 16 ms
23,440 KB
testcase_03 AC 16 ms
23,652 KB
testcase_04 AC 60 ms
23,856 KB
testcase_05 AC 60 ms
24,984 KB
testcase_06 AC 94 ms
25,108 KB
testcase_07 AC 73 ms
24,600 KB
testcase_08 AC 51 ms
24,384 KB
testcase_09 AC 31 ms
23,864 KB
testcase_10 AC 89 ms
24,984 KB
testcase_11 AC 22 ms
23,888 KB
testcase_12 AC 46 ms
24,580 KB
testcase_13 AC 96 ms
25,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef pair<int, int> P;
typedef unsigned int uint;
typedef unsigned long long ull;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};

const int inf = 1000000009;
const double eps = 1e-8;
ll board[1600][1600];

ll solve(int n, int k) {
    int buf = 500, s = 1600;

    int x[n], y[n];
    ll hp[n];
    for (int i = 0; i < n; i++) {
	int _x, _y;
	scanf("%d%d%lld", &_x, &_y, &hp[i]);
	x[i] = _x + buf;
	y[i] = _y + buf;
    }

    for (int i = 0; i < k; i++) {
	int ax, ay, w, h;
	ll d;
	scanf("%d%d%d%d%lld", &ax, &ay, &w, &h, &d);
	ax += buf;
	ay += buf;
	board[ay][ax] += d;
	board[ay+h+1][ax] -= d;
	board[ay][ax+w+1] -= d;
	board[ay+h+1][ax+w+1] += d;
    }

    for (int i = 0; i < s; i++) {
	for (int j = 1; j < s; j++) {
	    board[i][j] += board[i][j-1];
	}
    }

    for (int i = 1; i < s; i++) {
	for (int j = 0; j < s; j++) {
	    board[i][j] += board[i-1][j];
	}
    }

    ll res = 0;
    for (int i = 0; i < n; i++) {
	res += max(0LL, hp[i] - board[y[i]][x[i]]);
    }
    
    return res;
}

int main() {
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    */

    int n, k;
    scanf("%d%d", &n, &k);
    printf("%lld\n", solve(n, k));
}
0