結果

問題 No.165 四角で囲え!
ユーザー なおなお
提出日時 2015-03-12 23:51:00
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,971 bytes
コンパイル時間 1,485 ms
コンパイル使用メモリ 154,232 KB
実行使用メモリ 8,624 KB
最終ジャッジ日時 2023-09-11 08:03:09
合計ジャッジ時間 13,955 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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>
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){
        FOR(y2,y1,h) FOR(x2,x1,w){
            if(s1(x1,y1,x2,y2) > B) break;
            maxv = max(maxv, s2(x1,y1,x2,y2));
        }
    }
    cout << maxv << endl;
    return 0;
}
0