結果

問題 No.866 レベルKの正方形
ユーザー IKyoproIKyopro
提出日時 2019-08-17 11:54:00
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,400 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 70,580 KB
実行使用メモリ 435,920 KB
最終ジャッジ日時 2023-10-25 00:06:15
合計ジャッジ時間 9,687 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 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 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 TLE -
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(26,vector<vector<int>>(H+1,vector<int>(W+1,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[c-'a'][i][j]++;            
        }
        for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) sum[c-'a'][i][j] += sum[c-'a'][i][j-1];
        for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) sum[c-'a'][i][j] += sum[c-'a'][i-1][j];
    }
    ll ans = 0;
    auto calc = [&](int x1,int y1,int x2,int y2){
        int res = 0;
        for(int c=0;c<26;c++) res += sum[c][x2][y2]-sum[c][x1-1][y2]-sum[c][x2][y1-1]+sum[c][x1-1][y1-1]>=1;
        return res;
    };
    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;
            if(calc(i,j,i+m-1,j+m-1)<=K) l1 = m;
            else r1 = m;
        }
        ll l2 = 0,r2 = l1+1;
        while(l2+1<r2){
            ll m = (l2+r2)/2;
            int cnt = 0;
            if(calc(i,j,i+m-1,j+m-1)<K) l2 = m;
            else r2 = m;
        }
        ans += l1-l2;
    }
    cout << ans << endl;
}
0