結果

問題 No.866 レベルKの正方形
ユーザー square1001square1001
提出日時 2019-08-16 21:43:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,102 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 73,228 KB
実行使用メモリ 16,056 KB
最終ジャッジ日時 2023-10-23 22:11:45
合計ジャッジ時間 11,178 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 742 ms
11,504 KB
testcase_09 AC 1,133 ms
11,508 KB
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 <string>
#include <vector>
#include <iostream>
using namespace std;
long long solve(int H, int W, int K, vector<string> S) {
	long long ans = 0;
	for (int i = 0; i < H; ++i) {
		int sz = 0, cnt = 0;
		vector<int> c(26);
		for (int j = 0; j < W; ++j) {
			while (cnt < K && i + sz < H && j + sz < W) {
				for (int l = 0; l < sz; ++l) {
					if (c[S[i + sz][j + l] - 'a']++ == 0) ++cnt;
					if (c[S[i + l][j + sz] - 'a']++ == 0) ++cnt;
				}
				if (c[S[i + sz][j + sz] - 'a']++ == 0) ++cnt;
				++sz;
			}
			if (sz != 0) {
				ans += sz - 1;
				if (cnt < K) ++ans;
			}
			if (sz > 0) {
				--sz;
				for (int l = 0; l < sz; ++l) {
					if (--c[S[i + sz][j + l] - 'a'] == 0) --cnt;
					if (--c[S[i + l][j] - 'a'] == 0) --cnt;
				}
				if (--c[S[i + sz][j + sz] - 'a'] == 0) --cnt;
			}
		}
	}
	return ans;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int H, W, K;
	cin >> H >> W >> K;
	vector<string> S(H);
	for (int i = 0; i < H; ++i) cin >> S[i];
	long long res1 = solve(H, W, K, S);
	long long res2 = solve(H, W, K + 1, S);
	cout << res2 - res1 << '\n';
	return 0;
}
0