結果

問題 No.866 レベルKの正方形
ユーザー snow39snow39
提出日時 2019-08-17 17:08:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,192 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 99,424 KB
実行使用メモリ 61,132 KB
最終ジャッジ日時 2023-10-25 01:00:53
合計ジャッジ時間 9,982 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
58,980 KB
testcase_01 AC 13 ms
58,980 KB
testcase_02 AC 13 ms
58,980 KB
testcase_03 AC 13 ms
58,980 KB
testcase_04 AC 13 ms
58,980 KB
testcase_05 AC 13 ms
58,980 KB
testcase_06 AC 13 ms
58,980 KB
testcase_07 AC 13 ms
58,980 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 29 ms
56,924 KB
testcase_23 AC 13 ms
56,972 KB
testcase_24 AC 14 ms
61,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int H,W,K;
string S[251];

int c[251][251];

int dp[26][2501][2501];

void chmin(int &a,int b){
  if(a>b) a=b;
}

int main(){
  cin>>H>>W>>K;
  for(int i=0;i<H;i++) cin>>S[i];

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      c[i][j]=S[i][j]-'a';
    }
  }

  for(int a=0;a<26;a++) for(int i=0;i<H;i++) for(int j=0;j<W;j++) dp[a][i][j]=min(H-i+1,W-j+1);

  for(int a=0;a<26;a++){
    for(int i=H-1;i>=0;i--){
      for(int j=W-1;j>=0;j--){
        if(c[i][j]==a) dp[a][i][j]=1;
        else{
          if(i+1<H) chmin(dp[a][i][j],dp[a][i+1][j]+1);
          if(j+1<W) chmin(dp[a][i][j],dp[a][i][j+1]+1); 
          if(i+1<H&&j+1<W) chmin(dp[a][i][j],dp[a][i+1][j+1]+1);
        }
      }
    }
  }

  ll ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      vector<int> v;
      for(int a=0;a<26;a++) v.push_back(dp[a][i][j]);
      sort(v.begin(),v.end());
      ans+=v[K]-v[K-1];
    }
  }

  cout<<ans<<endl;

  return 0;
}
0