結果

問題 No.866 レベルKの正方形
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-08-16 22:39:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,518 bytes
コンパイル時間 1,729 ms
コンパイル使用メモリ 114,288 KB
実行使用メモリ 452,412 KB
最終ジャッジ日時 2023-10-24 01:59:47
合計ジャッジ時間 16,336 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,000 KB
testcase_01 AC 4 ms
9,000 KB
testcase_02 AC 3 ms
9,000 KB
testcase_03 AC 4 ms
9,000 KB
testcase_04 AC 3 ms
9,000 KB
testcase_05 AC 3 ms
9,000 KB
testcase_06 AC 4 ms
9,000 KB
testcase_07 AC 3 ms
9,000 KB
testcase_08 AC 5,818 ms
447,828 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
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 #

#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> void chmin(T &t, const T &f) { if (t > f) t = f; }
template <class T> void chmax(T &t, const T &f) { if (t < f) t = f; }

int H, W, K;
char C[2010][2010];

int sum[26][2010][2010];
int ansL[2010][2010];
int ansU[2010][2010];

inline int calc(int e, int x0, int x1, int y0, int y1) {
  return sum[e][x0][y0] - sum[e][x0][y1] - sum[e][x1][y0] + sum[e][x1][y1];
}

int main() {
  for (; ~scanf("%d%d%d", &H, &W, &K); ) {
    for (int x = 0; x < H; ++x) {
      scanf("%s", C[x]);
    }
    
    for (int e = 0; e < 26; ++e) {
      for (int x = 0; x < H; ++x) for (int y = 0; y < W; ++y) {
        sum[e][x + 1][y + 1] = sum[e][x + 1][y] + sum[e][x][y + 1] - sum[e][x][y] + ((C[x][y] - 'a' == e) ? 1 : 0);
      }
    }
    Int ans = 0;
    for (int x = 0; x < H; ++x) for (int y = 0; y < W; ++y) {
      int lo, hi;
      lo = 0;
      hi = min(H - x, W - y) + 1;
      if (x > 0 && y > 0) {
        chmax(lo, ansU[x - 1][y - 1] - 2);
      }
      for (; lo + 1 < hi; ) {
        const int mid = (lo + hi) / 2;
        int cnt = 0;
        for (int e = 0; e < 26; ++e) {
          if (calc(e, x, x + mid, y, y + mid) > 0) {
            ++cnt;
          }
        }
        ((cnt >= K + 1) ? hi : lo) = mid;
      }
      ansU[x][y] = hi;
      lo = 0;
      if (x > 0 && y > 0) {
        chmax(lo, ansL[x - 1][y - 1] - 2);
      }
      for (; lo + 1 < hi; ) {
        const int mid = (lo + hi) / 2;
        int cnt = 0;
        for (int e = 0; e < 26; ++e) {
          if (calc(e, x, x + mid, y, y + mid) > 0) {
            ++cnt;
          }
        }
        ((cnt >= K) ? hi : lo) = mid;
      }
      ansL[x][y] = hi;
      ans += ansU[x][y] - ansL[x][y];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
0