結果

問題 No.866 レベルKの正方形
ユーザー QCFiumQCFium
提出日時 2019-09-26 16:09:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,938 bytes
コンパイル時間 2,778 ms
コンパイル使用メモリ 190,960 KB
実行使用メモリ 419,848 KB
最終ジャッジ日時 2023-10-24 15:32:13
合計ジャッジ時間 69,940 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2,200 ms
419,812 KB
testcase_09 AC 2,530 ms
419,848 KB
testcase_10 AC 4,670 ms
419,848 KB
testcase_11 AC 5,121 ms
419,848 KB
testcase_12 TLE -
testcase_13 AC 4,892 ms
419,848 KB
testcase_14 AC 5,378 ms
419,848 KB
testcase_15 AC 4,033 ms
419,848 KB
testcase_16 TLE -
testcase_17 AC 4,410 ms
419,848 KB
testcase_18 AC 4,814 ms
419,848 KB
testcase_19 AC 5,232 ms
419,848 KB
testcase_20 AC 4,761 ms
419,848 KB
testcase_21 AC 3,471 ms
419,848 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 target("avx2")
#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;
			const int max_size = std::min(h - i, w - j);
			{
				int start = last_low[i - j + w - 1] == -1 ? 0 : last_low[i - j + w - 1] - 1;
				int cur = start;
				while (cur < max_size) {
					int m = cur + 1;
					int cnt = 0;
					for (int k = 0; k < 26; k++)
						if (sum[k][i + m][j + m] + sum[k][i][j] != sum[k][i][j + m] + sum[k][i + m][j]) cnt++;
					if (cnt < k) cur++;
					else break;
				}
				last_low[i - j + w - 1] = tmp1 = cur;
			}{
				int start = last_high[i - j + w - 1] == -1 ? 0 : last_high[i - j + w - 1] - 1;
				int cur = start;
				while (cur < max_size) {
					int m = cur + 1;
					int cnt = 0;
					for (int k = 0; k < 26; k++)
						if (sum[k][i + m][j + m] + sum[k][i][j] != sum[k][i][j + m] + sum[k][i + m][j]) cnt++;
					if (cnt <= k) cur++;
					else break;
				}
				last_high[i - j + w - 1] = tmp2 = cur;
			}
			res += tmp2 - tmp1;
		}
	}
	std::cout << res << std::endl;
	
	return 0;
}
0