結果
| 問題 | No.165 四角で囲え! |
| コンテスト | |
| ユーザー |
msm1993
|
| 提出日時 | 2020-06-01 11:49:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 144 ms / 5,000 ms |
| コード長 | 1,562 bytes |
| コンパイル時間 | 1,967 ms |
| コンパイル使用メモリ | 183,888 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-21 12:32:27 |
| 合計ジャッジ時間 | 4,626 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
ソースコード
#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;
}
msm1993