結果

問題 No.866 レベルKの正方形
ユーザー tonetone
提出日時 2019-08-22 00:52:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,913 bytes
コンパイル時間 1,177 ms
コンパイル使用メモリ 91,712 KB
実行使用メモリ 814,336 KB
最終ジャッジ日時 2024-04-19 02:13:38
合計ジャッジ時間 3,821 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 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 <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vvv(a, b, c, d, e) vector<vector<vector<e> > >(a, vector<vector<e> >(b, vector<e> (c, d)))
#define vvvl vector<vector<vector<ll> > >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll H, W, K;
  std::cin >> H >> W >> K;
  std::vector<string> c(H);
  for(int i=0;i<H;i++) std::cin >> c[i];
  vvvl dp = vvv(H, W, 26, 0, ll);

  for(int i=0;i<26;i++){
    dp[H-1][W-1][i] = (c[H-1][W-1]-'a'==i?1:-1);
    for(int j=0;j<H;j++){
      for(int k=0;k<W;k++){
        if(j==0&&k==0) continue;
        if(c[H-1-j][W-1-k]-'a'==i) dp[H-1-j][W-1-k][i] = 1;
        else if(j==0) dp[H-1-j][W-1-k][i] = (dp[H-1-j][W-k][i]==-1?-1:dp[H-1-j][W-k][i]+1);
        else if(k==0) dp[H-1-j][W-1-k][i] = (dp[H-j][W-1-k][i]==-1?-1:dp[H-j][W-1-k][i]+1);
        else {
          if(max({dp[H-j][W-1-k][i], dp[H-1-j][W-k][i], dp[H-j][W-k][i]})==-1) dp[H-1-j][W-1-k][i]=-1;
          else dp[H-1-j][W-1-k][i] = min({(dp[H-j][W-1-k][i]==-1?1000000007:dp[H-j][W-1-k][i]+1),
             (dp[H-1-j][W-k][i]==-1?1000000007:dp[H-1-j][W-k][i]+1), (dp[H-j][W-k][i]==-1?1000000007:dp[H-j][W-k][i]+1)});
        }
        if(dp[H-1-j][W-1-k][i]!=-1&&(j+1<dp[H-1-j][W-1-k][i]||k+1<dp[H-1-j][W-1-k][i])) dp[H-1-j][W-1-k][i]=-1;
      }
    }
  }
  ll ans = 0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      std::vector<ll> las(26);
      for(int k=0;k<26;k++) las[k] = (dp[i][j][k]==-1?1000000007:dp[i][j][k]);
      sort(las.begin(), las.end());
      if(las[K-1]==1000000007) continue;
      ans += min({H-i + 1, W-j+ 1, las[K]}) - las[K-1] ;
    }
  }
  std::cout << ans << '\n';

  return 0;
}
0