結果

問題 No.866 レベルKの正方形
ユーザー risujirohrisujiroh
提出日時 2019-08-16 21:50:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,915 ms / 6,000 ms
コード長 1,242 bytes
コンパイル時間 2,716 ms
コンパイル使用メモリ 189,416 KB
実行使用メモリ 413,956 KB
最終ジャッジ日時 2023-10-23 22:36:12
合計ジャッジ時間 50,084 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,116 ms
413,892 KB
testcase_09 AC 2,449 ms
413,828 KB
testcase_10 AC 3,667 ms
413,856 KB
testcase_11 AC 3,915 ms
413,888 KB
testcase_12 AC 3,044 ms
413,856 KB
testcase_13 AC 3,914 ms
413,888 KB
testcase_14 AC 3,085 ms
413,888 KB
testcase_15 AC 3,510 ms
413,856 KB
testcase_16 AC 3,831 ms
413,856 KB
testcase_17 AC 3,618 ms
413,856 KB
testcase_18 AC 3,655 ms
413,888 KB
testcase_19 AC 2,879 ms
413,956 KB
testcase_20 AC 2,065 ms
413,956 KB
testcase_21 AC 3,189 ms
413,956 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 #

#pragma GCC optimize ("Ofast,unroll-loops")
#pragma GCC target ("avx")
#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 c[2001][2001][26];

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