結果

問題 No.165 四角で囲え!
ユーザー kimiyuki
提出日時 2016-12-13 17:38:18
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 257 ms / 5,000 ms
コード長 2,904 bytes
コンパイル時間 1,332 ms
コンパイル使用メモリ 104,928 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-26 03:37:34
合計ジャッジ時間 4,806 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
typedef long long ll;
using namespace std;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector
    <decltype(cont)>(x, cont); }
template <typename T>
map<T,int> coordinate_compression_map(vector<T> const & xs) {
int n = xs.size();
vector<int> ys(n);
whole(iota, ys, 0);
whole(sort, ys, [&](int i, int j) { return xs[i] < xs[j]; });
map<T,int> f;
for (int i : ys) {
if (not f.count(xs[i])) { // make unique
int j = f.size();
f[xs[i]] = j; // f[xs[i]] has a side effect, increasing the f.size()
}
}
return f;
}
template <typename T>
vector<int> apply_compression(map<T,int> const & f, vector<T> const & xs) {
int n = xs.size();
vector<int> ys(n);
repeat (i,n) ys[i] = f.at(xs[i]);
return ys;
}
int main() {
int n, b; cin >> n >> b;
vector<int> x(n), y(n), p(n); repeat (i,n) cin >> x[i] >> y[i] >> p[i];
x = apply_compression(coordinate_compression_map(x), x);
y = apply_compression(coordinate_compression_map(y), y);
vector<int> j(n);
whole(iota, j, 0);
whole(sort, j, [&](int i, int j) { return x[i] < x[j]; });
int ans = 0;
repeat (ry,n+1) repeat (ly,ry) {
int li = 0, ri = 0;
int lx = 0, rx = 0;
int cnt = 0, sum_p = 0;
while (rx < n) {
++ rx;
while (ri < n and x[j[ri]] < rx) {
if (ly <= y[j[ri]] and y[j[ri]] < ry) {
cnt += 1;
sum_p += p[j[ri]];
}
++ ri;
}
while (b < sum_p) {
++ lx;
while (li < n and x[j[li]] < lx) {
if (ly <= y[j[li]] and y[j[li]] < ry) {
cnt -= 1;
sum_p -= p[j[li]];
}
++ li;
}
}
setmax(ans, cnt);
}
}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0