結果

問題 No.866 レベルKの正方形
ユーザー IKyoproIKyopro
提出日時 2019-08-17 00:11:52
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,456 bytes
コンパイル時間 670 ms
コンパイル使用メモリ 70,584 KB
実行使用メモリ 543,776 KB
最終ジャッジ日時 2023-10-24 12:38:40
合計ジャッジ時間 9,312 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 MLE -
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 <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    int H,W,K;
    cin >> H >> W >> K;
    vector<vector<char>> F(H+1,vector<char>(W+1));
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) cin >> F[i][j];
    vector<vector<vector<int>>> sum(H+1,vector<vector<int>>(W+1,vector<int>(26,0)));
    for(char c='a';c<='z';c++){
        for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) if(F[i][j]==c){
            sum[i][j][c-'a']++;            
        }
        for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) sum[i][j][c-'a'] += sum[i][j-1][c-'a'];
        for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) sum[i][j][c-'a'] += sum[i-1][j][c-'a'];
    }
    ll ans = 0;
    auto exist = [&](int x1,int y1,int x2,int y2,int c){
        return sum[x2][y2][c]-sum[x1-1][y2][c]-sum[x2][y1-1][c]+sum[x1-1][y1-1][c]>=1;
    };
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++){
        ll l1 = 1,r1 = min(H-i+1,W-j+1)+1;
        while(l1+1<r1){
            ll m = (l1+r1)/2;
            int cnt = 0;
            for(int k=0;k<26;k++) cnt += exist(i,j,i+m-1,j+m-1,k);
            if(cnt<=K) l1 = m;
            else r1 = m;
        }
        ll l2 = 0,r2 = min(H-i+1,W-j+1)+1;
        while(l2+1<r2){
            ll m = (l2+r2)/2;
            int cnt = 0;
            for(int k=0;k<26;k++) cnt += exist(i,j,i+m-1,j+m-1,k);
            if(cnt<K) l2 = m;
            else r2 = m;
        }
        ans += l1-l2;
    }
    cout << ans << endl;
}
0