結果

問題 No.866 レベルKの正方形
ユーザー noisy_noiminnoisy_noimin
提出日時 2019-08-17 14:32:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,547 bytes
コンパイル時間 593 ms
コンパイル使用メモリ 69,452 KB
実行使用メモリ 814,264 KB
最終ジャッジ日時 2023-10-25 00:25:33
合計ジャッジ時間 2,682 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 MLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>

using namespace std;

using ll = long long;

int h,w,k;
ll counts[2001][2001][26];

inline int count_level(int i, int j, int r) {
    int level = 0;
    for(int k=0;k<26;++k) {
        if(counts[i+r-1][j+r-1][k] - counts[i+r-1][j-1][k] - counts[i-1][j+r-1][k] + counts[i-1][j-1][k] > 0) {
            ++level;
        }
    }
    return level;
}

inline ll binary_search(int i, int j, int k) {
    ll ok = 0, ng = min(h-i, w-j) + 1;
    // ok: 半径 ok のとき level <= k;
    // ng: 半径 ng のとき level > k;
    while(ng-ok > 1) {
        ll r = (ok+ng) / 2;
        int level = count_level(i, j, r);
        if(level > k) {
            ng = r;
        } else {
            ok = r;
        }
    }
    return ok;
}

int main() {
    std::ios::sync_with_stdio(false); cin.tie(0);
    cin >> h >> w >> k;

    char c;
    fill_n(counts[0][0], (h+1)*(w+1)*26, 0);
    for(int i=1;i<=h;++i) {
        for(int j=1;j<=w;++j) {
            for(int k=0;k<26;++k) {
                counts[i][j][k] = counts[i-1][j][k] + counts[i][j-1][k] - counts[i-1][j-1][k];
            }
            cin >> c;
            ++counts[i][j][c-'a'];
        }
    }

    ll ans = 0;
    for(int i=1;i<=h;++i) {
        for(int j=1;j<=w;++j) {
            ll max_r_k = binary_search(i, j, k);
            ll max_r_k1 = binary_search(i, j, k-1);

            ans += max(0LL, max_r_k-max_r_k1);
            // cerr << i << "," << j << ": " << max_r_k << " " << max_r_k1 << endl;
        }
    }

    cout << ans << endl;
}
0