結果

問題 No.866 レベルKの正方形
ユーザー MisterMister
提出日時 2020-08-05 02:45:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,366 bytes
コンパイル時間 2,026 ms
コンパイル使用メモリ 86,156 KB
実行使用メモリ 598,112 KB
最終ジャッジ日時 2023-10-13 06:57:48
合計ジャッジ時間 37,506 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

using lint = long long;

constexpr int INF = 1 << 30;

void solve() {
    int h, w, k;
    std::cin >> h >> w >> k;

    auto dss = vec(h + 1, vec(w + 1, vec(27, INF)));
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            char c;
            std::cin >> c;
            dss[i][j][c - 'a'] = 0;

            for (int d = 0; d < 27; ++d) {
                dss[i][j][d] = std::min(dss[i][j][d],
                                        std::min({dss[i - 1][j][d],
                                                  dss[i][j - 1][d],
                                                  dss[i - 1][j - 1][d]}) +
                                            1);
            }
        }
    }

    lint ans = 0;
    for (int rx = 1; rx <= h; ++rx) {
        for (int ry = 1; ry <= w; ++ry) {
            auto& ds = dss[rx][ry];
            std::sort(ds.begin(), ds.end());

            int l = std::min(ds[k - 1], std::min(rx, ry));
            int r = std::min(ds[k], std::min(rx, ry));
            ans += r - l;
        }
    }

    std::cout << ans << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0