結果

問題 No.866 レベルKの正方形
ユーザー kk
提出日時 2021-05-03 16:33:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 934 ms / 6,000 ms
コード長 1,116 bytes
コンパイル時間 1,992 ms
コンパイル使用メモリ 201,284 KB
実行使用メモリ 413,900 KB
最終ジャッジ日時 2023-09-29 13:15:48
合計ジャッジ時間 15,398 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 608 ms
413,552 KB
testcase_09 AC 707 ms
413,696 KB
testcase_10 AC 893 ms
413,620 KB
testcase_11 AC 934 ms
413,812 KB
testcase_12 AC 815 ms
413,756 KB
testcase_13 AC 924 ms
413,640 KB
testcase_14 AC 722 ms
413,900 KB
testcase_15 AC 880 ms
413,740 KB
testcase_16 AC 907 ms
413,712 KB
testcase_17 AC 902 ms
413,740 KB
testcase_18 AC 899 ms
413,644 KB
testcase_19 AC 698 ms
413,748 KB
testcase_20 AC 611 ms
413,748 KB
testcase_21 AC 528 ms
413,760 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

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

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++) {
    int l = 1;
    int r = 1;
    for (int x1 = 1; x1 <= w; x1++) {
      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;
      l = max(l-1, 1);
      r = max(r-1, 1);
    }
  }
  cout << ret << endl;
  
  return 0;
}
0