結果

問題 No.165 四角で囲え!
ユーザー koyoprokoyopro
提出日時 2015-10-22 23:51:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 681 ms / 5,000 ms
コード長 1,797 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 155,852 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 23:45:48
合計ジャッジ時間 9,000 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 340 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 437 ms
4,376 KB
testcase_06 AC 84 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 231 ms
4,380 KB
testcase_12 AC 147 ms
4,380 KB
testcase_13 AC 47 ms
4,376 KB
testcase_14 AC 142 ms
4,380 KB
testcase_15 AC 146 ms
4,376 KB
testcase_16 AC 658 ms
4,376 KB
testcase_17 AC 643 ms
4,380 KB
testcase_18 AC 681 ms
4,376 KB
testcase_19 AC 674 ms
4,380 KB
testcase_20 AC 659 ms
4,376 KB
testcase_21 AC 660 ms
4,376 KB
testcase_22 AC 657 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define int long long
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
struct P { int x, y, p; P(){}; P(int _x, int _y): x(_x), y(_y){}; };

int N,T,B;
vector<P> ps;
bool compx(int i, int j) {
    return ps[i].x < ps[j].x;
}
bool compy(int i, int j) {
    return ps[i].y < ps[j].y;
}
map<int, vector<int> > xm;
signed main()
{
    cin >> N >> B;
    ps.resize(N);
    REP(i,N) cin >> ps[i].x >> ps[i].y >> ps[i].p;
    vector<int> xs;
    vector<int> ys;
    REP(i,N) xs.push_back(i);
    REP(i,N) ys.push_back(i);
    sort(ALL(ys), compy);
    sort(ALL(xs), compx);
    int maxn = 0;
    REP(i,N) REP(j,i+1) {
        if (j && ps[xs[j-1]].x == ps[xs[j]].x) continue;
        if (i < N-1 && ps[xs[i+1]].x == ps[xs[i]].x) continue;
        int bottom = 0;
        int top = 0;
        int point = 0;
        int num = 0;
        vector<int> qs;
        FOR(k,j,i+1) {
            qs.push_back(xs[k]);
        }
        sort(ALL(qs), compy);
        // 尺取り法
        while(top < qs.size()) {
            P p = ps[qs[top]];
            num++;
            point += p.p;
            while(top + 1 < qs.size() && ps[qs[top+1]].y == p.y) {
                top++;
                P p = ps[qs[top]];
                point += p.p;
                num++;
            }
            while (point > B) {
                int y = ps[qs[bottom]].y;
                while(bottom <= top && ps[qs[bottom]].y == y) {
                    point -= ps[qs[bottom]].p;
                    num--;
                    bottom++;
                }
            }
            maxn = max(maxn, num);
            // 次へ
            top++;
        }
    }
    cout << maxn << endl;
    return 0;
}
0