結果

問題 No.866 レベルKの正方形
ユーザー mencottonmencotton
提出日時 2019-08-16 22:47:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,854 bytes
コンパイル時間 814 ms
コンパイル使用メモリ 80,108 KB
実行使用メモリ 547,464 KB
最終ジャッジ日時 2023-10-24 02:22:21
合計ジャッジ時間 20,679 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 MLE -
testcase_09 TLE -
testcase_10 MLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int wanted;
vector<vector<vector<int>>> c_sum;

int bin_lower(int x, int y, int max_size) {
    int ng = 0;
    int ok = max_size + 1;

    while (abs(ok - ng) > 1) {
        int mid = ng + (ok - ng) / 2;

        int count = 0;
        for (int i = 0; i < 26; i++) {
            if (c_sum[x + mid][y + mid][i] - c_sum[x + mid][y][i] - c_sum[x][y + mid][i] + c_sum[x][y][i] > 0)count++;
        }
        if (count >= wanted)ok = mid;
        else ng = mid;
    }

    return ok;
}

int bin_upper(int x, int y, int max_size) {
    int ng = 0;
    int ok = max_size + 1;

    while (abs(ok - ng) > 1) {
        int mid = ng + (ok - ng) / 2;

        int count = 0;
        for (int i = 0; i < 26; i++) {
            if (c_sum[x + mid][y + mid][i] - c_sum[x + mid][y][i] - c_sum[x][y + mid][i] + c_sum[x][y][i] > 0)count++;
        }
        if (count > wanted)ok = mid;
        else ng = mid;
    }

    return ok;
}

int main() {
    int h, w;
    cin >> h >> w >> wanted;
    vector<string> ban(h);
    for (int i = 0; i < h; i++)cin >> ban[i];

    c_sum = vector<vector<vector<int>>>(h + 1, vector<vector<int>>(w + 1, vector<int>(26)));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int c = 0; c < 26; c++) {
                c_sum[i + 1][j + 1][c] =
                        c_sum[i + 1][j][c] + c_sum[i][j + 1][c] - c_sum[i][j][c] + (ban[i][j] - 'a' == c ? 1 : 0);
            }
        }
    }

    int ret = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int max_size = min(h - i, w - j);
            int x = bin_upper(i, j, max_size);
            int y = bin_lower(i, j, max_size);
            ret += x - y;
        }
    }

    cout << ret << endl;
    return 0;
}
0