結果
| 問題 |
No.866 レベルKの正方形
|
| コンテスト | |
| ユーザー |
はまやんはまやん
|
| 提出日時 | 2019-08-17 19:16:23 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 3,153 bytes |
| コンパイル時間 | 2,196 ms |
| コンパイル使用メモリ | 195,396 KB |
| 最終ジャッジ日時 | 2025-01-07 13:35:29 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 MLE * 1 |
| other | AC * 1 TLE * 14 MLE * 7 |
ソースコード
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int VW, int VH> struct Ruisekiwa2D {
int v[VH][VW];
Ruisekiwa2D() { rep(y, 0, VH) rep(x, 0, VW) v[y][x] = 0; }
void set(int x, int y, int c) { v[y][x] = c; }
void build() {
rep(y, 0, VH) rep(x, 0, VW) {
if (0 < y) v[y][x] += v[y - 1][x];
if (0 < x) v[y][x] += v[y][x - 1];
if (0 < y && 0 < x) v[y][x] -= v[y - 1][x - 1];
}
}
int get(int sx, int sy, int tx, int ty) { // [sx,sy]~[tx,ty]
assert(sx <= tx && sy <= ty);
int rs = v[ty][tx];
if (0 < sx) rs -= v[ty][sx - 1];
if (0 < sy) rs -= v[sy - 1][tx];
if (0 < sx && 0 < sy) rs += v[sy - 1][sx - 1];
return rs;
}
};
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int H, W, K;
string C[2010];
Ruisekiwa2D<2010, 2010> r2d[26];
//---------------------------------------------------------------------------------------------------
int get(int x, int y, int length) {
int res = 0;
rep(c, 0, 26) if (0 < r2d[c].get(x, y, x + length - 1, y + length - 1)) res++;
return res;
}
//---------------------------------------------------------------------------------------------------
int binarySearch(int x, int y, int l, int r, int limit) { //[l,r)
if (limit <= get(x, y, l)) return l;
int ng = l, ok = r;
while (ng + 1 != ok) {
int md = (ng + ok) / 2;
if (limit <= get(x, y, md)) ok = md;
else ng = md;
}
return ok;
}
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> H >> W >> K;
rep(y, 0, H) cin >> C[y];
rep(y, 0, H) rep(x, 0, W) r2d[C[y][x] - 'a'].set(x, y, 1);
rep(c, 0, 26) r2d[c].build();
ll ans = 0;
rep(y, 0, H) rep(x, 0, W) {
int maxlen = min(W - x, H - y);
ans += binarySearch(x, y, 1, maxlen + 1, K + 1) - binarySearch(x, y, 1, maxlen + 1, K);
}
cout << ans << endl;
}
はまやんはまやん