結果

問題 No.866 レベルKの正方形
ユーザー kwm_tkwm_t
提出日時 2023-05-01 22:21:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4,923 ms / 6,000 ms
コード長 2,356 bytes
コンパイル時間 2,278 ms
コンパイル使用メモリ 205,024 KB
実行使用メモリ 414,424 KB
最終ジャッジ日時 2024-04-30 20:33:38
合計ジャッジ時間 56,665 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 3,141 ms
414,324 KB
testcase_09 AC 3,518 ms
414,364 KB
testcase_10 AC 4,364 ms
414,364 KB
testcase_11 AC 4,600 ms
414,424 KB
testcase_12 AC 3,323 ms
414,328 KB
testcase_13 AC 4,474 ms
414,264 KB
testcase_14 AC 3,208 ms
414,376 KB
testcase_15 AC 3,980 ms
414,356 KB
testcase_16 AC 4,575 ms
414,340 KB
testcase_17 AC 4,326 ms
414,208 KB
testcase_18 AC 4,350 ms
414,424 KB
testcase_19 AC 2,233 ms
414,372 KB
testcase_20 AC 721 ms
414,372 KB
testcase_21 AC 4,923 ms
414,348 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 3 ms
7,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
int cc[2002][2002][26];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h, w, k; cin >> h >> w >> k;
	vector<string>s(h);
	rep(i, h)cin >> s[i];
	//[i,j)*[k,l) = x[j][l] -x[j][k] -x[i][l] +x[i][k]
	auto calc = [&](int i, int j, int k, int l, int c)->int {
		return  cc[j][l][c] - cc[j][k][c] - cc[i][l][c] + cc[i][k][c];
	};
	rep(i, h)rep(j, w) {
		rep(k, 26) {
			char c = 'a' + k;
			if (c == s[i][j])cc[i + 1][j + 1][k]++;
		}
	}
	rep(i, h + 1)rep(j, w)rep(k, 26) cc[i][j + 1][k] += cc[i][j][k];
	rep(i, w + 1)rep(j, h)rep(k, 26) cc[j + 1][i][k] += cc[j][i][k];
	long long ans = 0;
	rep(i, h)rep(j, w) {
		int mx = min(h - i, w - j);
		{
			int cnt = 0;
			rep(k, 26) {
				int x = calc(i, i + mx, j, j + mx, k);
				if (x)cnt++;
			}
			if (cnt < k)continue;
		}
		// 以上の最大
		long long ngL = 0;
		long long okL = mx;
		while (1 < abs(okL - ngL)) {
			long long mid = (ngL + okL) / 2;
			auto check = [&]() {
				int cnt = 0;
				rep(k, 26) {
					int x = calc(i, i + mid, j, j + mid, k);
					if (x)cnt++;
				}
				return cnt >= k;
			};
			if (check()) okL = mid;
			else ngL = mid;
		}
		// より大の最大
		long long ngR = 0;
		long long okR = mx + 1;
		while (1 < abs(okR - ngR)) {
			long long mid = (ngR + okR) / 2;
			auto check = [&]() {
				int cnt = 0;
				rep(k, 26) {
					int x = calc(i, i + mid, j, j + mid, k);
					if (x)cnt++;
				}
				return cnt > k;
			};
			if (check()) okR = mid;
			else ngR = mid;
		}
		ans += okR - okL;
	}
	cout << ans << endl;
	return 0;
}
0