結果

問題 No.866 レベルKの正方形
ユーザー QCFiumQCFium
提出日時 2019-08-16 21:47:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,439 bytes
コンパイル時間 1,696 ms
コンパイル使用メモリ 173,184 KB
実行使用メモリ 424,044 KB
最終ジャッジ日時 2023-10-23 22:21:04
合計ジャッジ時間 10,253 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 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 1 ms
4,348 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
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>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

int main() {
	int h = ri(), w = ri(), k = ri();
	std::string a[h];
	for (int i = 0; i < h; i++) std::cin >> a[i];
	
	std::vector<int> sum[26][h + 1];
	for (int i = 0; i < 26; i++)
		for (int j = 0; j <= h; j++) sum[i][j].resize(w + 1);
	for (int j = 0; j < h; j++) for (int k = 0; k < w; k++) sum[a[j][k] - 'a'][j + 1][k + 1]++;
	for (int i = 0; i < 26; i++) {
		for (int j = 0; j <= h; j++) for (int k = 0; k < w; k++) sum[i][j][k + 1] += sum[i][j][k];
		for (int j = 0; j < h; j++) for (int k = 0; k <= w; k++) sum[i][j + 1][k] += sum[i][j][k];
	}
	int64_t res = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int max_size = std::min(h - i, w - j);
			int l = 0, r = max_size + 1;
			while (r - l > 1) {
				int m = l + (r - l) / 2;
				int cnt = 0;
				for (int k = 0; k < 26; k++)
					if (sum[k][i + m][j + m] - sum[k][i][j + m] - sum[k][i + m][j] + sum[k][i][j]) cnt++;
				if (cnt >= k) r = m;
				else l = m;
			}
			int cur = l;
			l = 0, r = max_size + 1;
			while (r - l > 1) {
				int m = l + (r - l) / 2;
				int cnt = 0;
				for (int k = 0; k < 26; k++)
					if (sum[k][i + m][j + m] - sum[k][i][j + m] - sum[k][i + m][j] + sum[k][i][j]) cnt++;
				if (cnt > k) r = m;
				else l = m;
			}
			res += l - cur;
		}
	}
	std::cout << res << std::endl;
	
	return 0;
}
0