結果
問題 | No.866 レベルKの正方形 |
ユーザー |
![]() |
提出日時 | 2020-04-28 22:08:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,167 bytes |
コンパイル時間 | 3,837 ms |
コンパイル使用メモリ | 218,008 KB |
最終ジャッジ日時 | 2025-01-10 03:03:28 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 8 TLE * 14 |
ソースコード
#pragma GCC optimize("Ofast")#pragma GCC target("avx,avx2,fma")#include <bits/stdc++.h>#define rep(i, n) for (lli i = 0; i < (n); i++)#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)using namespace std;using lli = long long int;void YESNO(bool), YesNo(bool);template <class T1, class T2>bool chmin(T1 &l, const T2 &r);template <class T1, class T2>bool chmax(T1 &l, const T2 &r);int c[2005][2005];int sum[26][2005][2005] = {};inline int f(int l, int i, int j, int p){return sum[l][i + p][j + p] - sum[l][i + p][j] - sum[l][i][j + p] + sum[l][i][j];}int h, w, k;int calc(int i, int j, int p){// [up, n)でp種類以上int up1 = min(h - i, w - j) + 1;int low1 = 0;const int h = h;const int w = w;const int k = k;while (up1 - low1 > 1){int mid = (up1 + low1) / 2;int cnt = 0;rep(l, 26)cnt += (f(l, i, j, mid) >= 1);(cnt >= p ? up1 : low1) = mid;}if (up1 == 0)return 0;int up2 = up1;int low2 = 0;p--;while (up2 - low2 > 1){int mid = (up2 + low2) / 2;int cnt = 0;rep(l, 26)cnt += (f(l, i, j, mid) >= 1);(cnt >= p ? up2 : low2) = mid;}return up1 - up2;}int main(){cin >> h >> w >> k;rep(i, h) rep(j, w){char ch;cin >> ch;c[i][j] = ch - 'a';}rep(l, 26){rep(i, h) rep(j, w)sum[l][i + 1][j + 1] = sum[l][i][j + 1] + sum[l][i + 1][j] - sum[l][i][j] + int(c[i][j] == l);}int ret = 0;rep(i, h) rep(j, w){// cout << i << " " << j << " " << calc(i, j, k) << endl;// cout << i << " " << j << " " << calc(i, j, k + 1) << endl;ret += calc(i, j, k + 1);}cout << ret << endl;}// -- libvoid YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }template <class T1, class T2>bool chmin(T1 &l, const T2 &r){return (l > r) ? (l = r, true) : false;}template <class T1, class T2>bool chmax(T1 &l, const T2 &r){return (l < r) ? (l = r, true) : false;}