結果

問題 No.866 レベルKの正方形
ユーザー Y17Y17
提出日時 2019-08-17 00:21:42
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,608 bytes
コンパイル時間 2,505 ms
コンパイル使用メモリ 161,212 KB
実行使用メモリ 50,896 KB
最終ジャッジ日時 2023-10-24 13:14:10
合計ジャッジ時間 10,127 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
45,264 KB
testcase_01 AC 10 ms
46,900 KB
testcase_02 AC 9 ms
40,900 KB
testcase_03 AC 10 ms
50,896 KB
testcase_04 AC 10 ms
50,896 KB
testcase_05 AC 9 ms
44,900 KB
testcase_06 AC 10 ms
44,896 KB
testcase_07 AC 9 ms
42,900 KB
testcase_08 TLE -
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 <bits/stdc++.h>
using namespace std;

int rui[26][2010][2010] = {};
int h, w;
char c[2010][2010];

bool isOK(int i, int j, int ha, int num){

    int ans = 0;

    for(int x = 0;x < 26;x++){
        if(rui[x][i+ha+1][j+ha+1] - rui[x][i+ha+1][j] - rui[x][i][j+ha+1] + rui[x][i][j] > 0){
            ans++;
        }
    }

    return ans >= num;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int k;
    cin >> h >> w >> k;

    for(int i = 0;i < h;i++){
        cin >> c[i];
        for(int j = 0;j < w;j++){
            rui[c[i][j]-'a'][i+1][j+1] = 1;
        }
    }

    for(int x = 0;x < 26;x++){
        for(int i = 0;i <= h;i++){
            for(int j = 0;j <= w;j++){
                rui[x][i+1][j] += rui[x][i][j];
            }
        }
    }

    for(int x = 0;x < 26;x++){
        for(int i = 0;i <= h;i++){
            for(int j = 0;j <= w;j++){
                rui[x][i][j+1] += rui[x][i][j];
            }
        }
    }

    long long ans = 0;
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            int l, r;
            l = 0;
            r = min(h-i, w-j);

            while(r-l > 1){
                int mid = (l+r)/2;
                if(isOK(i, j, mid, k)) r = mid;
                else l = mid;
            }

            int l2, r2;
            l2 = 0;
            r2 = min(h-i, w-j);
            while(r2-l2 > 1){
                int mid = (l2+r2)/2;
                if(isOK(i, j, mid, k+1)) r2 = mid;
                else l2 = mid;

            }

            ans += l2-l;
        }
    }

    cout << ans << endl;
    return 0;
}
0