結果

問題 No.165 四角で囲え!
ユーザー __math__math
提出日時 2015-03-13 00:02:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 192 ms / 5,000 ms
コード長 1,944 bytes
コンパイル時間 1,066 ms
コンパイル使用メモリ 113,860 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 23:31:39
合計ジャッジ時間 3,782 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 131 ms
4,376 KB
testcase_06 AC 36 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 64 ms
4,380 KB
testcase_12 AC 32 ms
4,376 KB
testcase_13 AC 30 ms
4,380 KB
testcase_14 AC 38 ms
4,376 KB
testcase_15 AC 37 ms
4,380 KB
testcase_16 AC 173 ms
4,376 KB
testcase_17 AC 142 ms
4,376 KB
testcase_18 AC 192 ms
4,376 KB
testcase_19 AC 159 ms
4,376 KB
testcase_20 AC 145 ms
4,376 KB
testcase_21 AC 144 ms
4,376 KB
testcase_22 AC 143 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <iterator>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

int compress(vector<int>& v){
	vector<int> a = v;
	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());
	for (auto& x : v) x = lower_bound(a.begin(), a.end(), x) - a.begin();
	return sz(a);
}

int main(){
	int n, b; cin >> n >> b;
	b++;
	vector<int> xv, yv, pv;
	vector<tuple<int, int, int>> tp;
	FOR(i, n){
		int x, y, p; cin >> x >> y >> p;
		tp.emplace_back(y, x, p);
	}
	sort(tp.begin(), tp.end());
	for (auto a : tp) {
		int y, x, p;
		tie(y,x,p) = a;
		xv.push_back(x);
		yv.push_back(y);
		pv.push_back(p);
	}

	int len = compress(xv);
	compress(yv);

	int ans = 0;
	FOR(i, len){
		for (int j = i; j < len; j++) {
			Pii cur[400] = {};
			FOR(k, sz(xv)) if (i <= xv[k] && xv[k] <= j) {
				cur[yv[k]].first += 1;
				cur[yv[k]].second += pv[k];
			}
			int r = 0, bsum = 0;
			int sm = 0;
			FOR(k, 400){
				r = max(r, k);
				while (r < 400 && bsum + cur[r].second < b) {
					sm += cur[r].first;
					bsum += cur[r].second;
					r++;
				}
				if (sm > ans) {
					ans = sm;
				}

				if (sm) {
					bsum -= cur[k].second;
					sm -= cur[k].first;
				}
			}
		}
	}

	cout << ans << endl;
}
0