結果

問題 No.866 レベルKの正方形
ユーザー QCFiumQCFium
提出日時 2019-11-15 17:17:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,233 ms / 6,000 ms
コード長 1,897 bytes
コンパイル時間 2,895 ms
コンパイル使用メモリ 189,708 KB
実行使用メモリ 417,992 KB
最終ジャッジ日時 2023-10-25 03:40:36
合計ジャッジ時間 20,724 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 844 ms
417,988 KB
testcase_09 AC 854 ms
417,992 KB
testcase_10 AC 1,175 ms
417,992 KB
testcase_11 AC 1,233 ms
417,992 KB
testcase_12 AC 1,088 ms
417,992 KB
testcase_13 AC 1,209 ms
417,992 KB
testcase_14 AC 1,007 ms
417,992 KB
testcase_15 AC 1,153 ms
417,992 KB
testcase_16 AC 1,216 ms
417,992 KB
testcase_17 AC 1,147 ms
417,992 KB
testcase_18 AC 1,164 ms
417,992 KB
testcase_19 AC 958 ms
417,992 KB
testcase_20 AC 890 ms
417,992 KB
testcase_21 AC 845 ms
417,992 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];
	
	int sum[h + 1][w + 1][26];
	memset(sum, 0, sizeof(sum));
	for (int j = 0; j < h; j++) for (int k = 0; k < w; k++) sum[j + 1][k + 1][a[j][k] - 'a']++;
	for (int i = 0; i <= h; i++) for (int j = 0; j < w; j++) for (int k = 0; k < 26; k++) sum[i][j + 1][k] += sum[i][j][k];
	for (int i = 0; i < h; i++) for (int j = 0; j <= w; j++) for (int k = 0; k < 26; k++) sum[i + 1][j][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[i + m][j + m][k] + sum[i][j][k] != sum[i][j + m][k] + sum[i + m][j][k]) 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[i + m][j + m][k] + sum[i][j][k] != sum[i][j + m][k] + sum[i + m][j][k]) 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