結果

問題 No.165 四角で囲え!
ユーザー やまぞうやまぞう
提出日時 2015-03-15 03:56:57
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,481 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 81,840 KB
実行使用メモリ 12,028 KB
最終ジャッジ日時 2023-09-11 08:21:26
合計ジャッジ時間 13,408 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdint>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int N;
int B;
struct Point
{
	Point() {}
	Point(int x, int y, int p) : x(x), y(y), p(p) {}

	int x;
	int y;
	int p;
};
vector<Point> points;

void input(istream& in)
{
	in >> N >> B;
	points.resize(N);
	for (int i = 0; i < N; i++) {
		in >> points[i].x >> points[i].y >> points[i].p;
	}
}

int resolve()
{
	map<int, vector<Point*>> Xmap;
	map<int, vector<Point*>> Ymap;
	for (int i = 0; i < N; i++) {
		Xmap[points[i].x].push_back(&points[i]);
		Ymap[points[i].y].push_back(&points[i]);
	}
	vector<int> X;
	for (auto ite : Xmap) {
		X.push_back(ite.first);
	}
	vector<int> Y;
	for (auto ite : Ymap) {
		Y.push_back(ite.first);
	}

	int best_count = 0;
	for (size_t ix1 = 0; ix1 < X.size(); ix1++) {
		int x1 = X[ix1];
		for (size_t ix2 = ix1; ix2 < X.size(); ix2++) {
			int x2 = X[ix2];

			for (size_t iy1 = 0; iy1 < Y.size(); iy1++) {
				int y1 = Y[iy1];

				int count = 0;
				int score = 0;
				for (size_t iy2 = iy1; iy2 < Y.size(); iy2++) {
					int y2 = Y[iy2];

					for (auto ppoint : Ymap[y2]) {
						if (x1 <= ppoint->x && ppoint->x <= x2) {
							count++;
							score += ppoint->p;
						}
					}
					if (score > B) {
						break;
					}
					if (count > best_count) {
						best_count = count;
					}
				}
			}
		}
	}
	return best_count;
}

int main(int argc, char **argv)
{
	input(cin);
	cout << resolve() << endl;
	return 0;
}
0