結果

問題 No.866 レベルKの正方形
ユーザー QCFiumQCFium
提出日時 2019-09-26 16:02:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,035 bytes
コンパイル時間 2,200 ms
コンパイル使用メモリ 188,604 KB
実行使用メモリ 419,852 KB
最終ジャッジ日時 2023-10-24 15:25:44
合計ジャッジ時間 25,260 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 2,081 ms
419,828 KB
testcase_09 AC 2,477 ms
419,852 KB
testcase_10 AC 4,582 ms
419,852 KB
testcase_11 AC 4,872 ms
419,852 KB
testcase_12 AC 5,767 ms
419,852 KB
testcase_13 AC 4,763 ms
419,852 KB
testcase_14 AC 5,117 ms
419,852 KB
testcase_15 AC 4,105 ms
419,852 KB
testcase_16 TLE -
testcase_17 AC 4,553 ms
419,852 KB
testcase_18 AC 4,894 ms
419,852 KB
testcase_19 AC 5,108 ms
419,852 KB
testcase_20 AC 4,562 ms
419,852 KB
testcase_21 AC 3,361 ms
419,852 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 #

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#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;
	int last_low[h + w - 1];
	int last_high[h + w - 1];
	for (int i = 0; i < h + w - 1; i++) {
		last_low[i] = -1;
		last_high[i] = -1;
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int tmp1, tmp2;
			{
				int start = last_low[i - j + w - 1] == -1 ? 0 : last_low[i - j + w - 1] - 1;
				int max_size = std::min(h - i, w - j);
				int cur = start;
				while (cur < max_size) {
					int m = cur + 1;
					bool ok;
					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++;
					ok = cnt >= k;
					
					if (!ok) cur++;
					else break;
				}
				last_low[i - j + w - 1] = cur;
				tmp1 = cur;
			}{
				int start = last_high[i - j + w - 1] == -1 ? 0 : last_high[i - j + w - 1] - 1;
				int max_size = std::min(h - i, w - j);
				int cur = start;
				while (cur < max_size) {
					int m = cur + 1;
					bool ok;
					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++;
					ok = cnt > k;
					
					if (!ok) cur++;
					else break;
				}
				last_high[i - j + w - 1] = cur;
				tmp2 = cur;
			}
			res += tmp2 - tmp1;
		}
	}
	std::cout << res << std::endl;
	
	return 0;
}
0