結果

問題 No.165 四角で囲え!
ユーザー pekempeypekempey
提出日時 2015-08-20 16:27:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 1,548 bytes
コンパイル時間 1,725 ms
コンパイル使用メモリ 153,088 KB
実行使用メモリ 6,840 KB
最終ジャッジ日時 2023-08-26 23:45:21
合計ジャッジ時間 3,517 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
5,952 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 96 ms
6,108 KB
testcase_06 AC 20 ms
5,028 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 40 ms
5,656 KB
testcase_12 AC 17 ms
5,040 KB
testcase_13 AC 17 ms
5,288 KB
testcase_14 AC 14 ms
4,772 KB
testcase_15 AC 13 ms
5,100 KB
testcase_16 AC 131 ms
6,768 KB
testcase_17 AC 91 ms
6,668 KB
testcase_18 AC 135 ms
6,536 KB
testcase_19 AC 111 ms
6,652 KB
testcase_20 AC 92 ms
6,544 KB
testcase_21 AC 91 ms
6,840 KB
testcase_22 AC 92 ms
6,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

ll N, B;
ll X[400], Y[400], P[400];
ll sum[500][500], num[500][500];

ll calc(ll s[500][500], int x1, int y1, int x2, int y2) {
	return s[x2][y2] - s[x2][y1] - s[x1][y2] + s[x1][y1];
}

int main() {
	cin >> N >> B;
	rep (i, N) cin >> X[i] >> Y[i] >> P[i];

	vector<ll> xs, ys;
	rep (i, N) {
		xs.push_back(X[i]);
		ys.push_back(Y[i]);
	}
	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	ys.erase(unique(ys.begin(), ys.end()), ys.end());

	rep (i, N) {
		X[i] = lower_bound(xs.begin(), xs.end(), X[i]) - xs.begin();
		Y[i] = lower_bound(ys.begin(), ys.end(), Y[i]) - ys.begin();
	}

	int W = xs.size() + 2;
	int H = ys.size() + 2;

	rep (i, N) {
		sum[X[i] + 1][Y[i] + 1] += P[i];
		num[X[i] + 1][Y[i] + 1]++;
	}
	rep (i, W + 1) rep (j, H + 1) {
		sum[i][j + 1] += sum[i][j];
		num[i][j + 1] += num[i][j];
	}
	rep (j, H + 1) rep (i, W + 1) {
		sum[i + 1][j] += sum[i][j];
		num[i + 1][j] += num[i][j];
	}

	ll ans = 0;

	rep (i, W * H) {
		int x1 = i % W;
		int y1 = i / W;
		int x2 = W;
		rep2 (y2, y1 + 1, H) {
			while (x2 > x1 && calc(sum, x1, y1, x2, y2) > B) x2--;
			ans = max(ans, calc(num, x1, y1, x2, y2));
		}
	}
	cout << ans << endl;

	return 0;
}
0