結果

問題 No.165 四角で囲え!
ユーザー sugim48sugim48
提出日時 2015-03-13 00:31:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 223 ms / 5,000 ms
コード長 1,946 bytes
コンパイル時間 864 ms
コンパイル使用メモリ 92,424 KB
実行使用メモリ 6,116 KB
最終ジャッジ日時 2023-08-26 23:34:32
合計ジャッジ時間 3,518 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
5,068 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 140 ms
5,248 KB
testcase_06 AC 29 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,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 55 ms
4,764 KB
testcase_12 AC 22 ms
4,376 KB
testcase_13 AC 23 ms
4,376 KB
testcase_14 AC 18 ms
4,376 KB
testcase_15 AC 16 ms
4,380 KB
testcase_16 AC 193 ms
6,116 KB
testcase_17 AC 141 ms
6,016 KB
testcase_18 AC 223 ms
5,960 KB
testcase_19 AC 169 ms
5,960 KB
testcase_20 AC 147 ms
5,936 KB
testcase_21 AC 147 ms
6,024 KB
testcase_22 AC 147 ms
5,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <complex>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v, w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int compress(vector<int>& X) {
	vector<int> x = X;
	sort(x.begin(), x.end());
	x.erase(unique(x.begin(), x.end()), x.end());
	for (int i = 0; i < X.size(); i++)
		X[i] = lower_bound(x.begin(), x.end(), X[i]) - x.begin();
	return x.size();
}

int calc(int l, int r, int u, int d, vector<vector<int> >& sum) {
	return sum[d][r] - sum[d][l] - sum[u][r] + sum[u][l];
}

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];
	int w = compress(X), h = compress(Y);
	vector<vector<int> > a(h, vector<int>(w)), p(h, vector<int>(w));
	for (int i = 0; i < N; i++) {
		a[Y[i]][X[i]]++;
		p[Y[i]][X[i]] += P[i];
	}
	vector<vector<int> > asum(h + 1, vector<int>(w + 1)), psum(h + 1, vector<int>(w + 1));
	for (int y = 1; y <= h; y++)
		for (int x = 1; x <= w; x++) {
			asum[y][x] = asum[y][x - 1] + asum[y - 1][x] - asum[y - 1][x - 1] + a[y - 1][x - 1];
			psum[y][x] = psum[y][x - 1] + psum[y - 1][x] - psum[y - 1][x - 1] + p[y - 1][x - 1];
		}
	int maxi = 0;
	for (int l = 0; l <= w; l++)
		for (int r = l; r <= w; r++) {
			int d = 0;
			for (int u = 0; u <= h; u++)
				while (d <= h && calc(l, r, u, d, psum) <= B) {
					maxi = max(maxi, calc(l, r, u, d, asum));
					d++;
				}
		}
	cout << maxi << endl;
}
0