結果

問題 No.866 レベルKの正方形
ユーザー kk
提出日時 2021-05-03 16:47:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 785 ms / 6,000 ms
コード長 1,266 bytes
コンパイル時間 2,157 ms
コンパイル使用メモリ 202,040 KB
実行使用メモリ 445,120 KB
最終ジャッジ日時 2023-09-29 13:31:16
合計ジャッジ時間 11,915 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 785 ms
444,792 KB
testcase_09 AC 734 ms
444,944 KB
testcase_10 AC 555 ms
444,996 KB
testcase_11 AC 554 ms
444,840 KB
testcase_12 AC 357 ms
445,044 KB
testcase_13 AC 547 ms
445,056 KB
testcase_14 AC 277 ms
445,120 KB
testcase_15 AC 555 ms
444,924 KB
testcase_16 AC 483 ms
444,912 KB
testcase_17 AC 555 ms
444,844 KB
testcase_18 AC 542 ms
444,828 KB
testcase_19 AC 242 ms
444,896 KB
testcase_20 AC 201 ms
444,964 KB
testcase_21 AC 285 ms
445,084 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int dp[2001][2001][26];
int memoL[2001][2001];
int memoR[2001][2001];

int calc(int y1, int x1, int n) {
  int y2 = y1 + n - 1;
  int x2 = x1 + n - 1;
  int ret = 0;
  for (int k = 0; k < 26; k++)
    if (dp[y2][x2][k] - dp[y2][x1-1][k] - dp[y1-1][x2][k] + dp[y1-1][x1-1][k] > 0)
      ++ret;
  return ret;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int h, w, p;
  cin >> h >> w >> p;

  vector<string> bd(h);
  for (int i = 0; i < h; i++)
    cin >> bd[i];

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int c = bd[i][j] - 'a';
      for (int k = 0; k < 26; k++)
        dp[i+1][j+1][k] = dp[i+1][j][k] + dp[i][j+1][k] - dp[i][j][k];
      dp[i+1][j+1][c]++;
    }
  }

  long long ret = 0;
  for (int y1 = 1; y1 <= h; y1++) {
    for (int x1 = 1; x1 <= w; x1++) {
      int l = max({1, memoL[y1-1][x1]-1, memoL[y1][x1-1]-1});
      int r = max({1, memoR[y1-1][x1]-1, memoR[y1][x1-1]-1});      
      int max_n = min(h - y1 + 1, w - x1 + 1);
      while (l <= max_n && calc(y1, x1, l) < p) l++;
      while (r <= max_n && calc(y1, x1, r) <= p) r++;
      ret += r - l;
      memoL[y1][x1] = l;
      memoR[y1][x1] = r;
    }
  }
  cout << ret << endl;
  
  return 0;
}
0