結果

問題 No.60 魔法少女
ユーザー ooaiu
提出日時 2025-03-07 12:20:56
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 81 ms / 5,000 ms
コード長 939 bytes
コンパイル時間 3,501 ms
コンパイル使用メモリ 277,128 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2025-03-07 12:21:02
合計ジャッジ時間 6,167 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int M = 1550;
int imos[M][M];
int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int N, K;
	cin >> N >> K;
	const int off = 500;
	vector<array<int, 3>> P(N);
	for(auto&[x, y, hp] : P) {
		cin >> x >> y >> hp;
		x += off, y += off;
	}
	for(int i = 0; i < K; i++) {
		int x, y, w, h, d;
		cin >> x >> y >> w >> h >> d;
		x += off, y += off;
		// [x, x + w], [y, y + h]
		assert(0<=x&&x+w+1<M);
		assert(0<=y&&y+h+1<M);
		imos[x][y] += d;
		imos[x][y + h + 1] -= d;
		imos[x + w + 1][y] -= d;
		imos[x + w + 1][y + h + 1] += d;
	}
	for(int i = 0; i < M; i++) {
		for(int j = 1; j < M; j++) {
			imos[i][j] += imos[i][j - 1];
		}
	}
	for(int i = 1; i < M; i++) {
		for(int j = 0; j < M; j++) {
			imos[i][j] += imos[i - 1][j];
		}
	}
	ll ans = 0;
	for(const auto&[x, y, hp] : P) {
		ans += max(0, hp - imos[x][y]);
	}
	cout << ans << endl;
}
0