結果

問題 No.165 四角で囲え!
ユーザー codershifthcodershifth
提出日時 2015-12-29 10:44:09
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,833 bytes
コンパイル時間 8,812 ms
コンパイル使用メモリ 185,068 KB
最終ジャッジ日時 2023-10-23 14:47:55
合計ジャッジ時間 17,096 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;

pair<ll,ll> operator+(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return make_pair(a.first+b.first, a.second+b.second);
}
pair<ll,ll> operator-(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return make_pair(a.first-b.first, a.second-b.second);
}
class SurroundWithSquare {
public:
    void dump(const pair<ll,ll> &a) {
        cerr<<a.first<<","<<a.second<<endl;
    }
    void solve(void)
    {
        int N,B;
        cin>>N>>B;

        // 座標圧縮を使う
        vector<ll> xs;
        vector<ll> ys;
        vector<tuple<ll,ll,ll>> ps;
        REP(i,N)
        {
            ll x,y,p;
            cin>>x>>y>>p;
            ps.emplace_back(x,y,p);
            xs.push_back(x);
            ys.push_back(y);
        }
        sort(RANGE(xs));
        sort(RANGE(ys));

        map<ll,int> xmap;
        map<ll,int> ymap;
        REP(i,N)
        {
            xmap.emplace(xs[i],xmap.size());
            ymap.emplace(ys[i],ymap.size());
        }
        const int maxX = xmap.size();
        const int maxY = ymap.size();

        // 0<=x,y<400
        pair<ll,ll> field[maxY][maxX];
        REP(y,maxY) REP(x,maxX) field[y][x] = make_pair(0,0);

        REP(i,N)
        {
            ll x,y,p;
            tie(x,y,p) = ps[i];
            field[ymap[y]][xmap[x]] = make_pair(p,1);
        }
        pair<ll,ll> Sum[maxY][maxX];
        REP(i,maxY) REP(j,maxX) Sum[i][j] = make_pair(0,0);

        REP(y,maxY)
        REP(x,maxX)
        {
            Sum[y][x] = field[y][x];
            if (x > 0)
                Sum[y][x] = Sum[y][x] + Sum[y][x-1];
        }
        REP(y,maxY)
        REP(x,maxX)
        {
            if (y > 0)
                Sum[y][x] = Sum[y][x] + Sum[y-1][x];
        }

        //REP(y,maxY) { REP(x,maxX) cerr<<Sum[y][x].second<<" ";cerr<<endl;}

        ll maxN = 0;
        REP(uy,maxY)
        REP(ux,maxX)
        REP(ly,uy+1)
        REP(lx,ux+1)
        {
            pair<ll,ll> cnt(0,0);
            pair<ll,ll> lb,rb,lt,rt;
            lb = rb = lt = rt = make_pair(0,0);

            rt = Sum[uy][ux];
            if (ly > 0)
                rb = Sum[ly-1][ux];
            if (lx > 0)
                lt = Sum[uy][lx-1];
            if (lx > 0 && ly > 0)
                lb = Sum[ly-1][lx-1];

            cnt = rt - lt - rb + lb;
            if (cnt.first <= B)
                maxN = max(maxN, cnt.second);
        }
        cout<<maxN<<endl;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new SurroundWithSquare();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0