結果

問題 No.866 レベルKの正方形
ユーザー square1001square1001
提出日時 2020-04-10 23:56:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 934 bytes
コンパイル時間 646 ms
コンパイル使用メモリ 74,112 KB
実行使用メモリ 518,472 KB
最終ジャッジ日時 2023-10-14 08:35:40
合計ジャッジ時間 25,204 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,352 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
4,352 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <iostream>
#include <algorithm>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int inf = 1012345678;
int H, W, K, dp[2048][2048][32]; char S[2048][2048];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> H >> W >> K;
	for (int i = 0; i < H; ++i) {
		cin >> S[i];
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			int c = S[i][j] - 'a';
			for (int k = 0; k < c; ++k) {
				dp[i + 1][j + 1][k] = min({ dp[i + 1][j][k], dp[i][j + 1][k], dp[i][j][k] }) + 1;
			}
			for (int k = c + 1; k <= 26; ++k) {
				dp[i + 1][j + 1][k] = min({ dp[i + 1][j][k], dp[i][j + 1][k], dp[i][j][k] }) + 1;
			}
		}
	}
	long long ans = 0;
	for (int i = 1; i <= H; ++i) {
		for (int j = 1; j <= W; ++j) {
			sort(dp[i][j], dp[i][j] + 27);
			ans += dp[i][j][K] - dp[i][j][K - 1];
		}
	}
	cout << ans << endl;
	return 0;
}
0