結果

問題 No.866 レベルKの正方形
ユーザー MarcusAureliusAntoninusMarcusAureliusAntoninus
提出日時 2019-08-16 22:59:55
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 5,455 ms / 6,000 ms
コード長 1,553 bytes
コンパイル時間 2,612 ms
使用メモリ 411,616 KB
最終ジャッジ日時 2022-11-22 11:03:57
合計ジャッジ時間 28,209 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
3,608 KB
testcase_01 AC 1 ms
3,640 KB
testcase_02 AC 2 ms
3,628 KB
testcase_03 AC 1 ms
3,576 KB
testcase_04 AC 2 ms
3,580 KB
testcase_05 AC 1 ms
3,644 KB
testcase_06 AC 1 ms
3,616 KB
testcase_07 AC 2 ms
3,700 KB
testcase_08 AC 4,022 ms
411,500 KB
testcase_09 AC 4,223 ms
411,508 KB
testcase_10 AC 4,822 ms
411,544 KB
testcase_11 AC 4,939 ms
411,568 KB
testcase_12 AC 4,723 ms
411,572 KB
testcase_13 AC 4,877 ms
411,568 KB
testcase_14 AC 5,069 ms
411,444 KB
testcase_15 AC 4,682 ms
411,440 KB
testcase_16 AC 5,010 ms
411,584 KB
testcase_17 AC 4,648 ms
411,568 KB
testcase_18 AC 4,750 ms
411,440 KB
testcase_19 AC 4,321 ms
411,616 KB
testcase_20 AC 3,331 ms
411,508 KB
testcase_21 AC 5,455 ms
411,500 KB
testcase_22 AC 1 ms
3,572 KB
testcase_23 AC 2 ms
3,680 KB
testcase_24 AC 2 ms
3,612 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