結果

問題 No.866 レベルKの正方形
ユーザー snow39snow39
提出日時 2019-08-17 17:12:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,417 ms / 6,000 ms
コード長 1,246 bytes
コンパイル時間 966 ms
コンパイル使用メモリ 99,768 KB
実行使用メモリ 433,440 KB
最終ジャッジ日時 2023-10-25 01:08:03
合計ジャッジ時間 43,306 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
56,928 KB
testcase_01 AC 13 ms
56,928 KB
testcase_02 AC 12 ms
56,928 KB
testcase_03 AC 13 ms
56,928 KB
testcase_04 AC 13 ms
56,928 KB
testcase_05 AC 13 ms
56,928 KB
testcase_06 AC 13 ms
56,928 KB
testcase_07 AC 13 ms
56,928 KB
testcase_08 AC 3,417 ms
433,404 KB
testcase_09 AC 2,719 ms
433,412 KB
testcase_10 AC 2,527 ms
433,440 KB
testcase_11 AC 3,181 ms
433,440 KB
testcase_12 AC 2,724 ms
433,440 KB
testcase_13 AC 3,241 ms
433,440 KB
testcase_14 AC 2,795 ms
433,440 KB
testcase_15 AC 3,036 ms
433,440 KB
testcase_16 AC 3,035 ms
433,440 KB
testcase_17 AC 2,795 ms
433,440 KB
testcase_18 AC 3,030 ms
433,440 KB
testcase_19 AC 3,246 ms
433,440 KB
testcase_20 AC 2,892 ms
433,440 KB
testcase_21 AC 1,737 ms
433,440 KB
testcase_22 AC 12 ms
56,932 KB
testcase_23 AC 13 ms
56,932 KB
testcase_24 AC 14 ms
63,140 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[2001];

int c[2001][2001];

int dp[26][2001][2001];

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());
      if(K==26) ans+=min(H-i+1,W-j+1)-v[K-1];
      else ans+=v[K]-v[K-1];
    }
  }

  cout<<ans<<endl;

  return 0;
}
0