結果

問題 No.165 四角で囲え!
ユーザー h_nosonh_noson
提出日時 2016-05-02 11:18:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 187 ms / 5,000 ms
コード長 1,616 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 74,996 KB
実行使用メモリ 4,940 KB
最終ジャッジ日時 2023-08-26 23:47:22
合計ジャッジ時間 2,784 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
4,592 KB
testcase_01 AC 3 ms
4,556 KB
testcase_02 AC 2 ms
4,644 KB
testcase_03 AC 3 ms
4,656 KB
testcase_04 AC 3 ms
4,632 KB
testcase_05 AC 97 ms
4,628 KB
testcase_06 AC 26 ms
4,648 KB
testcase_07 AC 2 ms
4,612 KB
testcase_08 AC 3 ms
4,696 KB
testcase_09 AC 2 ms
4,532 KB
testcase_10 AC 2 ms
4,628 KB
testcase_11 AC 40 ms
4,580 KB
testcase_12 AC 17 ms
4,616 KB
testcase_13 AC 19 ms
4,664 KB
testcase_14 AC 15 ms
4,772 KB
testcase_15 AC 12 ms
4,552 KB
testcase_16 AC 129 ms
4,644 KB
testcase_17 AC 88 ms
4,700 KB
testcase_18 AC 187 ms
4,600 KB
testcase_19 AC 108 ms
4,940 KB
testcase_20 AC 90 ms
4,604 KB
testcase_21 AC 89 ms
4,752 KB
testcase_22 AC 89 ms
4,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 100000000

typedef long long ll;

int main() {
    int i, j, n, b;
    int x[400], y[400], p[400];
    int points[401][401] {};
    int cnt[401][401] {};
    map<int,int> mpx, mpy;
    cin >> n >> b;
    rep (i,n) {
        cin >> x[i] >> y[i] >> p[i];
        mpx[x[i]]++;
        mpy[y[i]]++;
    }
    j = 1;
    for (auto& e : mpx) e.second = j++;
    j = 1;
    for (auto& e : mpy) e.second = j++;
    rep (i,n) {
        x[i] = mpx[x[i]];
        y[i] = mpy[y[i]];
        points[x[i]][y[i]] = p[i];
        cnt[x[i]][y[i]] = 1;
    }
    rep (i,mpx.size()+1) REP (j,1,mpy.size()) {
        points[i][j] += points[i][j-1];
        cnt[i][j] += cnt[i][j-1];
    }
    rep (j,mpy.size()+1) REP (i,1,mpx.size()) {
        points[i][j] += points[i-1][j];
        cnt[i][j] += cnt[i-1][j];
    }
    int ans = 0;
    REP (i,1,mpx.size()) REP (j,i,mpx.size()) {
        int k, l;
        k = l = 1;
        while (l <= mpy.size()) {
            int pnt = points[j][l] - points[j][k-1] - points[i-1][l] + points[i-1][k-1];
            int num = cnt[j][l] - cnt[j][k-1] - cnt[i-1][l] + cnt[i-1][k-1];
            if (pnt <= b) {
                ans = max(ans,num);
                l++;
            }
            else if (k == l)
                l++;
            else
                k++;
        }
    }
    cout << ans << endl;
    return 0;
}
0