結果

問題 No.866 レベルKの正方形
ユーザー 👑 jupirojupiro
提出日時 2020-03-13 21:27:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,521 ms / 6,000 ms
コード長 2,029 bytes
コンパイル時間 1,410 ms
コンパイル使用メモリ 116,344 KB
実行使用メモリ 486,016 KB
最終ジャッジ日時 2024-05-02 07:30:55
合計ジャッジ時間 32,564 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2,521 ms
469,840 KB
testcase_09 AC 2,081 ms
470,912 KB
testcase_10 AC 1,932 ms
457,240 KB
testcase_11 AC 2,410 ms
478,836 KB
testcase_12 AC 1,966 ms
462,208 KB
testcase_13 AC 2,435 ms
486,016 KB
testcase_14 AC 2,089 ms
479,788 KB
testcase_15 AC 2,308 ms
476,196 KB
testcase_16 AC 2,204 ms
475,648 KB
testcase_17 AC 2,086 ms
476,032 KB
testcase_18 AC 2,275 ms
470,420 KB
testcase_19 AC 2,480 ms
479,192 KB
testcase_20 AC 2,291 ms
466,176 KB
testcase_21 AC 960 ms
414,244 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 4 ms
6,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

bool a[26][2001][2001];
char s[2010];
int dp[26][2001][2001];

int srt[26];
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	int H, W, K; scanf("%d %d %d", &H, &W, &K);
	for (int i = 0; i < 26; i++) for (int j = 0; j <= H; j++) for (int k = 0; k <= W; k++) dp[i][j][k] = min(H - j + 1, W - k + 1);
	for (int i = 0; i < H; i++) {
		scanf("%s", s);
		for (int j = 0; j < W; j++) {
			a[s[j] - 'a'][i][j] = true;
			dp[s[j] - 'a'][i][j] = 1;
		}
	}

	for (int i = 0; i < 26; i++) {
		for (int j = H - 1; j >= 0; j--) {
			for (int k = W - 1; k >= 0; k--) {
				chmin(dp[i][j][k], dp[i][j + 1][k] + 1);
				chmin(dp[i][j][k], dp[i][j][k + 1] + 1);
				chmin(dp[i][j][k], dp[i][j + 1][k + 1] + 1);
			}
		}
	}
	ll res = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			for (int k = 0; k < 26; k++) {
				srt[k] = dp[k][i][j];
			}
			sort(srt, srt + 26);
			if (K == 26) res += min(H - i + 1, W - j + 1) - srt[K - 1];
			else res += srt[K] - srt[K - 1];	
		}
	}
	printf("%lld\n", res);
	return 0;
	/*
		おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!!
	*/
}
0