結果

問題 No.866 レベルKの正方形
ユーザー betrue12betrue12
提出日時 2019-08-16 21:51:15
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 5,858 ms / 6,000 ms
コード長 976 bytes
コンパイル時間 1,409 ms
使用メモリ 417,804 KB
最終ジャッジ日時 2022-11-22 05:06:30
合計ジャッジ時間 75,492 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
3,648 KB
testcase_01 AC 1 ms
3,476 KB
testcase_02 AC 1 ms
3,632 KB
testcase_03 AC 1 ms
3,480 KB
testcase_04 AC 2 ms
3,644 KB
testcase_05 AC 2 ms
3,644 KB
testcase_06 AC 2 ms
3,648 KB
testcase_07 AC 1 ms
3,484 KB
testcase_08 AC 4,382 ms
417,688 KB
testcase_09 AC 4,312 ms
417,696 KB
testcase_10 AC 4,967 ms
417,768 KB
testcase_11 AC 5,048 ms
417,632 KB
testcase_12 AC 5,513 ms
417,804 KB
testcase_13 AC 5,007 ms
417,696 KB
testcase_14 AC 5,858 ms
417,624 KB
testcase_15 AC 4,811 ms
417,628 KB
testcase_16 AC 5,475 ms
417,780 KB
testcase_17 AC 4,959 ms
417,700 KB
testcase_18 AC 4,974 ms
417,620 KB
testcase_19 AC 5,714 ms
417,776 KB
testcase_20 AC 5,238 ms
417,688 KB
testcase_21 AC 5,558 ms
417,780 KB
testcase_22 AC 2 ms
3,452 KB
testcase_23 AC 2 ms
3,516 KB
testcase_24 AC 2 ms
3,560 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