結果

問題 No.866 レベルKの正方形
ユーザー MarcusAureliusAntoninusMarcusAureliusAntoninus
提出日時 2019-08-16 23:03:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,572 bytes
コンパイル時間 2,548 ms
コンパイル使用メモリ 210,960 KB
実行使用メモリ 416,132 KB
最終ジャッジ日時 2023-10-24 03:58:31
合計ジャッジ時間 17,492 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 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 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

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{k_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 && level < k; 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