結果

問題 No.866 レベルKの正方形
ユーザー MarcusAureliusAntoninusMarcusAureliusAntoninus
提出日時 2019-08-16 22:59:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5,276 ms / 6,000 ms
コード長 1,553 bytes
コンパイル時間 2,580 ms
コンパイル使用メモリ 211,064 KB
実行使用メモリ 411,736 KB
最終ジャッジ日時 2023-10-24 03:41:12
合計ジャッジ時間 64,746 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3,223 ms
411,736 KB
testcase_09 AC 3,361 ms
411,736 KB
testcase_10 AC 4,295 ms
411,736 KB
testcase_11 AC 4,539 ms
411,736 KB
testcase_12 AC 4,859 ms
411,736 KB
testcase_13 AC 4,320 ms
411,736 KB
testcase_14 AC 4,986 ms
411,736 KB
testcase_15 AC 4,034 ms
411,736 KB
testcase_16 AC 4,745 ms
411,736 KB
testcase_17 AC 4,072 ms
411,736 KB
testcase_18 AC 4,308 ms
411,736 KB
testcase_19 AC 4,377 ms
411,736 KB
testcase_20 AC 3,082 ms
411,736 KB
testcase_21 AC 5,276 ms
411,736 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using vi26 = std::vector<std::array<int, 26>>;
using vvi26 = std::vector<vi26>;

int H, W, K;
vvi26 table;

int calcLevelK(int, int);
bool lowerBound(int, int, int, int);

int main()
{
	scanf("%d%d%d", &H, &W, &K);
	table.resize(H + 1, vi26(W + 1));
	for (int h{1}; h <= H; h++)
		for (int w{1}; w <= W; w++)
		{
			char c;
			scanf(" %c", &c);
			table[h][w][c - 'a']++;
		}
	for (int h{1}; h <= H; h++)
		for (int w{1}; w <= W; w++)
			for (int c{}; c < 26; c++)
				table[h][w][c] += table[h][w - 1][c];
	for (int h{1}; h <= H; h++)
		for (int w{}; w <= W; w++)
			for (int c{}; c < 26; c++)
				table[h][w][c] += table[h - 1][w][c];
	int64_t ans{};
	for (int h{}; h < H; h++)
		for (int w{}; w < W; w++)
			ans += calcLevelK(h, w);

	printf("%lld\n", ans);

	return 0;
}

int calcLevelK(int h, int w)
{
	int k_left{}, k_right{std::min(H + 1 - h, W + 1 - w)};
	while (k_right - k_left > 1)
	{
		int mid{(k_right + k_left) / 2};
		if (lowerBound(h, w, mid, K)) k_right = mid;
		else k_left = mid;
	}
	if (k_right == std::min(H + 1 - h, W + 1 - w)) return 0;
	int k1_left{}, k1_right{std::min(H + 1 - h, W + 1 - w)};
	while (k1_right - k1_left > 1)
	{
		int mid{(k1_right + k1_left) / 2};
		if (lowerBound(h, w, mid, K + 1)) k1_right = mid;
		else k1_left = mid;
	}
	return k1_right - k_right;
}

bool lowerBound(int h, int w, int size, int k)
{
	int level{};
	for (int c{}; c < 26; c++)
		if (table[h + size][w + size][c] + table[h][w][c] - table[h][w + size][c] - table[h + size][w][c] > 0)
			level++;
	return level >= k;
}
0