結果

問題 No.165 四角で囲え!
ユーザー なおなお
提出日時 2015-03-12 23:54:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 161 ms / 5,000 ms
コード長 2,071 bytes
コンパイル時間 1,334 ms
コンパイル使用メモリ 153,900 KB
実行使用メモリ 5,052 KB
最終ジャッジ日時 2023-08-26 23:31:35
合計ジャッジ時間 3,718 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
4,576 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 113 ms
4,604 KB
testcase_06 AC 26 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 47 ms
4,380 KB
testcase_12 AC 20 ms
4,380 KB
testcase_13 AC 21 ms
4,376 KB
testcase_14 AC 16 ms
4,376 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 AC 155 ms
4,844 KB
testcase_17 AC 112 ms
4,880 KB
testcase_18 AC 161 ms
5,052 KB
testcase_19 AC 135 ms
4,852 KB
testcase_20 AC 115 ms
4,880 KB
testcase_21 AC 115 ms
4,904 KB
testcase_22 AC 115 ms
4,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
#define FOR(i, f, t)        for(int(i)=(f);(i)<(t);(++i))
#define RREP(i, n)          for(int(i)=(n)-1;(i)>=0;--(i))
#define FOREACH(it, c)      for(auto it=(c).begin();it!=(c).end();++it)
const int MOD = int(1e9+7);

int res = 0;

int N, B;
int x[444],y[444],p[444];

int m1[444][444];
int m2[444][444];

int s1(int x1, int y1, int x2, int y2){
    int sum = m1[y2][x2];
    if(x1 > 0) sum -= m1[y2][x1-1];
    if(y1 > 0) sum -= m1[y1-1][x2];
    if(x1 > 0 && y1 > 0) sum += m1[y1-1][x1-1];
    return sum;
}
int s2(int x1, int y1, int x2, int y2){
    int sum = m2[y2][x2];
    if(x1 > 0) sum -= m2[y2][x1-1];
    if(y1 > 0) sum -= m2[y1-1][x2];
    if(x1 > 0 && y1 > 0) sum += m2[y1-1][x1-1];
    return sum;
}

int main(){
    do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0);

    cin >> N >> B;

    map<int,int> mx, my;

    REP(i,N){
        cin >> x[i] >> y[i] >> p[i];
        mx[x[i]] = 1;
        my[y[i]] = 1;
    }

    int w = 0; FOREACH(it, mx) it->second = w++;
    int h = 0; FOREACH(it, my) it->second = h++;

    REP(i,N){
        int xx = mx[x[i]], yy = my[y[i]];
        m1[yy][xx] += p[i];
        m2[yy][xx] ++;
    }

    FOR(x,1,w){
        m1[0][x] = m1[0][x] + m1[0][x-1];
        m2[0][x] = m2[0][x] + m2[0][x-1];
    }
    FOR(y,1,h){
        m1[y][0] = m1[y][0] + m1[y-1][0];
        m2[y][0] = m2[y][0] + m2[y-1][0];
    }
    FOR(y,1,h) FOR(x,1,w){
        m1[y][x] = m1[y][x] + m1[y][x-1] + m1[y-1][x] - m1[y-1][x-1];
        m2[y][x] = m2[y][x] + m2[y][x-1] + m2[y-1][x] - m2[y-1][x-1];
    }

    int maxv = 0;
    REP(y1,h)REP(x1,w){
        int x2 = x1;
        for(int y2 = h-1; y2 >= y1; y2--){
            while(x2 < w){
                if(s1(x1,y1,x2,y2) > B) break;
                maxv = max(maxv, s2(x1,y1,x2,y2));
                x2++;
            }
        }
    }
    cout << maxv << endl;
    return 0;
}
0