結果

問題 No.165 四角で囲え!
ユーザー face4face4
提出日時 2019-09-28 11:10:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,350 bytes
コンパイル時間 960 ms
コンパイル使用メモリ 90,084 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 19:27:41
合計ジャッジ時間 4,672 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 184 ms
6,940 KB
testcase_06 AC 37 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 RE -
testcase_12 AC 104 ms
6,940 KB
testcase_13 AC 98 ms
6,948 KB
testcase_14 AC 109 ms
6,944 KB
testcase_15 AC 96 ms
6,940 KB
testcase_16 RE -
testcase_17 AC 212 ms
6,940 KB
testcase_18 AC 323 ms
6,940 KB
testcase_19 AC 244 ms
6,944 KB
testcase_20 AC 216 ms
6,940 KB
testcase_21 AC 220 ms
6,940 KB
testcase_22 AC 219 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

#define inRange(x,a,b) (a <= x && x <= b)
typedef pair<int,int> pii;
const int INF = 1e9+1;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, b;
    cin >> n >> b;
    vector<pair<pii,int>> vp;
    vector<int> ax, ay;
    for(int i = 0; i < n; i++){
        int x, y, p;
        cin >> x >> y >> p;
        vp.push_back({{x,y},p});
        ax.push_back(x);
        ay.push_back(y);
    }
    ax.push_back(INF); ax.push_back(-INF);
    ay.push_back(INF); ay.push_back(-INF);

    sort(ax.begin(),ax.end());
    ax.erase(unique(ax.begin(),ax.end()),ax.end());
    auto fx = [&](int val)->int{
        return lower_bound(ax.begin(),ax.end(),val)-ax.begin();
    };
    sort(ay.begin(),ay.end());
    ay.erase(unique(ay.begin(),ay.end()),ay.end());
    auto fy = [&](int val)->int{
        return lower_bound(ay.begin(),ay.end(),val)-ay.begin();
    };
    int numx = ax.size(), numy = ax.size();

    vector<vector<int>> cnt(numx, vector<int>(numy, 0)), sum(numx, vector<int>(numy, 0));
    for(int i = 0; i < n; i++){
        int ix = fx(vp[i].first.first), iy = fy(vp[i].first.second);
        cnt[ix][iy]++;
        sum[ix][iy] += vp[i].second;
    }
    for(int i = 0; i < numx; i++){
        for(int j = 1; j < numy; j++){
            cnt[i][j] += cnt[i][j-1];
            sum[i][j] += sum[i][j-1];
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i; j < n; j++){
            int low = fy(vp[i].first.second), high = fy(vp[j].first.second);
            if(low > high)  swap(low, high);
            int l = 0, r = 0, tmpsum = 0, tmpcnt = 0;
            while(l < numx){
                while(r < numx && sum[r][high]-sum[r][low-1]+tmpsum <= b){
                    tmpsum += sum[r][high]-sum[r][low-1];
                    tmpcnt += cnt[r][high]-cnt[r][low-1];
                    r++;
                }
                ans = max(ans, tmpcnt);
                if(l == r){
                    l = ++r;
                    tmpsum = 0, tmpcnt = 0;
                }else{
                    tmpsum -= sum[l][high]-sum[l][low-1];
                    tmpcnt -= cnt[l][high]-cnt[l][low-1];
                    l++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0