結果

問題 No.866 レベルKの正方形
ユーザー vwxyzvwxyz
提出日時 2024-04-14 14:28:24
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,563 bytes
コンパイル時間 1,482 ms
コンパイル使用メモリ 114,804 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-04-14 14:29:01
合計ジャッジ時間 35,332 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3,022 ms
19,328 KB
testcase_09 AC 2,655 ms
19,328 KB
testcase_10 AC 2,278 ms
19,456 KB
testcase_11 AC 2,782 ms
19,328 KB
testcase_12 AC 2,055 ms
19,328 KB
testcase_13 AC 2,829 ms
19,456 KB
testcase_14 AC 1,837 ms
19,328 KB
testcase_15 AC 2,649 ms
19,456 KB
testcase_16 AC 2,353 ms
19,328 KB
testcase_17 AC 2,652 ms
19,328 KB
testcase_18 AC 2,656 ms
19,328 KB
testcase_19 AC 1,895 ms
19,328 KB
testcase_20 AC 1,415 ms
19,328 KB
testcase_21 WA -
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>

using namespace std;

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<int>> A(H, vector<int>(W));
    for (int h = 0; h < H; ++h) {
        string row;
        cin >> row;
        for (int w = 0; w < W; ++w) {
            A[h][w] = row[w] - 'a';
        }
    }
    const int inf = 1<<30;
    vector<int> dp(26 * W, inf);
    int ans = 0;
    for (int h = 0; h < H; ++h) {
        vector<int> prev = dp;
        fill(dp.begin(), dp.end(), inf);
        for (int w = 0; w < W; ++w) {
            for (int a = 0; a < 26; ++a) {
                if (A[h][w] == a) {
                    dp[a * W + w] = 0;
                }
                if (h > 0) {
                    dp[a * W + w] = min(dp[a * W + w], prev[a * W + w] + 1);
                }
                if (w > 0) {
                    dp[a * W + w] = min(dp[a * W + w], dp[a * W + w - 1] + 1);
                }
                if (h > 0 && w > 0) {
                    dp[a * W + w] = min(dp[a * W + w], prev[a * W + w - 1] + 1);
                }
            }
            vector<int> idx;
            for (int a = 0; a < 26; ++a) {
                if (dp[a * W + w] <= min(h, w)) {
                    idx.push_back(dp[a * W + w]);
                }
            }
            idx.push_back(min(h, w) + 1);
            if (idx.size() > K) {
                sort(idx.begin(), idx.end());
                ans += idx[K] - idx[K - 1];
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0