結果

問題 No.165 四角で囲え!
ユーザー 古寺いろは古寺いろは
提出日時 2015-03-23 16:53:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 182 ms / 5,000 ms
コード長 1,199 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 79,692 KB
実行使用メモリ 4,964 KB
最終ジャッジ日時 2023-08-26 23:40:05
合計ジャッジ時間 3,938 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
4,780 KB
testcase_01 AC 3 ms
4,608 KB
testcase_02 AC 2 ms
4,808 KB
testcase_03 AC 2 ms
4,924 KB
testcase_04 AC 2 ms
4,608 KB
testcase_05 AC 120 ms
4,660 KB
testcase_06 AC 25 ms
4,648 KB
testcase_07 AC 2 ms
4,608 KB
testcase_08 AC 2 ms
4,732 KB
testcase_09 AC 2 ms
4,672 KB
testcase_10 AC 2 ms
4,740 KB
testcase_11 AC 114 ms
4,644 KB
testcase_12 AC 166 ms
4,688 KB
testcase_13 AC 162 ms
4,716 KB
testcase_14 AC 160 ms
4,824 KB
testcase_15 AC 142 ms
4,836 KB
testcase_16 AC 182 ms
4,716 KB
testcase_17 AC 137 ms
4,948 KB
testcase_18 AC 178 ms
4,720 KB
testcase_19 AC 160 ms
4,860 KB
testcase_20 AC 137 ms
4,656 KB
testcase_21 AC 136 ms
4,964 KB
testcase_22 AC 138 ms
4,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

int main() {
	int N, B;
	cin >> N >> B;
	vector<int> x(N), y(N), p(N);
	for (int i = 0; i < N; i++)
	{
		cin >> x[i] >> y[i] >> p[i];
	}
	map<int, int> mx, my;

	vector<int> sx(x), sy(y);
	sort(sx.begin(), sx.end());
	sort(sy.begin(), sy.end());
	for (int i = 0; i < N; i++)
	{
		mx[sx[i]] = i;
		my[sy[i]] = i;
	}

	int dp[402][402] = {};
	int dp2[402][402] = {};
	for (int i = 0; i < N; i++)
	{
		x[i] = mx[x[i]] + 1;
		y[i] = my[y[i]] + 1;
		dp[y[i]][x[i]]++;
		dp2[y[i]][x[i]] += p[i];

	}

	for (int i = 1; i <= N + 1; i++)
	{
		for (int j = 1; j <= N + 1; j++)
		{
			dp[i][j] += dp[i - 1][j];
			dp[i][j] += dp[i][j - 1];
			dp[i][j] -= dp[i - 1][j - 1];

			dp2[i][j] += dp2[i - 1][j];
			dp2[i][j] += dp2[i][j - 1];
			dp2[i][j] -= dp2[i - 1][j - 1];

		}
	}

	

	int ans = 0;

	for (int i = 0; i <= N; i++)
	{
		for (int j = 0; j <= N; j++)
		{
			int X = N + 1;
			for (int Y = i; Y <= N + 1; Y++)
			{
				while (X >= 0 && dp2[Y][X] - dp2[Y][j] - dp2[i][X] + dp2[i][j] > B) X--;
				if (X >= 0) ans = max(ans, dp[Y][X] - dp[Y][j] - dp[i][X] + dp[i][j]);

			}
		}
	}

	cout << ans << endl;

}
0