結果

問題 No.866 レベルKの正方形
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-08-16 22:48:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,096 bytes
コンパイル時間 1,597 ms
コンパイル使用メモリ 112,652 KB
実行使用メモリ 418,120 KB
最終ジャッジ日時 2023-10-24 02:26:11
合計ジャッジ時間 79,145 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,976 KB
testcase_01 AC 4 ms
8,976 KB
testcase_02 AC 4 ms
8,976 KB
testcase_03 AC 4 ms
8,976 KB
testcase_04 AC 4 ms
8,976 KB
testcase_05 AC 4 ms
8,976 KB
testcase_06 AC 5 ms
8,976 KB
testcase_07 AC 4 ms
8,976 KB
testcase_08 AC 5,168 ms
416,680 KB
testcase_09 AC 4,613 ms
417,464 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 AC 5,624 ms
417,820 KB
testcase_13 TLE -
testcase_14 AC 5,067 ms
417,820 KB
testcase_15 AC 5,563 ms
417,912 KB
testcase_16 AC 5,714 ms
418,120 KB
testcase_17 AC 5,599 ms
418,120 KB
testcase_18 AC 5,710 ms
418,120 KB
testcase_19 AC 4,359 ms
417,912 KB
testcase_20 AC 3,866 ms
417,912 KB
testcase_21 AC 3,446 ms
417,912 KB
testcase_22 AC 3 ms
8,340 KB
testcase_23 AC 3 ms
8,340 KB
testcase_24 AC 5 ms
10,044 KB
権限があれば一括ダウンロードができます

ソースコード

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];

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];
}
inline int get(int x, int y, int l) {
  int ret = 0;
  for (int e = 0; e < 26; ++e) {
    if (calc(e, x, x + l, y, y + l) > 0) {
      ++ret;
    }
  }
  return ret;
}

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 s = 0; s < 2; ++s) {
      for (int t = 0 - (H - 1); t <= (W - 1) - 0; ++t) {
        int l = 1;
        for (int x = 0; x < H; ++x) {
          const int y = x + t;
          if (0 <= y && y < W) {
            --l;
            for (; x + l <= H && y + l <= W && get(x, y, l) < K + s; ++l) {}
            ans += (s == 0) ? -l : +l;
          }
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
0