結果

問題 No.866 レベルKの正方形
ユーザー 👑 emthrmemthrm
提出日時 2019-08-17 16:18:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,795 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 131,104 KB
実行使用メモリ 413,728 KB
最終ジャッジ日時 2023-10-25 01:02:27
合計ジャッジ時間 31,234 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
56,892 KB
testcase_01 AC 12 ms
56,892 KB
testcase_02 AC 13 ms
56,892 KB
testcase_03 AC 12 ms
56,892 KB
testcase_04 AC 12 ms
56,892 KB
testcase_05 AC 12 ms
56,892 KB
testcase_06 AC 12 ms
56,892 KB
testcase_07 AC 13 ms
56,892 KB
testcase_08 AC 2,346 ms
413,728 KB
testcase_09 AC 1,843 ms
413,692 KB
testcase_10 AC 1,664 ms
413,624 KB
testcase_11 AC 2,284 ms
413,708 KB
testcase_12 AC 1,879 ms
413,624 KB
testcase_13 AC 2,330 ms
413,644 KB
testcase_14 WA -
testcase_15 AC 2,160 ms
413,624 KB
testcase_16 AC 2,080 ms
413,624 KB
testcase_17 AC 1,912 ms
413,624 KB
testcase_18 AC 2,162 ms
413,624 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 962 ms
413,624 KB
testcase_22 AC 12 ms
54,820 KB
testcase_23 AC 12 ms
54,820 KB
testcase_24 AC 13 ms
58,984 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[26][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];
  REP(k, 26) REP(i, h) REP(j, w) dp[k][i][j] = INF;
  for (int i = h - 1; i >= 0; --i) for (int j = w - 1; j >= 0; --j) {
    REP(k, 26) {
      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(26);
    REP(k, 26) a[k] = dp[k][i][j];
    sort(ALL(a));
    ans += a[K] - a[K - 1];
  }
  cout << ans << '\n';
  return 0;
}
0