結果
| 問題 |
No.866 レベルKの正方形
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2019-08-16 21:50:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3,205 ms / 6,000 ms |
| コード長 | 1,242 bytes |
| コンパイル時間 | 2,668 ms |
| コンパイル使用メモリ | 189,128 KB |
| 実行使用メモリ | 414,060 KB |
| 最終ジャッジ日時 | 2024-09-22 15:53:58 |
| 合計ジャッジ時間 | 42,723 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#pragma GCC optimize ("Ofast,unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
int c[2001][2001][26];
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
int h, w, k; cin >> h >> w >> k;
V<string> s(h); for (auto&& e : s) cin >> e;
// VV< array<int, 26> > c(h + 1, V< array<int, 26> >(w + 1));
for (int i = h - 1; i >= 0; --i) for (int j = w - 1; j >= 0; --j) {
for (int x = 0; x < 26; ++x) {
c[i][j][x] = (s[i][j] - 'a' == x) + c[i + 1][j][x] + c[i][j + 1][x] - c[i + 1][j + 1][x];
}
}
auto fn = [&](int i, int j, int x) -> int {
auto chk = [&](int a) -> bool {
int s = 0;
for (int l = 0; l < 26; ++l) {
s += !!(c[i][j][l] - c[i + a][j][l] - c[i][j + a][l] + c[i + a][j + a][l]);
}
return s <= x;
};
int ok = 0, ng = min(h - i, w - j) + 1;
while (ng - ok > 1) {
int mid = ok + ng >> 1;
(chk(mid) ? ok : ng) = mid;
}
return ok;
};
lint res = 0;
for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) {
res += fn(i, j, k) - fn(i, j, k - 1);
}
cout << res << '\n';
}
risujiroh