結果
| 問題 |
No.866 レベルKの正方形
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-08-17 01:00:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3,800 ms / 6,000 ms |
| コード長 | 1,417 bytes |
| コンパイル時間 | 1,692 ms |
| コンパイル使用メモリ | 172,988 KB |
| 実行使用メモリ | 414,172 KB |
| 最終ジャッジ日時 | 2024-09-24 07:46:36 |
| 合計ジャッジ時間 | 52,994 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
using namespace std;
using ll = long long;
char S[2000][2001];
int sum[26][2001][2001];
int main() {
int H, W, K;
scanf("%d %d %d", &H, &W, &K);
rep(i, H) scanf("%s", S[i]);
rep(i, H) rep(j, W) rep(k, 26) {
sum[k][i+1][j+1] = sum[k][i+1][j] + sum[k][i][j+1] - sum[k][i][j] + (S[i][j] - 'a' == k);
}
vector<int> from_y, from_x;
from_y.push_back(0);
from_x.push_back(0);
rep(i, H-1) from_y.push_back(i+1), from_x.push_back(0);
rep(i, W-1) from_y.push_back(0), from_x.push_back(i+1);
auto calc = [&](int k, int y1, int y2, int x1, int x2) -> int {
return sum[k][y2][x2] - sum[k][y2][x1] - sum[k][y1][x2] + sum[k][y1][x1];
};
ll ans = 0;
rep(u, from_y.size()) {
int y = from_y[u];
int x = from_x[u];
vector<int> ptr(26);
int mn = 0;
int mx = 0;
int len = min(H - from_y[u], W - from_x[u]);
for (; y < H && x < W; y++, x++) {
rep(k, 26) {
while (ptr[k] <= len && calc(k, y, ptr[k] + from_y[u], x, ptr[k] + from_x[u]) == 0) ptr[k]++;
}
auto count = [&](int x) {
int ans = 0;
rep(k, 26) ans += ptr[k] <= x;
return ans;
};
while (mn <= len && count(mn) < K) mn++;
while (mx <= len && count(mx) <= K) mx++;
ans += mx - mn;
}
}
cout << ans << endl;
}