結果

問題 No.165 四角で囲え!
ユーザー xuzijian629xuzijian629
提出日時 2018-10-10 19:16:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 337 ms / 5,000 ms
コード長 2,408 bytes
コンパイル時間 1,459 ms
コンパイル使用メモリ 179,040 KB
実行使用メモリ 16,128 KB
最終ジャッジ日時 2024-04-20 19:28:24
合計ジャッジ時間 4,714 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
11,648 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 197 ms
12,800 KB
testcase_06 AC 51 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 88 ms
8,960 KB
testcase_12 AC 41 ms
6,944 KB
testcase_13 AC 42 ms
6,944 KB
testcase_14 AC 30 ms
6,940 KB
testcase_15 AC 30 ms
6,940 KB
testcase_16 AC 250 ms
15,616 KB
testcase_17 AC 232 ms
15,872 KB
testcase_18 AC 337 ms
16,128 KB
testcase_19 AC 250 ms
16,000 KB
testcase_20 AC 223 ms
16,000 KB
testcase_21 AC 226 ms
16,128 KB
testcase_22 AC 229 ms
16,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
using ii = pair<int, i64>;

map<i64, i64> compX, compY, extX, extY;
map<ii, i64> point;
vvi board, boardp;

// all inclusive
i64 pointsum(int i0, int i1, int j0, int j1) {
    i0++;
    i1++;
    j0++;
    j1++;
    return board[i1][j1] - board[i1][j0 - 1] - board[i0 - 1][j1] + board[i0 - 1][j0 - 1];
}

i64 pointnum(int i0, int i1, int j0, int j1) {
    i0++;
    i1++;
    j0++;
    j1++;
    return boardp[i1][j1] - boardp[i1][j0 - 1] - boardp[i0 - 1][j1] + boardp[i0 - 1][j0 - 1];
}

int main() {
    int n, b;
    cin >> n >> b;
    
    for (int i = 0; i < n; i++) {
        i64 x, y, p;
        cin >> x >> y >> p;
        
        compX[x] = compY[y] = 0;
        point[ii(x, y)] = p;
    }
    
    int k = 0;
    for (auto& p: compX) {
        p.second = k++;
        extX[p.second] = p.first;
    }
    k = 0;
    for (auto& p: compY) {
        p.second = k++;
        extY[p.second] = p.first;
    }
    
    int X = compX.size(), Y = compY.size();
    board = vvi(X + 1, vi(Y + 1));
    boardp = vvi(X + 1, vi(Y + 1));
    for (int i = 0; i < X; i++) {
        for (int j = 0; j < Y; j++) {
            board[i + 1][j + 1] = point[ii(extX[i], extY[j])];
            boardp[i + 1][j + 1] = point[ii(extX[i], extY[j])] > 0;
        }
    }
    
    for (int i = 0; i <= X; i++) {
        for (int j = 0; j < Y; j++) {
            board[i][j + 1] += board[i][j];
            boardp[i][j + 1] += boardp[i][j];
        }
    }
    
    for (int j = 0; j <= Y; j++) {
        for (int i = 0; i < X; i++) {
            board[i + 1][j] += board[i][j];
            boardp[i + 1][j] += boardp[i][j];
        }
    }
    
    i64 ans = 0;
    for (int i = 0; i < X; i++) {
        for (int j = i; j < X; j++) {
            i64 sum = 0;
            int l = 0, r = 0;
            while (1) {
                if (sum <= b) {
                    sum += pointsum(i, j, r, r);
                    if (sum <= b) {
                        ans = max(ans, pointnum(i, j, l, r));
                    }
                    r++;
                    if (r == Y) {
                        break;
                    }
                } if (sum > b) {
                    sum -= pointsum(i, j, l, l);
                    l++;
                }
            }
        }
    }
    
    cout << ans << endl;
}
0