結果

問題 No.866 レベルKの正方形
ユーザー MisterMister
提出日時 2020-08-05 02:48:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,973 ms / 6,000 ms
コード長 1,409 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 75,224 KB
実行使用メモリ 425,936 KB
最終ジャッジ日時 2023-10-13 07:05:07
合計ジャッジ時間 25,216 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,464 KB
testcase_01 AC 2 ms
5,540 KB
testcase_02 AC 2 ms
5,468 KB
testcase_03 AC 2 ms
5,472 KB
testcase_04 AC 2 ms
5,736 KB
testcase_05 AC 2 ms
5,528 KB
testcase_06 AC 2 ms
5,480 KB
testcase_07 AC 2 ms
5,668 KB
testcase_08 AC 1,842 ms
425,796 KB
testcase_09 AC 1,573 ms
425,668 KB
testcase_10 AC 1,379 ms
425,676 KB
testcase_11 AC 1,971 ms
425,872 KB
testcase_12 AC 1,529 ms
425,792 KB
testcase_13 AC 1,896 ms
425,724 KB
testcase_14 AC 1,609 ms
425,728 KB
testcase_15 AC 1,630 ms
425,740 KB
testcase_16 AC 1,760 ms
425,676 KB
testcase_17 AC 1,652 ms
425,936 KB
testcase_18 AC 1,696 ms
425,740 KB
testcase_19 AC 1,973 ms
425,872 KB
testcase_20 AC 1,727 ms
425,664 KB
testcase_21 AC 693 ms
425,796 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,352 KB
testcase_24 AC 3 ms
7,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>

using lint = long long;

constexpr int N = 2000;
int dss[N + 1][N + 1][27];

constexpr int INF = 1 << 30;

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

    for (int i = 0; i <= h; ++i) {
        for (int j = 0; j <= w; ++j) {
            for (int d = 0; d < 27; ++d) {
                dss[i][j][d] = 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, ds + 27);

            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