結果

問題 No.866 レベルKの正方形
ユーザー betrue12betrue12
提出日時 2019-08-16 22:09:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,534 ms / 6,000 ms
コード長 1,262 bytes
コンパイル時間 1,607 ms
コンパイル使用メモリ 169,968 KB
実行使用メモリ 417,956 KB
最終ジャッジ日時 2023-10-23 23:56:31
合計ジャッジ時間 22,177 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,768 KB
testcase_01 AC 3 ms
5,768 KB
testcase_02 AC 2 ms
5,768 KB
testcase_03 AC 2 ms
5,768 KB
testcase_04 AC 3 ms
5,768 KB
testcase_05 AC 2 ms
5,768 KB
testcase_06 AC 2 ms
5,768 KB
testcase_07 AC 2 ms
5,768 KB
testcase_08 AC 1,529 ms
417,952 KB
testcase_09 AC 1,418 ms
417,956 KB
testcase_10 AC 1,534 ms
417,956 KB
testcase_11 AC 1,472 ms
417,956 KB
testcase_12 AC 1,208 ms
417,956 KB
testcase_13 AC 1,485 ms
417,956 KB
testcase_14 AC 1,147 ms
417,956 KB
testcase_15 AC 1,485 ms
417,956 KB
testcase_16 AC 1,413 ms
417,956 KB
testcase_17 AC 1,483 ms
417,956 KB
testcase_18 AC 1,468 ms
417,956 KB
testcase_19 AC 1,087 ms
417,956 KB
testcase_20 AC 966 ms
417,956 KB
testcase_21 AC 1,087 ms
417,956 KB
testcase_22 AC 2 ms
5,764 KB
testcase_23 AC 2 ms
5,764 KB
testcase_24 AC 3 ms
7,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int H, W, K;
static int sum[2001][2001][26];

int calc(int si, int sj, int P){
    int r = 0;
    int ans = 0;
    for(int l=0; ; l++){
        int i = si+l, j = sj+l;
        if(i >= H || j >= W) break;
        while(r < l) r++;
        while(true){
            int d = r-l;
            if(i+d > H || j+d > W) break;
            int num = 0;
            for(int k=0; k<26; k++) if(sum[i][j][k] + sum[i+d][j+d][k] - sum[i+d][j][k] - sum[i][j+d][k] > 0) num++;
            if(num <= P){
                r++;
            }else{
                break;
            }
        }
        ans += r-l;
    }
    return ans;
}

int main(){
    
    cin >> H >> W >> K;
    string S[2000];
    for(int i=0;i<H; i++) cin >> S[i];
    for(int i=0; i<H; i++) for(int j=0; j<W; j++) sum[i+1][j+1][S[i][j]-'a']++;
    for(int i=1; i<=H; i++) for(int j=0; j<=W; j++) for(int k=0; k<26; k++) sum[i][j][k] += sum[i-1][j][k];
    for(int i=0; i<=H; i++) for(int j=1; j<=W; j++) for(int k=0; k<26; k++) sum[i][j][k] += sum[i][j-1][k];
    
    int64_t ans = 0;
    for(int j=0; j<W; j++) ans += calc(0, j, K) - calc(0, j, K-1);
    for(int i=1; i<H; i++) ans += calc(i, 0, K) - calc(i, 0, K-1);
    cout << ans << endl;
    return 0;
}
0