結果

問題 No.866 レベルKの正方形
ユーザー Kiona1018Kiona1018
提出日時 2019-09-14 13:56:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,884 ms / 6,000 ms
コード長 2,250 bytes
コンパイル時間 2,028 ms
コンパイル使用メモリ 173,312 KB
実行使用メモリ 417,892 KB
最終ジャッジ日時 2023-09-19 09:48:20
合計ジャッジ時間 51,311 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3,346 ms
417,688 KB
testcase_09 AC 3,307 ms
417,572 KB
testcase_10 AC 3,019 ms
417,680 KB
testcase_11 AC 3,467 ms
417,548 KB
testcase_12 AC 3,144 ms
417,672 KB
testcase_13 AC 3,884 ms
417,892 KB
testcase_14 AC 3,455 ms
417,612 KB
testcase_15 AC 3,299 ms
417,624 KB
testcase_16 AC 3,296 ms
417,668 KB
testcase_17 AC 3,283 ms
417,748 KB
testcase_18 AC 3,683 ms
417,612 KB
testcase_19 AC 3,380 ms
417,560 KB
testcase_20 AC 2,976 ms
417,612 KB
testcase_21 AC 1,855 ms
417,696 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
const int INF = 1000000000;

int main()
{
    int h, w, k;
    cin >> h >> w >> k;

    string table[h];
    rep(i, 0, h)
        cin >> table[i];

    int dis[26][h+1][w+1];
    rep(c,0, 26)
        rep(i, 0, h + 1)
            rep(j, 0, w + 1)
                dis[c][i][j] = INF;

    rep(c, 0, 26)
    {
        char color = c + 'a';

        rrep(i, h, 0)
            rrep(j, w, 0)
            {
                if (table[i][j] == color)
                    dis[c][i][j] = 1;
                else
                {
                    int max_k = min(h-i, w-j);
                    if (dis[c][i+1][j] + 1 <= max_k)
                        dis[c][i][j] = min(dis[c][i][j], dis[c][i+1][j] + 1);
                    if (dis[c][i][j+1] + 1 <= max_k)
                        dis[c][i][j] = min(dis[c][i][j], dis[c][i][j+1] + 1);
                    if (dis[c][i+1][j+1] + 1 <= max_k)
                        dis[c][i][j] = min(dis[c][i][j], dis[c][i+1][j+1] + 1);
                }
                // if (color == 'd')
                //     cout << i << ' ' << j << ' ' << dis[c][i][j] << endl;
            }
    }

    ll ans = 0;
    rep(i, 0, h)
        rep(j, 0, w)
        {
            vector<int> nums;
            int max_k = min(h-i, w-j) + 1;
            nums.push_back(max_k);
            rep(c, 0, 26)
            {
                if (dis[c][i][j] == INF)
                    nums.push_back(max_k);
                else
                    nums.push_back(dis[c][i][j]);
            }
            sort(nums.begin(), nums.end());

            // rep(c, 0, 26)
            //     cout << nums[c] << " ";
            // cout << endl;
            // cout << "**********" << endl;
            // cout <<i << ' ' << j << ' ' <<  nums[k] << ' ' << nums[k-1] << endl;

            if (nums[k - 1] == INF) continue;
            if (nums[k] == INF)
                nums[k] = min(h - i, w - i);

            // cout <<i << ' ' << j << ' ' <<  nums[k] << ' ' << nums[k-1] << endl;
            ans += (ll) nums[k] - nums[k - 1];
        }
    cout << ans << endl;
    return 0;
}
0