結果

問題 No.866 レベルKの正方形
ユーザー ゆにぽけゆにぽけ
提出日時 2024-03-11 13:38:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,559 bytes
コンパイル時間 1,594 ms
コンパイル使用メモリ 140,084 KB
実行使用メモリ 539,136 KB
最終ジャッジ日時 2024-03-11 13:39:23
合計ジャッジ時間 56,872 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
using namespace std;
void Main()
{
	int H,W,K;
	cin >> H >> W >> K;
	vector<string> S(H);
	for(int i = 0;i < H;i++)
	{
		cin >> S[i];
	}
	const int L = 26;
	vector<vector<vector<int>>> dp(H,vector<vector<int>>(W,vector<int>(L,(int)1e9)));
	for(int k = 0;k < L;k++)
	{
		for(int i = H - 1;i >= 0;i--)
		{
			for(int j = W - 1;j >= 0;j--)
			{
				if(S[i][j] == char('a' + k))
				{
					dp[i][j][k] = 1;
				}
				if(i + 1 < H)
				{
					dp[i][j][k] = min(dp[i][j][k],dp[i + 1][j][k] + 1);
				}
				if(j + 1 < W)
				{
					dp[i][j][k] = min(dp[i][j][k],dp[i][j + 1][k] + 1);
				}
				if(i + 1 < H && j + 1 < W)
				{
					dp[i][j][k] = min(dp[i][j][k],dp[i + 1][j + 1][k] + 1);
				}
			}
		}
	}
	long long ans = 0;
	for(int i = 0;i < H;i++)
	{
		for(int j = 0;j < W;j++)
		{
			sort(dp[i][j].begin(),dp[i][j].end());
			int P = min(H - i,W - j) + 1,Q = P;
			P = min(P,dp[i][j][K - 1]);
			if(K < L)
			{
				Q = min(Q,dp[i][j][K]);
			}
			ans += Q - P;
		}
	}
	cout << ans << "\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	/* cin >> tt; */
	while(tt--) Main();
}

0