結果

問題 No.866 レベルKの正方形
ユーザー okok
提出日時 2020-07-11 09:19:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3,851 ms / 6,000 ms
コード長 1,667 bytes
コンパイル時間 867 ms
コンパイル使用メモリ 81,312 KB
実行使用メモリ 415,072 KB
最終ジャッジ日時 2023-08-02 18:41:31
合計ジャッジ時間 54,118 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,748 KB
testcase_01 AC 2 ms
5,512 KB
testcase_02 AC 2 ms
5,784 KB
testcase_03 AC 2 ms
5,612 KB
testcase_04 AC 3 ms
5,520 KB
testcase_05 AC 3 ms
5,540 KB
testcase_06 AC 2 ms
5,804 KB
testcase_07 AC 2 ms
5,680 KB
testcase_08 AC 2,941 ms
414,908 KB
testcase_09 AC 2,954 ms
415,064 KB
testcase_10 AC 3,603 ms
415,072 KB
testcase_11 AC 3,651 ms
415,020 KB
testcase_12 AC 3,729 ms
414,916 KB
testcase_13 AC 3,677 ms
414,960 KB
testcase_14 AC 3,826 ms
414,936 KB
testcase_15 AC 3,422 ms
414,920 KB
testcase_16 AC 3,851 ms
414,992 KB
testcase_17 AC 3,465 ms
414,908 KB
testcase_18 AC 3,650 ms
414,932 KB
testcase_19 AC 3,650 ms
415,036 KB
testcase_20 AC 3,556 ms
414,956 KB
testcase_21 AC 3,606 ms
414,928 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 2 ms
7,556 KB
権限があれば一括ダウンロードができます

ソースコード

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 con[2005][2005][26];
string squares[2000];

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

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	// cout<<fixed<<setprecision(10);
	
	long long ans = 0;
	
	
	cin>>H>>W>>K;
	
	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];
				if(i) con[i][j][k] += con[i-1][j][k];
			}
		}
	}
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			int minimum = (H-i < W-j)?H-i:W-j;
			
			int h = minimum + 1, l = 0, m, a;
			
			while(l + 1 < h){
				m = (l + h)/2;
				
				if(check(i,j,m) > K){
					h = m;
				} else {
					l = m;
				}
			}
			
			a = h;
			
			h = minimum + 1, l = 0;
			
			while(l + 1 < h){
				m = (l + h)/2;
				
				if(!(check(i,j,m) < K)){
					h = m;
				} else {
					l = m;
				}
			}
			
			ans += a - l - 1;
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}
0