結果

問題 No.165 四角で囲え!
ユーザー parukiparuki
提出日時 2016-09-05 22:57:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 201 ms / 5,000 ms
コード長 1,864 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 175,852 KB
実行使用メモリ 6,092 KB
最終ジャッジ日時 2023-08-26 23:47:36
合計ジャッジ時間 4,452 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
5,084 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 139 ms
5,424 KB
testcase_06 AC 23 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 57 ms
4,852 KB
testcase_12 AC 23 ms
4,376 KB
testcase_13 AC 23 ms
4,380 KB
testcase_14 AC 17 ms
4,376 KB
testcase_15 AC 17 ms
4,376 KB
testcase_16 AC 201 ms
6,044 KB
testcase_17 AC 162 ms
5,992 KB
testcase_18 AC 157 ms
6,012 KB
testcase_19 AC 187 ms
6,092 KB
testcase_20 AC 167 ms
6,032 KB
testcase_21 AC 169 ms
6,000 KB
testcase_22 AC 168 ms
5,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<class Val>
vector<Val> compress(vector<Val> &v){
    vector<Val> a = v;
    sort(all(a));
    a.erase(unique(all(a)), a.end());
    each(b, v)b = (int)(lower_bound(all(a), b) - a.begin());
    return a;
}

typedef int SumType;
class Sum2D{
public:
    Sum2D(){}
    Sum2D(const vector<vector<SumType>> &a)
    :h((int)a.size()),w((int)a[0].size()), s(h+1, vector<SumType>(w+1))
    {
        for(int i = 1; i <= h; ++i) for(int j = 1; j <= w; ++j)
            s[i][j] = s[i - 1][j] + s[i][j - 1] + a[i-1][j-1] - s[i - 1][j - 1];
    }

    SumType sum(int u, int l, int d, int r){
        return s[d][r] - s[u][r] - s[d][l] + s[u][l];
    }
private:
    int h, w;
    vector<vector<SumType>> s;
};

int main(){
    int N, B;
    cin >> N >> B;

    vi X(N), Y(N), P(N);
    rep(i, N)scanf("%d%d%d", &X[i], &Y[i], &P[i]);

    int H = sz(compress(Y));
    int W = sz(compress(X));

    vector<vi> A(H, vi(W)), aa(H, vi(W));
    rep(i, N){
        A[Y[i]][X[i]] = P[i];
        aa[Y[i]][X[i]] = 1;
    }

    Sum2D sm(A), tm(aa);

    int ans = 0;
    rep(u, H)rep(l, W){
        if(A[u][l] > B)continue;
        int r = W;

        FOR(d, u + 1, H + 1){
            while(l<r && sm.sum(u, l, d, r)>B)r--;
            if(l == r)break;
            int cnt = tm.sum(u, l, d, r);
            smax(ans, cnt);
        }
    }
    cout << ans << endl;
}
0