結果

問題 No.866 レベルKの正方形
ユーザー totori_nyaatotori_nyaa
提出日時 2019-12-30 22:41:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,057 bytes
コンパイル時間 1,343 ms
コンパイル使用メモリ 168,972 KB
実行使用メモリ 414,080 KB
最終ジャッジ日時 2024-04-27 16:38:35
合計ジャッジ時間 39,345 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2,642 ms
414,080 KB
testcase_09 AC 2,704 ms
413,952 KB
testcase_10 AC 2,969 ms
414,060 KB
testcase_11 AC 3,147 ms
413,988 KB
testcase_12 AC 2,526 ms
414,080 KB
testcase_13 AC 3,058 ms
414,080 KB
testcase_14 AC 1,920 ms
413,952 KB
testcase_15 AC 2,938 ms
413,952 KB
testcase_16 AC 2,900 ms
413,952 KB
testcase_17 AC 3,021 ms
413,920 KB
testcase_18 AC 2,989 ms
413,952 KB
testcase_19 AC 1,717 ms
413,952 KB
testcase_20 AC 725 ms
413,952 KB
testcase_21 WA -
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int c[2001][2001][26];

signed main(){
    ios::sync_with_stdio(false);
	// cin.tie(0);
    // cout << fixed << setprecision(20);

    int h,w,n;
    scanf("%d %d %d",&h,&w,&n);
    char s[h][w];
    for(int i=0;i<h;i++){
        scanf("%s",s[i]);
        for(int j=0;j<w;j++){
            //cerr << s[i][j];
            c[i+1][j+1][s[i][j]-'a']++;
            for(int k=0;k<26;k++){
                c[i+1][j+1][k] += c[i+1][j][k];
            }
        }
        //cerr << endl;
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int k=0;k<26;k++){
                c[i+1][j+1][k] += c[i][j+1][k];
            }
        }
    }

    ll ans = 0;

    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            int cnt=0;
            for(int k=0;k<26;k++){
                if(c[i][j][k] - c[i-min(i,j)][j][k] - c[i][j-min(i,j)][k] + c[i-min(i,j)][j-min(i,j)][k]) cnt++;
            }
            if(cnt<n) continue;
            int upper,lower;

            long long low=-1,up=min(i,j)+1,mid;
            while(up-low>1){
                mid=(up+low)/2;
                cnt = 0;
                for(int k=0;k<26;k++){
                    if(c[i][j][k] - c[i-mid][j][k] - c[i][j-mid][k] + c[i-mid][j-mid][k]>0) cnt++;
                }
                if(cnt<=n){
                    low=mid;
                }
                else{
                    up=mid;
                }
            }
            upper = low;

            low = -1, up = min(i,j)+1;
            while(up-low>1){
                mid=(up+low)/2;
                cnt = 0;
                for(int k=0;k<26;k++){
                    if(c[i][j][k] - c[i-mid][j][k] - c[i][j-mid][k] + c[i-mid][j-mid][k]>0) cnt++;
                }
                if(cnt<n){
                    low=mid;
                }
                else{
                    up=mid;
                }
            }
            lower = low;
            ans += upper - lower;
        }
    }
    printf("%d", ans);


}
0