結果

問題 No.866 レベルKの正方形
ユーザー okok
提出日時 2019-08-18 20:07:49
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 2,189 bytes
コンパイル時間 1,096 ms
コンパイル使用メモリ 89,888 KB
実行使用メモリ 544,204 KB
最終ジャッジ日時 2023-07-24 18:57:42
合計ジャッジ時間 9,444 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 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<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

// #define int short
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

const int NUM = 26;
int H, W, K;

int check(vector<vector<vector<int>>> & con, int y, int x, int sz){
	int level = 0;
	
	sz--;
	
	if(sz < 0) return 0;
	if(sz + y >= H || sz + x >= W) return NUM+1;
	
	int y2 = y + sz, x2 = x + sz;
	
	for(int i = 0; i < NUM; i++){
		int sum = con[y2+1][x2+1][i] - con[y2+1][x][i] - con[y][x2+1][i] + con[y][x][i];
		
		level += !!sum;
	}
	
	return level;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	long long ans = 0;
	
	vector<string> squares;
	vector<vector<vector<int>>> con;
	
	cin>>H>>W>>K;
	
	
	con.resize(H+2, vector<vector<int>>(W+2, vector<int>(NUM, 0)));
	squares.resize(H);
	
	for(int i = 0; i < H; i++){
		cin>>squares[i];
		for(int j = 0; j < W; j++){
			con[i+1][j+1][squares[i][j] - 'a']++;
		}
	}
	
	for(int k = 0; k < NUM; k++){
		for(int i = 0; i <= H; i++){
			for(int j = 0; j <= W; j++){
				con[i][j+1][k] += con[i][j][k];
				// con[i+1][j][k] += con[i][j][k];
				if(i) con[i][j][k] += con[i-1][j][k];
			}
		}
	}
	// for(int k = 0; k < NUM; k++){
		// for(int i = 0; i <= H; i++){
			// for(int j = 0; j <= W; j++){
				// con[i+1][j][k] += con[i][j][k];
			// }
		// }
	// }
	
	// while(true){
		// int a, b, c;
		// cin>>a>>b>>c;
		
		// cout<<check(con, a, b, c)<<endl;
	// }
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			int h = min(H-i, W-j) + 1, l = 0, m;
			int a, b;
			
			while(l + 1 < h){
				m = (l + h)/2;
				
				if(check(con,i,j,m) > K){
					h = m;
				} else {
					l = m;
				}
			}
			
			a = h;
			
			h = min(H-i, W-j) + 1, l = 0;
			
			while(l + 1 < h){
				m = (l + h)/2;
				
				if(!(check(con,i,j,m) < K)){
					h = m;
				} else {
					l = m;
				}
			}
			
			b = l;
			
			// cout<<"i = "<<i<<" j = "<<j<<" a = "<<a<<" b = "<<b<<endl;
			ans += a - b - 1;
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}
0