結果

問題 No.866 レベルKの正方形
ユーザー mkawa2
提出日時 2021-03-02 11:56:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5,929 ms / 6,000 ms
コード長 1,253 bytes
コンパイル時間 2,046 ms
コンパイル使用メモリ 196,436 KB
最終ジャッジ日時 2025-01-19 09:17:06
ジャッジサーバーID
(参考情報)
judge5 / judge4
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
const int inf = 1e9;
int cs[26][2005][2005];
int ld[2005][2005];
int rd[2005][2005];
int cnt(int const i,int const j,int const d){
int res=0;
rep(a,26) if(cs[a][i][j]+cs[a][i+d][j+d]-cs[a][i+d][j]-cs[a][i][j+d]) res++;
// cout<<i<<" "<<j<<" "<<d<<" "<<res<<" "<<endl;
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int h, w, k;
cin >> h >> w >> k;
rep(i, h){
string s;
cin >> s;
rep(j,w) cs[s[j] - 'a'][i + 1][j + 1] = 1;
}
rep(a, 26) {
rep(i, h) rep(j, w) cs[a][i + 1][j + 1] += cs[a][i + 1][j];
rep(j, w) rep(i, h) cs[a][i + 1][j + 1] += cs[a][i][j + 1];
}
ll ans = 0;
rep(i, h) rep(j, w){
int l,r;
l=max(0,ld[i][j]-1);
r=max(0,rd[i][j]-1);
while(i+l<h && j+l<w && cnt(i,j,l+1)<k) l++;
r=max(l,r);
while(i+r<h && j+r<w && cnt(i,j,r+1)<=k) r++;
ans+=r-l;
// cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<endl;
ld[i+1][j+1]=l;
rd[i+1][j+1]=r;
}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0