結果
問題 | No.866 レベルKの正方形 |
ユーザー |
|
提出日時 | 2020-06-11 18:04:27 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,329 bytes |
コンパイル時間 | 4,576 ms |
コンパイル使用メモリ | 102,504 KB |
最終ジャッジ日時 | 2025-01-11 01:15:09 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 8 TLE * 14 |
ソースコード
#pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <stdio.h> #include <vector> #include <algorithm> using namespace std; using ll = long long; using VI = vector<int>; using VL = vector<ll>; #define FOR(i,a,n) for(int i=(a);i<(n);++i) #define each(i, a) for(auto &i : a) template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); } template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); } template<class T> class acc2d { int h, w; vector<vector<T>>& dat; public: acc2d(vector<vector<T>>& _dat) : dat(_dat), h(_dat.size()), w(_dat[0].size()) { FOR(i, 0, h)FOR(j, 1, w)dat[i][j] += dat[i][j - 1]; FOR(i, 1, h)FOR(j, 0, w)dat[i][j] += dat[i - 1][j]; } T sum(int y1, int x1, int y2, int x2) { T ret = dat[y2][x2]; if (0 < y1)ret -= dat[y1 - 1][x2]; if (0 < x1)ret -= dat[y2][x1 - 1]; if (0 < y1 && 0 < x1)ret += dat[y1 - 1][x1 - 1]; return ret; } T sum(int y2, int x2) { return sum(0, 0, y2, x2); } }; int main() { int h, w, k; scanf("%d %d %d", &h, &w, &k); auto dat = vec<int>(26, h, w); FOR(y, 0, h) { char s[20]; scanf("%s", s); FOR(x, 0, w)++dat[s[x] - 'a'][y][x]; } vector<acc2d<int>> acc; each(i, dat)acc.emplace_back(i); ll ans = 0; FOR(y, 0, h)FOR(x, 0, w) { int l, r; { int ok = 0, ng = min(h - y, w - x) + 1; while (ng - ok > 1) { int mid = ok + ng >> 1; int kind = 0; FOR(i, 0, 26) { if (acc[i].sum(y, x, y + mid - 1, x + mid - 1))++kind; } if (kind <= k)ok = mid; else ng = mid; } r = ok; } { int ok = 0, ng = min(h - y, w - x) + 1; while (ng - ok > 1) { int mid = ok + ng >> 1; int kind = 0; FOR(i, 0, 26) { if (acc[i].sum(y, x, y + mid - 1, x + mid - 1))++kind; } if (kind < k)ok = mid; else ng = mid; } l = ok; } ans += r - l; } printf("%lld\n", ans); return 0; }