結果

問題 No.165 四角で囲え!
ユーザー msm1993msm1993
提出日時 2020-06-01 11:49:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 5,000 ms
コード長 1,562 bytes
コンパイル時間 2,736 ms
コンパイル使用メモリ 180,296 KB
実行使用メモリ 4,952 KB
最終ジャッジ日時 2023-08-13 16:28:48
合計ジャッジ時間 4,517 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
4,784 KB
testcase_01 AC 3 ms
4,728 KB
testcase_02 AC 3 ms
4,680 KB
testcase_03 AC 3 ms
4,732 KB
testcase_04 AC 3 ms
4,628 KB
testcase_05 AC 82 ms
4,652 KB
testcase_06 AC 17 ms
4,700 KB
testcase_07 AC 3 ms
4,620 KB
testcase_08 AC 3 ms
4,776 KB
testcase_09 AC 3 ms
4,764 KB
testcase_10 AC 3 ms
4,676 KB
testcase_11 AC 64 ms
4,764 KB
testcase_12 AC 78 ms
4,808 KB
testcase_13 AC 81 ms
4,952 KB
testcase_14 AC 82 ms
4,772 KB
testcase_15 AC 77 ms
4,652 KB
testcase_16 AC 115 ms
4,672 KB
testcase_17 AC 76 ms
4,832 KB
testcase_18 AC 119 ms
4,720 KB
testcase_19 AC 92 ms
4,660 KB
testcase_20 AC 75 ms
4,732 KB
testcase_21 AC 75 ms
4,736 KB
testcase_22 AC 75 ms
4,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

struct Point {
	int x;
	int y;
	int p;
};

int score[410][410], cnt[410][410];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, b;
	cin >> n >> b;
	vector<Point> ps(n);
	vector<int> vx(n), vy(n);
	for (int i = 0; i < n; i++) {
		cin >> ps[i].x >> ps[i].y >> ps[i].p;
		vx[i] = ps[i].x;
		vy[i] = ps[i].y;
	}

	sort(vx.begin(), vx.end());
	sort(vy.begin(), vy.end());
	vx.erase(unique(vx.begin(), vx.end()), vx.end());
	vy.erase(unique(vy.begin(), vy.end()), vy.end());
	map<int, int> X, Y;
	for (int i = 0; i < vx.size(); i++) X[vx[i]] = i;
	for (int i = 0; i < vy.size(); i++) Y[vy[i]] = i;

	for (int i = 0; i < n; i++) {
		score[X[ps[i].x] + 1][Y[ps[i].y] + 1] += ps[i].p;
		cnt[X[ps[i].x] + 1][Y[ps[i].y] + 1]++;
	}
	for (int i = 1; i <= 400; i++) {
		for (int j = 0; j <= 400; j++) {
			score[i][j] += score[i - 1][j];
			cnt[i][j] += cnt[i - 1][j];
		}
	}
	for (int i = 0; i <= 400; i++) {
		for (int j = 1; j <= 400; j++) {
			score[i][j] += score[i][j - 1];
			cnt[i][j] += cnt[i][j - 1];
		}
	}

	int ans = 0;
	for (int x1 = 0; x1 < n; x1++) {
		for (int x2 = x1; x2 < n; x2++) {
			for (int y1 = 0, y2 = 0; y2 < n; y2++) {
				while (y1 <= y2) {
					int tmp_score = score[x2 + 1][y2 + 1] - score[x2 + 1][y1] - score[x1][y2 + 1] + score[x1][y1];
					int tmp_cnt = cnt[x2 + 1][y2 + 1] - cnt[x2 + 1][y1] - cnt[x1][y2 + 1] + cnt[x1][y1];
					if (tmp_score <= b) {
						ans = max(ans, tmp_cnt);
						break;
					}	
					y1++;					
				}				
			}
		}
	}
	cout << ans << endl;
	return 0;
}
0