結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,736 KB
testcase_01 AC 2 ms
5,460 KB
testcase_02 AC 2 ms
5,468 KB
testcase_03 AC 2 ms
5,596 KB
testcase_04 AC 2 ms
5,468 KB
testcase_05 AC 2 ms
5,532 KB
testcase_06 AC 2 ms
5,468 KB
testcase_07 AC 2 ms
5,660 KB
testcase_08 AC 1,838 ms
425,868 KB
testcase_09 AC 1,564 ms
425,792 KB
testcase_10 AC 1,383 ms
425,940 KB
testcase_11 AC 1,977 ms
425,732 KB
testcase_12 AC 1,521 ms
425,672 KB
testcase_13 AC 1,897 ms
425,792 KB
testcase_14 AC 1,614 ms
425,736 KB
testcase_15 AC 1,639 ms
425,872 KB
testcase_16 AC 1,761 ms
425,868 KB
testcase_17 AC 1,648 ms
425,992 KB
testcase_18 AC 1,687 ms
425,732 KB
testcase_19 AC 1,971 ms
425,728 KB
testcase_20 AC 1,733 ms
425,672 KB
testcase_21 AC 696 ms
425,664 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,352 KB
testcase_24 AC 3 ms
7,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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