結果
| 問題 |
No.866 レベルKの正方形
|
| コンテスト | |
| ユーザー |
totori_nyaa
|
| 提出日時 | 2019-12-30 22:27:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4,087 ms / 6,000 ms |
| コード長 | 2,434 bytes |
| コンパイル時間 | 1,732 ms |
| コンパイル使用メモリ | 170,904 KB |
| 実行使用メモリ | 413,952 KB |
| 最終ジャッジ日時 | 2024-11-15 19:58:46 |
| 合計ジャッジ時間 | 48,157 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int c[2001][2001][26];
signed main(){
//cout << setprecision(16) ;
ios::sync_with_stdio(false);
cin.tie(0);
int h,w,n;
cin>>h>>w>>n;
string s[h];
for(int i=0;i<h;i++){
cin>>s[i];
for(int j=0;j<w;j++){
c[i+1][j+1][s[i][j]-'a']++;
for(int k=0;k<26;k++){
c[i+1][j+1][k] += c[i+1][j][k];
}
}
}
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
for(int k=0;k<26;k++){
c[i+1][j+1][k] += c[i][j+1][k];
}
}
}
ll ans = 0;
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
int cnt=0;
for(int k=0;k<26;k++){
if(c[i][j][k] - c[i-min(i,j)][j][k] - c[i][j-min(i,j)][k] + c[i-min(i,j)][j-min(i,j)][k]) cnt++;
}
if(cnt<n) continue;
int upper,lower;
//lowは下限―1、upは上限+1にする
long long low=-1,up=min(i,j)+1,mid;
while(up-low>1){
mid=(up+low)/2;
//上半分か下半分の条件を求める
cnt = 0;
for(int k=0;k<26;k++){
if(c[i][j][k] - c[i-mid][j][k] - c[i][j-mid][k] + c[i-mid][j-mid][k]>0) cnt++;
}
//上半分の時
if(cnt<=n){
low=mid;
}
//下半分の時
else{
up=mid;
}
}
//lowが答え
upper = low;
low = -1, up = min(i,j)+1;
while(up-low>1){
mid=(up+low)/2;
//上半分か下半分の条件を求める
cnt = 0;
for(int k=0;k<26;k++){
if(c[i][j][k] - c[i-mid][j][k] - c[i][j-mid][k] + c[i-mid][j-mid][k]>0) cnt++;
}
//上半分の時
if(cnt<n){
low=mid;
}
//下半分の時
else{
up=mid;
}
}
lower = low;
//cerr<<i<<" "<<j<<" "<<lower<<" "<<upper<<endl;
ans += upper - lower;
}
}
cout<<ans<<endl;
}
totori_nyaa