結果

問題 No.866 レベルKの正方形
ユーザー noisy_noiminnoisy_noimin
提出日時 2019-08-18 14:33:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,108 bytes
コンパイル時間 867 ms
コンパイル使用メモリ 71,012 KB
実行使用メモリ 441,580 KB
最終ジャッジ日時 2024-04-09 02:13:19
合計ジャッジ時間 29,453 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
426,072 KB
testcase_01 AC 125 ms
427,080 KB
testcase_02 AC 124 ms
426,072 KB
testcase_03 AC 124 ms
426,040 KB
testcase_04 AC 123 ms
427,784 KB
testcase_05 AC 125 ms
426,408 KB
testcase_06 AC 125 ms
427,636 KB
testcase_07 AC 126 ms
427,152 KB
testcase_08 AC 2,122 ms
441,448 KB
testcase_09 AC 1,627 ms
441,444 KB
testcase_10 AC 1,416 ms
441,576 KB
testcase_11 AC 2,032 ms
441,580 KB
testcase_12 AC 1,693 ms
441,576 KB
testcase_13 AC 2,090 ms
441,444 KB
testcase_14 WA -
testcase_15 AC 1,976 ms
441,448 KB
testcase_16 AC 1,901 ms
441,452 KB
testcase_17 AC 1,753 ms
441,572 KB
testcase_18 AC 2,000 ms
441,448 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 807 ms
441,452 KB
testcase_22 AC 127 ms
426,300 KB
testcase_23 AC 124 ms
426,512 KB
testcase_24 AC 126 ms
428,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>

using namespace std;

using ll = long long;

int h,w,k;
int a[2000][2000], r[2001][2001][27];

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

    char c;
    for(int i=0;i<h;++i) {
        for(int j=0;j<w;++j) {
            cin >> c;
            a[i][j] = int(c - 'a');
        }
    }
    fill_n(r[0][0], 2001*2001*27, 1);
    for(int i=h-1;i>=0;--i) {
        for(int j=w-1;j>=0;--j) {
            for(int ci=0;ci<26;++ci) {
                if(a[i][j] == ci) {
                    r[i][j][ci] = 1;
                } else {
                    r[i][j][ci] = min(min(h-i, w-j) + 1, min({r[i+1][j][ci], r[i][j+1][ci], r[i+1][j+1][ci]}) + 1);
                }
            }
        }
    }

    ll ans = 0;
    for(int i=0;i<h;++i) {
        for(int j=0;j<w;++j) {
            sort(r[i][j], r[i][j]+26);
            if(r[i][j][k-1] == 1<<30) continue;
            if(r[i][j][k] == 1<<30) {
                ans += min(h-i, w-j) + 1 - r[i][j][k-1];
            } else {
                ans += r[i][j][k] - r[i][j][k-1];
            }
        }
    }

    cout << ans << endl;
}
0