結果

問題 No.866 レベルKの正方形
ユーザー kk
提出日時 2021-05-03 16:26:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,095 bytes
コンパイル時間 2,073 ms
コンパイル使用メモリ 202,328 KB
実行使用メモリ 418,292 KB
最終ジャッジ日時 2023-09-29 12:37:40
合計ジャッジ時間 18,918 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 635 ms
413,848 KB
testcase_09 AC 927 ms
413,788 KB
testcase_10 AC 2,784 ms
413,756 KB
testcase_11 AC 4,897 ms
413,772 KB
testcase_12 TLE -
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 <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;
    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++;
      int r = l;
      while (r <= max_n && calc(y1, x1, r) == p) r++;
      ret += r - l;
      l = max(l-1, 1);
    }
  }
  cout << ret << endl;
  
  return 0;
}
0