結果

問題 No.165 四角で囲え!
ユーザー omuomu
提出日時 2015-03-18 00:02:54
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,224 bytes
コンパイル時間 559 ms
コンパイル使用メモリ 74,908 KB
実行使用メモリ 8,608 KB
最終ジャッジ日時 2023-09-11 08:32:08
合計ジャッジ時間 15,632 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4,192 ms
4,696 KB
testcase_01 AC 2 ms
4,404 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,500 KB
testcase_04 AC 2 ms
4,540 KB
testcase_05 TLE -
testcase_06 AC 622 ms
4,636 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,668 KB
testcase_09 AC 3 ms
4,472 KB
testcase_10 AC 3 ms
4,680 KB
testcase_11 AC 1,857 ms
4,572 KB
testcase_12 AC 597 ms
4,676 KB
testcase_13 AC 596 ms
4,504 KB
testcase_14 AC 325 ms
4,684 KB
testcase_15 AC 389 ms
4,376 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

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++;

	int d[500][500]; clr(d);

	rep(i, n)
	{
		d[mx[x[i]]][my[y[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 (int x = x1; x < x2 + 1; x++){
			psum += d[x][0];
			sum += d[x][0]?1:0;
		}

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

		while (!(y1 == ycount-1 && y2 == ycount-1))
		{
			if (psum > b || y2 == ycount-1)
			{
				for (int x = x1; x < x2 + 1; x++){
					psum -= d[x][y1];
					sum -= d[x][y1] ? 1 : 0;
				}
				y1++;
			}
			else
			{
				y2++;
				for (int x = x1; x < x2 + 1; x++){
					psum += d[x][y2];
					sum += d[x][y2] ? 1 : 0;
				}
			}
			if (psum <= b)
			ans = max(sum,ans);
		}

	}

	cout << ans << endl;


	return 0;
	
}
0