結果
| 問題 |
No.165 四角で囲え!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-08-20 16:27:11 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 158 ms / 5,000 ms |
| コード長 | 1,548 bytes |
| コンパイル時間 | 2,205 ms |
| コンパイル使用メモリ | 166,032 KB |
| 実行使用メモリ | 6,784 KB |
| 最終ジャッジ日時 | 2024-12-26 03:34:08 |
| 合計ジャッジ時間 | 3,373 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
ソースコード
#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;
}