結果

問題 No.866 レベルKの正方形
ユーザー risujirohrisujiroh
提出日時 2019-08-16 21:47:52
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 5,905 ms / 6,000 ms
コード長 1,144 bytes
コンパイル時間 1,513 ms
使用メモリ 415,856 KB
最終ジャッジ日時 2022-11-22 04:43:38
合計ジャッジ時間 71,063 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
3,500 KB
testcase_01 AC 2 ms
3,412 KB
testcase_02 AC 1 ms
3,476 KB
testcase_03 AC 2 ms
3,408 KB
testcase_04 AC 2 ms
3,412 KB
testcase_05 AC 2 ms
3,412 KB
testcase_06 AC 1 ms
3,408 KB
testcase_07 AC 1 ms
3,408 KB
testcase_08 AC 3,792 ms
415,728 KB
testcase_09 AC 4,058 ms
415,696 KB
testcase_10 AC 4,705 ms
415,652 KB
testcase_11 AC 4,871 ms
415,764 KB
testcase_12 AC 5,512 ms
415,640 KB
testcase_13 AC 4,681 ms
415,848 KB
testcase_14 AC 5,905 ms
415,748 KB
testcase_15 AC 4,439 ms
415,648 KB
testcase_16 AC 5,238 ms
415,844 KB
testcase_17 AC 4,497 ms
415,644 KB
testcase_18 AC 4,615 ms
415,716 KB
testcase_19 AC 5,299 ms
415,856 KB
testcase_20 AC 4,796 ms
415,644 KB
testcase_21 AC 5,178 ms
415,640 KB
testcase_22 AC 2 ms
3,396 KB
testcase_23 AC 2 ms
3,400 KB
testcase_24 AC 2 ms
3,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int h, w, k; cin >> h >> w >> k;
  V<string> s(h); for (auto&& e : s) cin >> e;
  VV< array<int, 26> > c(h + 1, V< array<int, 26> >(w + 1));
  for (int i = h - 1; i >= 0; --i) for (int j = w - 1; j >= 0; --j) {
    for (int x = 0; x < 26; ++x) {
      c[i][j][x] = (s[i][j] - 'a' == x) + c[i + 1][j][x] + c[i][j + 1][x] - c[i + 1][j + 1][x];
    }
  }

  auto fn = [&](int i, int j, int x) -> int {
    auto chk = [&](int a) -> bool {
      int s = 0;
      for (int l = 0; l < 26; ++l) {
        s += !!(c[i][j][l] - c[i + a][j][l] - c[i][j + a][l] + c[i + a][j + a][l]);
      }
      return s <= x;
    };
    int ok = 0, ng = min(h - i, w - j) + 1;
    while (ng - ok > 1) {
      int mid = ok + ng >> 1;
      (chk(mid) ? ok : ng) = mid;
    }
    return ok;
  };
  
  lint res = 0;
  for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) {
    res += fn(i, j, k) - fn(i, j, k - 1);
  }
  cout << res << '\n';
}
0