結果

問題 No.866 レベルKの正方形
ユーザー leaf_1415leaf_1415
提出日時 2019-08-22 03:28:15
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,415 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 67,220 KB
実行使用メモリ 322,560 KB
最終ジャッジ日時 2024-04-19 08:02:18
合計ジャッジ時間 9,897 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 34 ms
97,792 KB
testcase_07 AC 34 ms
97,920 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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |         scanf("%d %d %d", &w, &h, &k);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:25:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |                 scanf("%s", c[x]);
      |                 ~~~~~^~~~~~~~~~~~

ソースコード

diff #

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

using namespace std;

int h, w, k;
int sum[2005][2005];
char c[2005][2005];
int dp[2005][2005];
vector<int> vec[2005][2005];

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)
{
	cin >> h >> w >> k;
	scanf("%d %d %d", &w, &h, &k);
	for(int x = 1; x <= w; x++){
		scanf("%s", c[x]);
		/*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)) continue;
				if(get(x, y, dp[x][y]) == 0) dp[x][y]++;
				if(dp[x][y] > min(w-x, h-y)) continue;
				vec[x][y].push_back(dp[x][y]);
			}
		}
	}
	
	int ans = 0;
	for(int x = 1; x <= w; x++){
		for(int y = 1; y <= h; y++){
			if(vec[x][y].size() < k) continue;
			vec[x][y].push_back(min(w-x, h-y)+1);
			sort(vec[x][y].begin(), vec[x][y].end());
			ans += vec[x][y][k] - vec[x][y][k-1];
		}
	}
	cout << ans << endl;
	
	return 0;
}
0