結果

問題 No.866 レベルKの正方形
ユーザー pekempeypekempey
提出日時 2019-08-16 22:17:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,376 bytes
コンパイル時間 3,295 ms
コンパイル使用メモリ 174,768 KB
実行使用メモリ 414,264 KB
最終ジャッジ日時 2023-10-24 00:39:00
合計ジャッジ時間 44,723 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,940 KB
testcase_01 AC 2 ms
5,940 KB
testcase_02 AC 2 ms
5,940 KB
testcase_03 AC 3 ms
5,940 KB
testcase_04 AC 3 ms
5,940 KB
testcase_05 AC 2 ms
5,940 KB
testcase_06 AC 2 ms
5,940 KB
testcase_07 AC 3 ms
5,940 KB
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 3,580 ms
414,264 KB
testcase_22 AC 3 ms
5,908 KB
testcase_23 AC 2 ms
5,908 KB
testcase_24 AC 3 ms
6,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

char S[2000][2001];
int sum[2001][2001][26];

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int H, W, K;
  scanf("%d %d %d", &H, &W, &K);
  rep(i, H) scanf("%s", S[i]);
  rep(i, H) rep(j, W) rep(k, 26) {
    sum[i+1][j+1][k] = sum[i+1][j][k] + sum[i][j+1][k] - sum[i][j][k] + (S[i][j] - 'a' == k);
  }
  vector<int> from_y, from_x;
  from_y.push_back(0);
  from_x.push_back(0);
  rep(i, H-1) from_y.push_back(i+1), from_x.push_back(0);
  rep(i, W-1) from_y.push_back(0), from_x.push_back(i+1);
  auto calc = [&](int k, int y1, int y2, int x1, int x2) -> int {
    return sum[y2][x2][k] - sum[y2][x1][k] - sum[y1][x2][k] + sum[y1][x1][k];
  };
  ll ans = 0;
  rep(u, from_y.size()) {
    int y = from_y[u];
    int x = from_x[u];
    vector<int> ptr(26);
    for (; y < H && x < W; y++, x++) {
      rep(k, 26) {
        while (ptr[k] + from_y[u] <= H && ptr[k] + from_x[u] <= W && calc(k, y, ptr[k] + from_y[u], x, ptr[k] + from_x[u]) == 0) ptr[k]++;
      }
      vector<int> tmp(ptr);
      tmp.push_back(y - from_y[u]);
      tmp.push_back(min(H - from_y[u], W - from_x[u]) + 1);
      sort(tmp.begin(), tmp.end());
      ans += tmp[K+1] - tmp[K];
    }
  }
  cout << ans << endl;
}
0