結果

問題 No.866 レベルKの正方形
ユーザー 沙耶花沙耶花
提出日時 2019-08-16 22:28:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,530 bytes
コンパイル時間 2,212 ms
コンパイル使用メモリ 172,344 KB
実行使用メモリ 421,304 KB
最終ジャッジ日時 2023-10-24 01:23:57
合計ジャッジ時間 10,163 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,696 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 2 ms
4,348 KB
testcase_06 AC 2 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 <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	int H,W,K;
	cin>>H>>W>>K;
	
	vector<string> S(H);
	
	for(int i=0;i<H;i++){
		cin>>S[i];
	}
	
	int sum[26][H+1][W+1];
	
	for(int i=0;i<26;i++){
		for(int j=0;j<H+1;j++){
			for(int k=0;k<W+1;k++){
				sum[i][j][k]=0;
			}
		}
	}
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			int k = (int)S[i][j]-'a';
			sum[k][i+1][j+1]++;
		}
	}
	
	for(int i=0;i<26;i++){
		for(int j=1;j<=H;j++){
			for(int k=0;k<=W;k++){
				sum[i][j][k] += sum[i][j-1][k];
			}
		}
		
		for(int j=0;j<=H;j++){
			for(int k=1;k<=W;k++){
				sum[i][j][k] += sum[i][j][k-1];
			}
		}
	
	}
	
	long long ans = 0;
	
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			int ok1 = min(H-i+1,W-j+1);
			int ng1 = -1;
			while(ok1-ng1>1){
				int cnt = 0;
				int mid = (ok1+ng1)/2;
				for(int k=0;k<26;k++){
					int x = sum[k][i+mid][j+mid]+sum[k][i-1][j-1]-sum[k][i+mid][j-1]-sum[k][i-1][j+mid];
					if(x>0)cnt++;
				}
				if(cnt>K)ok1=mid;
				else ng1=mid;
			}
			
			int ok2 = -1;
			int ng2 = min(H-i+1,W-j+1);
			while(ng2-ok2>1){
				int cnt = 0;
				int mid = (ok2+ng2)/2;
				for(int k=0;k<26;k++){
					int x = sum[k][i+mid][j+mid]+sum[k][i-1][j-1]-sum[k][i+mid][j-1]-sum[k][i-1][j+mid];
					if(x>0)cnt++;
				}
				if(cnt<K)ok2=mid;
				else ng2=mid;
			}
			ok2++;
			ok1--;
			if(ok1<ok2)continue;
			ans += ok1-ok2+1;
			
			
			
		}
	}
	cout<<ans<<endl;
	
	return 0;
}
0