結果

問題 No.60 魔法少女
ユーザー masamasa
提出日時 2016-07-29 16:21:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 5,000 ms
コード長 1,599 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 75,828 KB
実行使用メモリ 22,400 KB
最終ジャッジ日時 2024-04-24 10:45:51
合計ジャッジ時間 2,854 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
21,120 KB
testcase_01 AC 17 ms
21,120 KB
testcase_02 AC 17 ms
21,120 KB
testcase_03 AC 17 ms
21,120 KB
testcase_04 AC 62 ms
21,120 KB
testcase_05 AC 61 ms
22,272 KB
testcase_06 AC 94 ms
22,144 KB
testcase_07 AC 74 ms
21,760 KB
testcase_08 AC 53 ms
21,632 KB
testcase_09 AC 32 ms
21,248 KB
testcase_10 AC 91 ms
22,400 KB
testcase_11 AC 23 ms
21,376 KB
testcase_12 AC 47 ms
21,888 KB
testcase_13 AC 98 ms
22,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

const int XY_SHIFT = 500;

void show(vector<vector<int>> &vv) {
	int r = 5;
	for (int i = -r; i <= r; i++) {
		int y = i + XY_SHIFT;
		printf("%4d: ", i);
		for (int j = -r; j <= r; j++) {
			int x = j + XY_SHIFT;
			printf("%3d ", vv[y][x]);
		}
		printf("\n");
	}
}

int main() {
	int n, k;

	scanf("%d %d", &n, &k);
	vector<int> x(n), y(n), hp(n);
	for (int i = 0; i < n; i++) {
		scanf("%d %d %d", &x[i], &y[i], &hp[i]);
		x[i] += XY_SHIFT;
		y[i] += XY_SHIFT;
		// printf("i,x,y,hp: %2d %4d %4d %4d\n", i, x[i], y[i], hp[i]);
	}

	vector<vector<int>> attacks(1502, vector<int>(1502, 0));
	vector<vector<int>> damages(1503, vector<int>(1503, 0));
	int ax, ay, w, h, d;
	for (int i = 0; i < k; i++) {
		scanf("%d %d %d %d %d", &ax, &ay, &w, &h, &d);
		ax += XY_SHIFT;
		ay += XY_SHIFT;
		w++;
		h++;
		// printf("i,ax,ay,ax+w,ay+h: %2d %4d %4d %4d %4d\n", i, ax, ay, ax+w, ay+h);
		attacks[ay][ax] += d;
		attacks[ay][ax + w] += -d;
		attacks[ay + h][ax] += -d;
		attacks[ay + h][ax + w] += d;
	}

	for (int i = 0; i < 1002; i++) {
		for (int j = 0; j < 1002; j++) {
			damages[i+1][j+1] = damages[i][j+1] + damages[i+1][j] - damages[i][j] + attacks[i][j];
		}
	}

	// cout << "attacks ------------" << endl;
	// show(attacks);
	// cout << "damages ------------" << endl;
	// show(damages);

	int ans = 0;
	for (int i = 0; i < n; i++) {
		int rest = hp[i] - damages[y[i]+1][x[i]+1];
		if (rest > 0) {
			ans += rest;
		}
	}
	printf("%d\n", ans);
	return 0;
}
0