結果

問題 No.866 レベルKの正方形
ユーザー leaf_1415leaf_1415
提出日時 2019-08-22 03:54:44
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,396 bytes
コンパイル時間 1,385 ms
コンパイル使用メモリ 66,080 KB
実行使用メモリ 450,876 KB
最終ジャッジ日時 2023-08-01 09:13:55
合計ジャッジ時間 9,952 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,668 KB
testcase_01 AC 2 ms
7,536 KB
testcase_02 AC 2 ms
7,564 KB
testcase_03 AC 3 ms
7,748 KB
testcase_04 AC 2 ms
7,716 KB
testcase_05 AC 3 ms
7,532 KB
testcase_06 AC 3 ms
7,596 KB
testcase_07 AC 2 ms
7,544 KB
testcase_08 TLE -
testcase_09 AC 5,964 ms
447,040 KB
testcase_10 AC 5,731 ms
446,744 KB
testcase_11 TLE -
testcase_12 AC 5,937 ms
446,736 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 4,102 ms
446,784 KB
testcase_22 AC 3 ms
7,492 KB
testcase_23 AC 3 ms
7,668 KB
testcase_24 AC 4 ms
9,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#define llint long long
#define inf 1000000000

using namespace std;

int h, w, k;
int sum[2005][2005];
char c[2005][2005];
int dp[2005][2005];
int vec[2005][2005][26];

int get(int x, int y, int k)
{
	return sum[x+k][y+k]-sum[x+k][y-1]-sum[x-1][y+k]+sum[x-1][y-1];
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> h >> w >> k;
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			cin >> c[x][y];
		}
	}
	
	for(int x = 1; x <= w+1; x++) dp[x][h+1] = inf;
	for(int y = 1; y <= h+1; y++) dp[w+1][y] = inf;
	
	for(int i = 0; i < 26; i++){
		for(int x = 1; x <= w; x++){
			for(int y = 1; y <= h; y++){
				sum[x][y] = sum[x-1][y]+sum[x][y-1]-sum[x-1][y-1];
				if(c[x][y] == i+'a') sum[x][y]++;
			}
		}
		for(int y = h; y >= 1; y--){
			for(int x = w; x >= 1; x--){
				dp[x][y] = min(dp[x+1][y], dp[x][y+1]);
				if(c[x][y] == i+'a') dp[x][y] = 0;
				if(dp[x][y] <= min(w-x, h-y)){
					if(get(x, y, dp[x][y]) == 0) dp[x][y]++;
				}
				vec[x][y][i] = dp[x][y];
			}
		}
	}
	
	llint ans = 0;
	for(int x = 1; x <= w; x++){
		for(int y = 1; y <= h; y++){
			sort(vec[x][y], vec[x][y]+26);
			if(vec[x][y][k-1] >= inf) continue;
			if(k >= 26 || vec[x][y][k] >= inf) ans += min(w-x, h-y)+1;
			else ans += vec[x][y][k];
			ans -= vec[x][y][k-1];
		}
	}
	cout << ans << endl;
	
	return 0;
}
0