結果

問題 No.165 四角で囲え!
ユーザー sugim48sugim48
提出日時 2015-03-13 00:24:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,946 bytes
コンパイル時間 821 ms
コンパイル使用メモリ 94,072 KB
実行使用メモリ 6,196 KB
最終ジャッジ日時 2023-09-11 08:10:45
合計ジャッジ時間 7,334 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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