結果

問題 No.165 四角で囲え!
ユーザー outlineoutline
提出日時 2021-03-15 23:22:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 976 ms / 5,000 ms
コード長 2,892 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 143,608 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 02:37:26
合計ジャッジ時間 11,146 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 477 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 592 ms
5,376 KB
testcase_06 AC 102 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 251 ms
5,376 KB
testcase_12 AC 108 ms
5,376 KB
testcase_13 AC 108 ms
5,376 KB
testcase_14 AC 65 ms
5,376 KB
testcase_15 AC 78 ms
5,376 KB
testcase_16 AC 904 ms
5,376 KB
testcase_17 AC 937 ms
5,376 KB
testcase_18 AC 904 ms
5,376 KB
testcase_19 AC 965 ms
5,376 KB
testcase_20 AC 955 ms
5,376 KB
testcase_21 AC 957 ms
5,376 KB
testcase_22 AC 976 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template<typename T>
struct CumulativeSum2D{
    vector<vector<T>> data;

    CumulativeSum2D(int W, int H) : data(W + 1, vector<T>(H + 1, 0)) {}

    void add(int x, int y, T z){
        ++x, ++y;
        if(x >= data.size() || y >= data[0].size()) return;
        data[x][y] += z;
    }

    void build(){
        for(int i = 1; i < (int)data.size(); ++i){
            for(int j = 1; j < (int)data[i].size(); ++j){
                data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
            }
        }
    }

    T query(int sx, int sy, int gx, int gy){
        return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
    }
};

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

    int N, B;
    cin >> N >> B;
    vector<int> X(N), Y(N), P(N), xs, ys;
    for(int i = 0; i < N; ++i){
        cin >> X[i] >> Y[i] >> P[i];
        xs.emplace_back(X[i]);
        ys.emplace_back(Y[i]);
    }
    sort(begin(xs), end(xs));
    sort(begin(ys), end(ys));
    xs.erase(unique(begin(xs), end(xs)), end(xs));
    ys.erase(unique(begin(ys), end(ys)), end(ys));
    int H = xs.size(), W = ys.size();
    CumulativeSum2D<int> score(H, W), point(H, W);
    for(int i = 0; i < N; ++i){
        int x = lower_bound(begin(xs), end(xs), X[i]) - begin(xs);
        int y = lower_bound(begin(ys), end(ys), Y[i]) - begin(ys);
        score.add(x, y, P[i]);
        point.add(x, y, 1);
    }
    score.build();
    point.build();
    int ans = 0;
    for(int lx = 0; lx < H; ++lx){
        for(int rx = lx + 1; rx <= H; ++rx){
            for(int ly = 0; ly < W; ++ly){
                int low = ly, high = W + 1;
                while(high - low > 1){
                    int mid = (low + high) / 2;
                    if(score.query(lx, ly, rx, mid) <= B)   low = mid;
                    else    high = mid;
                }
                chmax(ans, point.query(lx, ly, rx, low));
            }
        }
    }
    cout << ans << endl;

    return 0;
}
0