結果

問題 No.866 レベルKの正方形
ユーザー 👑 emthrmemthrm
提出日時 2019-08-17 16:42:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,424 ms / 6,000 ms
コード長 1,742 bytes
コンパイル時間 1,328 ms
コンパイル使用メモリ 130,960 KB
実行使用メモリ 429,388 KB
最終ジャッジ日時 2023-10-25 01:03:59
合計ジャッジ時間 32,005 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
58,904 KB
testcase_01 AC 13 ms
58,904 KB
testcase_02 AC 13 ms
58,904 KB
testcase_03 AC 13 ms
58,904 KB
testcase_04 AC 12 ms
58,904 KB
testcase_05 AC 12 ms
58,904 KB
testcase_06 AC 12 ms
58,904 KB
testcase_07 AC 12 ms
58,904 KB
testcase_08 AC 2,273 ms
429,204 KB
testcase_09 AC 2,029 ms
429,284 KB
testcase_10 AC 1,777 ms
429,388 KB
testcase_11 AC 2,407 ms
429,372 KB
testcase_12 AC 1,963 ms
429,372 KB
testcase_13 AC 2,297 ms
429,372 KB
testcase_14 AC 2,042 ms
429,372 KB
testcase_15 AC 2,051 ms
429,372 KB
testcase_16 AC 2,164 ms
429,372 KB
testcase_17 AC 2,030 ms
429,372 KB
testcase_18 AC 2,094 ms
429,372 KB
testcase_19 AC 2,424 ms
429,372 KB
testcase_20 AC 2,133 ms
429,372 KB
testcase_21 AC 986 ms
429,372 KB
testcase_22 AC 12 ms
56,828 KB
testcase_23 AC 13 ms
56,828 KB
testcase_24 AC 13 ms
60,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int dp[27][2000][2000];

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int h, w, K; cin >> h >> w >> K;
  vector<string> c(h); REP(i, h) cin >> c[i];
  for (int i = h - 1; i >= 0; --i) for (int j = w - 1; j >= 0; --j) {
    REP(k, 27) {
      if (c[i][j] - 'a' == k) {
        dp[c[i][j] - 'a'][i][j] = 1;
      } else {
        dp[k][i][j] = min(h - i, w - j) + 1;
        if (i + 1 < h) dp[k][i][j] = min(dp[k][i][j], dp[k][i + 1][j] + 1);
        if (j + 1 < w) dp[k][i][j] = min(dp[k][i][j], dp[k][i][j + 1] + 1);
        if (i + 1 < h && j + 1 < w) dp[k][i][j] = min(dp[k][i][j], dp[k][i + 1][j + 1] + 1);
      }
    }
  }
  long long ans = 0;
  REP(i, h) REP(j, w) {
    vector<int> a(27);
    REP(k, 27) a[k] = dp[k][i][j];
    sort(ALL(a));
    ans += a[K] - a[K - 1];
  }
  cout << ans << '\n';
  return 0;
}
0