結果

問題 No.866 レベルKの正方形
ユーザー risujirohrisujiroh
提出日時 2019-08-16 21:47:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3,881 ms / 6,000 ms
コード長 1,144 bytes
コンパイル時間 1,795 ms
コンパイル使用メモリ 175,756 KB
実行使用メモリ 415,972 KB
最終ジャッジ日時 2023-10-23 22:26:55
合計ジャッジ時間 51,923 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2,886 ms
415,876 KB
testcase_09 AC 2,941 ms
415,888 KB
testcase_10 AC 3,378 ms
415,888 KB
testcase_11 AC 3,522 ms
415,888 KB
testcase_12 AC 3,777 ms
415,972 KB
testcase_13 AC 3,435 ms
415,888 KB
testcase_14 AC 3,881 ms
415,972 KB
testcase_15 AC 3,256 ms
415,888 KB
testcase_16 AC 3,722 ms
415,972 KB
testcase_17 AC 3,341 ms
415,972 KB
testcase_18 AC 3,436 ms
415,972 KB
testcase_19 AC 3,771 ms
415,972 KB
testcase_20 AC 3,447 ms
415,972 KB
testcase_21 AC 3,755 ms
415,968 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 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