結果

問題 No.866 レベルKの正方形
ユーザー 👑 tute7627tute7627
提出日時 2019-08-17 01:02:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 3,205 bytes
コンパイル時間 2,369 ms
コンパイル使用メモリ 194,336 KB
実行使用メモリ 814,768 KB
最終ジャッジ日時 2023-10-24 16:33:49
合計ジャッジ時間 8,539 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
191,956 KB
testcase_01 AC 146 ms
191,956 KB
testcase_02 AC 143 ms
191,956 KB
testcase_03 AC 146 ms
191,956 KB
testcase_04 AC 146 ms
191,956 KB
testcase_05 AC 146 ms
191,956 KB
testcase_06 AC 148 ms
191,956 KB
testcase_07 AC 150 ms
191,956 KB
testcase_08 MLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef short ll;
typedef long double ld;
const ll MOD = 1e3;
//const ll MOD = 998244353;
const ll INF = 1e3;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
//m.emplace(x,0).fi->se++;

struct z{
  ll x;
  ll y;
  ll l;
};
vector<vector<bool>>k(2000,vector<bool>(2000,INF));
vector<vector<map<ll,ll>>>s(2000,vector<map<ll,ll>>(2000));
vector<string> a(2000);
ll h,w;
void bfs(queue<struct z>p){
  for(ll i=0;i<h;i++)for(ll j=0;j<w;j++)k[i][j]=false;
  while(!p.empty()){
    ll x=p.front().x;
    ll y=p.front().y;
    ll l=p.front().l;
    //cout<<x spa y spa l<<endl;
    if(k[x][y]==false){
      k[x][y]=true;
      s[x][y].emplace(l,0).fi->second++;
      //if(x<=h-2)p.push({x+1,y,l+1});
      //if(y<=w-2)p.push({x,y+1,l+1});
      short o=1;
      short u=x-o;
      short v=y-o;
      short w=l+o;
      if(x>=o)p.push({u,y,w});
      if(y>=o)p.push({x,v,w});
      if(x>=o&&y>=o)p.push({u,v,w});     
    }
    p.pop();
  }
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll k;cin>>h>>w>>k;
  rep(i,0,h)cin>>a[i];
  //test;
  vector<queue<struct z>>b(26);
  rep(i,0,h)rep(j,0,w){
    b[a[i][j]-'a'].push({i,j,(ll)1});
  }
  rep(i,0,26)bfs(b[i]);
  rep(i,0,h)rep(j,0,w){
    s[i][j].emplace(min(h-i+1,w-j+1),0);
    ll countbuf=0;
    ll tmp=-1;
    for(auto z:s[i][j]){
      countbuf+=z.se;
      //cout<<i spa j spa z.fi spa z.se <<endl;
      //cout<<tmp spa countbuf spa k<<endl;
      if(tmp!=-1){
        res+=z.fi-tmp;
        break;
      }
      if(countbuf==k){
        tmp=z.fi;
      }
      if(z.fi>min(h-i,w-j))break;
    }
    //cout<<res spa min(h-i,w-j)<<endl;
  }
  cout<<res<<endl;
  return 0;
}
0