結果

問題 No.165 四角で囲え!
ユーザー kimiyukikimiyuki
提出日時 2016-12-13 17:38:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 264 ms / 5,000 ms
コード長 2,904 bytes
コンパイル時間 1,149 ms
コンパイル使用メモリ 100,348 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 23:47:48
合計ジャッジ時間 4,567 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 145 ms
4,376 KB
testcase_06 AC 36 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 117 ms
4,376 KB
testcase_12 AC 127 ms
4,380 KB
testcase_13 AC 162 ms
4,376 KB
testcase_14 AC 233 ms
4,380 KB
testcase_15 AC 174 ms
4,376 KB
testcase_16 AC 207 ms
4,376 KB
testcase_17 AC 135 ms
4,376 KB
testcase_18 AC 264 ms
4,376 KB
testcase_19 AC 162 ms
4,376 KB
testcase_20 AC 135 ms
4,376 KB
testcase_21 AC 136 ms
4,376 KB
testcase_22 AC 134 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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;
}
0