結果

問題 No.165 四角で囲え!
ユーザー fiordfiord
提出日時 2015-08-26 08:50:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,926 ms / 5,000 ms
コード長 1,059 bytes
コンパイル時間 1,509 ms
コンパイル使用メモリ 161,212 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-26 23:47:15
合計ジャッジ時間 28,712 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,290 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1,715 ms
4,376 KB
testcase_06 AC 219 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 623 ms
4,388 KB
testcase_12 AC 231 ms
4,380 KB
testcase_13 AC 225 ms
4,380 KB
testcase_14 AC 348 ms
4,380 KB
testcase_15 AC 374 ms
4,376 KB
testcase_16 AC 2,760 ms
4,380 KB
testcase_17 AC 2,809 ms
4,380 KB
testcase_18 AC 2,926 ms
4,380 KB
testcase_19 AC 2,866 ms
4,380 KB
testcase_20 AC 2,830 ms
4,380 KB
testcase_21 AC 2,788 ms
4,380 KB
testcase_22 AC 2,811 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
map<int,int> mx,my;
vector<pair<int,int>> ls[402];
int main(){
	int n,b;	cin>>n>>b;
	int x[n],y[n],p[n];
	for(int i=0;i<n;i++)	cin>>x[i]>>y[i]>>p[i],mx[x[i]]=my[y[i]]=0;
	mx[(1<<30)]=mx[-(1<<30)]=my[(1<<30)]=my[-(1<<30)]=0;
	int cnt=0;
	for(auto it=mx.begin();it!=mx.end();it++)	it->second=cnt++;
	cnt=0;
	for(auto it=my.begin();it!=my.end();it++)	it->second=cnt++;
	for(int i=0;i<n;i++)	ls[my[y[i]]].push_back(make_pair(x[i],p[i]));
	int ans=0;
	for(int x1=0;x1<(int)mx.size();x1++){
		for(int x2=x1;x2<(int)mx.size();x2++){
			int y1=0,point=0,tmp=0;
			queue<pair<int,int>> q;
			for(int y2=0;y2<(int)my.size();y2++){
				int pp=0,ptmp=0;
				for(auto it=ls[y2].begin();it!=ls[y2].end();it++){
					if(x1<=mx[it->first]&&mx[it->first]<=x2)	pp+=it->second,ptmp++;
				}
				q.push(make_pair(pp,ptmp));	point+=pp,tmp+=ptmp;
				while(point>b&&!q.empty()){
					auto rmv=q.front();	q.pop();
					point-=rmv.first;	tmp-=rmv.second;
					y1++;
				}
				ans=max(ans,tmp);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
0