結果
| 問題 |
No.866 レベルKの正方形
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-08-16 22:37:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,538 bytes |
| コンパイル時間 | 1,572 ms |
| コンパイル使用メモリ | 116,056 KB |
| 実行使用メモリ | 448,528 KB |
| 最終ジャッジ日時 | 2024-09-22 18:46:10 |
| 合計ジャッジ時間 | 9,685 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 8 TLE * 1 -- * 13 |
ソースコード
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> void chmin(T &t, const T &f) { if (t > f) t = f; }
template <class T> void chmax(T &t, const T &f) { if (t < f) t = f; }
int H, W, K;
char C[2010][2010];
int sum[26][2010][2010];
int ansL[2010][2010];
int ansU[2010][2010];
inline int calc(int e, int x0, int x1, int y0, int y1) {
return sum[e][x0][y0] - sum[e][x0][y1] - sum[e][x1][y0] + sum[e][x1][y1];
}
int main() {
for (; ~scanf("%d%d%d", &H, &W, &K); ) {
for (int x = 0; x < H; ++x) {
scanf("%s", C[x]);
}
for (int e = 0; e < 26; ++e) {
for (int x = 0; x < H; ++x) for (int y = 0; y < W; ++y) {
sum[e][x + 1][y + 1] = sum[e][x + 1][y] + sum[e][x][y + 1] - sum[e][x][y] + ((C[x][y] - 'a' == e) ? 1 : 0);
}
}
Int ans = 0;
for (int x = 0; x < H; ++x) for (int y = 0; y < W; ++y) {
int lo, hi;
lo = 0;
hi = min(H - x, W - y) + 1;
if (x > 0 && y > 0) {
chmax(lo, ansL[x - 1][y - 1] - 2);
}
for (; lo + 1 < hi; ) {
const int mid = (lo + hi) / 2;
int cnt = 0;
for (int e = 0; e < 26; ++e) {
if (calc(e, x, x + mid, y, y + mid) > 0) {
++cnt;
}
}
((cnt >= K) ? hi : lo) = mid;
}
ansL[x][y] = hi;
hi = min(H - x, W - y) + 1;
if (x > 0 && y > 0) {
chmax(lo, ansU[x - 1][y - 1] - 2);
}
for (; lo + 1 < hi; ) {
const int mid = (lo + hi) / 2;
int cnt = 0;
for (int e = 0; e < 26; ++e) {
if (calc(e, x, x + mid, y, y + mid) > 0) {
++cnt;
}
}
((cnt >= K + 1) ? hi : lo) = mid;
}
ansU[x][y] = hi;
ans += ansU[x][y] - ansL[x][y];
}
printf("%lld\n", ans);
}
return 0;
}