結果

問題 No.866 レベルKの正方形
ユーザー betrue12betrue12
提出日時 2019-08-16 21:51:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3,375 ms / 6,000 ms
コード長 976 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 169,896 KB
実行使用メモリ 417,900 KB
最終ジャッジ日時 2023-10-23 22:43:09
合計ジャッジ時間 44,950 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,712 KB
testcase_01 AC 2 ms
5,712 KB
testcase_02 AC 2 ms
5,712 KB
testcase_03 AC 2 ms
5,712 KB
testcase_04 AC 2 ms
5,712 KB
testcase_05 AC 2 ms
5,712 KB
testcase_06 AC 2 ms
5,712 KB
testcase_07 AC 1 ms
5,712 KB
testcase_08 AC 2,443 ms
417,900 KB
testcase_09 AC 2,579 ms
417,900 KB
testcase_10 AC 2,845 ms
417,900 KB
testcase_11 AC 2,953 ms
417,900 KB
testcase_12 AC 3,222 ms
417,900 KB
testcase_13 AC 2,864 ms
417,900 KB
testcase_14 AC 3,375 ms
417,900 KB
testcase_15 AC 2,749 ms
417,900 KB
testcase_16 AC 3,206 ms
417,900 KB
testcase_17 AC 2,822 ms
417,900 KB
testcase_18 AC 2,860 ms
417,900 KB
testcase_19 AC 3,239 ms
417,900 KB
testcase_20 AC 2,952 ms
417,900 KB
testcase_21 AC 3,221 ms
417,900 KB
testcase_22 AC 3 ms
5,708 KB
testcase_23 AC 2 ms
5,708 KB
testcase_24 AC 3 ms
7,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

int calc(int i, int j, int P){
    int ok = 0;
    int ng = min(H-i, W-j) + 1;
    while(ng-ok>1){
        int mid = (ok+ng)/2;
        int num = 0;
        for(int k=0; k<26; k++) if(sum[i][j][k] + sum[i+mid][j+mid][k] - sum[i+mid][j][k] - sum[i][j+mid][k] > 0) num++;
        (num <= P ? ok : ng) = mid;
    }
    return ok;
}

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 i=0; i<H; i++) for(int j=0; j<W; j++) ans += calc(i, j, K) - calc(i, j, K-1);
    cout << ans << endl;
    return 0;
}
0