結果

問題 No.165 四角で囲え!
ユーザー omuomu
提出日時 2015-03-18 13:22:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 398 ms / 5,000 ms
コード長 1,338 bytes
コンパイル時間 2,212 ms
コンパイル使用メモリ 77,740 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 23:39:27
合計ジャッジ時間 5,479 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 206 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 270 ms
4,380 KB
testcase_06 AC 43 ms
4,384 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 117 ms
4,376 KB
testcase_12 AC 55 ms
4,380 KB
testcase_13 AC 52 ms
4,380 KB
testcase_14 AC 72 ms
4,380 KB
testcase_15 AC 69 ms
4,376 KB
testcase_16 AC 380 ms
4,376 KB
testcase_17 AC 368 ms
4,380 KB
testcase_18 AC 357 ms
4,376 KB
testcase_19 AC 398 ms
4,376 KB
testcase_20 AC 382 ms
4,376 KB
testcase_21 AC 383 ms
4,376 KB
testcase_22 AC 380 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define clr(t)	memset(t,0,sizeof(t))
#define rep(i,n) for(int (i) = 0;i < (n);i++)
using namespace std;

int main()
{
	int n,b;
	cin >> n >> b;

	map<int,int> mx,my;
	int x[500],y[500],p[500];

	rep(i, n){
		cin >> x[i] >> y[i] >> p[i];
		mx[x[i]] = my[y[i]] = 0;
	}
	
	int xcount = 0;
	for (auto && i : mx)
		i.second = xcount++;
	int ycount = 0;
	for (auto && i : my)
		i.second = ycount++;

	vector<pair<int,int>> d[500];

	rep(i, n)
	{
		d[my[y[i]]].push_back(make_pair(mx[x[i]],p[i]));
	}

	int ans = 0;
	rep(x1,xcount)
	for (int x2 = x1; x2 < xcount; x2++)
	{
		int y1=0,y2=0;
		int psum = 0;int sum = 0;
		for (auto i : d[0])
		{
			if (i.first >= x1 && i.first <= x2)
			{
				psum += i.second;
				sum++;
			}
		}

		if (psum <= b)
		ans = max(sum, ans);

		while (!(y1 == ycount-1 && y2 == ycount-1))
		{
			if (psum > b || y2 == ycount-1)
			{
				for (auto i : d[y1])
				{
					if (i.first >= x1 && i.first <= x2)
					{
						psum -= i.second;
						sum--;
					}
				}
				y1++;
			}
			else
			{
				y2++;
				for (auto i : d[y2])
				{
					if (i.first >= x1 && i.first <= x2)
					{
						psum += i.second;
						sum++;
					}
				}
			}
			if (psum <= b)
			ans = max(sum,ans);
		}

	}

	cout << ans << endl;


	return 0;
	
}
0