結果

問題 No.60 魔法少女
ユーザー kurenai3110kurenai3110
提出日時 2017-04-10 15:59:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 190 ms / 5,000 ms
コード長 1,461 bytes
コンパイル時間 596 ms
コンパイル使用メモリ 69,012 KB
実行使用メモリ 7,408 KB
最終ジャッジ日時 2023-09-25 06:47:33
合計ジャッジ時間 3,555 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
7,340 KB
testcase_01 AC 11 ms
7,296 KB
testcase_02 AC 11 ms
7,300 KB
testcase_03 AC 10 ms
7,356 KB
testcase_04 AC 105 ms
7,304 KB
testcase_05 AC 116 ms
7,288 KB
testcase_06 AC 187 ms
7,300 KB
testcase_07 AC 139 ms
7,408 KB
testcase_08 AC 92 ms
7,408 KB
testcase_09 AC 44 ms
7,352 KB
testcase_10 AC 174 ms
7,352 KB
testcase_11 AC 28 ms
7,368 KB
testcase_12 AC 84 ms
7,288 KB
testcase_13 AC 190 ms
7,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define SIZE 1001
#define offset 500

//2次元Imos法
class Imos2 {
public:
	vector<vector<int>>table;
	int n, m;

	Imos2(int n_, int m_) {
		n = n_ + 1;
		m = m_ + 1;
		table.resize(n);
		for (int i = 0; i < n; i++)table[i].resize(m);
	}

	void input(pair<int, int>tl, pair<int, int>br, int v) {
		table[tl.first][tl.second] += v;
		table[tl.first][br.second] -= v;
		table[br.first][tl.second] -= v;
		table[br.first][br.second] += v;
	}

	void accumulate() {
		for (int i = 0; i < n; i++) {
			for (int j = 1; j < m; j++) {
				table[i][j] += table[i][j - 1];
			}
		}

		for (int j = 0; j < m; j++) {
			for (int i = 1; i < n; i++) {
				table[i][j] += table[i - 1][j];
			}
		}
	}
};

int solve() {
	Imos2 imos2(SIZE, SIZE);

	int N, K; cin >> N >> K;
	for (int i = 0; i < N; i++) {
		int x, y, hp;
		cin >> x >> y >> hp;
		x += offset; y += offset;
		imos2.input(make_pair(x, y), make_pair(x + 1, y + 1), hp);
	}
	for (int i = 0; i < K; i++) {
		int x, y, w, h, d;
		cin >> x >> y >> w >> h >> d;
		x += offset; y += offset;
		imos2.input(make_pair(x, y), make_pair(min(SIZE,x + w + 1), min(SIZE,y + h + 1)), -d);
	}

	imos2.accumulate();

	int ans = 0;
	for (int i = 0; i < SIZE; i++) {
		for (int j = 0; j < SIZE; j++) {
			if (imos2.table[i][j] > 0)ans += imos2.table[i][j];
		}
	}

	return ans;
}

int main()
{
	cout<< solve() <<endl;
    return 0;
}

0