結果

問題 No.866 レベルKの正方形
ユーザー 👑 emthrmemthrm
提出日時 2019-08-17 15:38:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,242 bytes
コンパイル時間 1,188 ms
コンパイル使用メモリ 125,188 KB
実行使用メモリ 51,712 KB
最終ジャッジ日時 2023-10-25 00:49:42
合計ジャッジ時間 10,440 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
39,424 KB
testcase_01 AC 13 ms
49,664 KB
testcase_02 AC 10 ms
39,424 KB
testcase_03 AC 12 ms
49,664 KB
testcase_04 AC 13 ms
51,712 KB
testcase_05 AC 11 ms
45,568 KB
testcase_06 AC 11 ms
43,520 KB
testcase_07 AC 11 ms
43,520 KB
testcase_08 TLE -
testcase_09 -- -
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 #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int c[26][2001][2001] = {}, cnt[26][2001][2001] = {};
int level(int y1, int x1, int y2, int x2) {
  int res = 0;
  REP(i, 26) {
    if (cnt[i][y2 + 1][x2 + 1] - cnt[i][y1][x2 + 1] - cnt[i][y2 + 1][x1] + cnt[i][y1][x1] > 0) ++res;
  }
  // cout << y1 << ' ' << x1 << ' ' << y2 << ' ' << x2 << '|' << res << '\n';
  return res;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int h, w, k; cin >> h >> w >> k;
  REP(i, h) {
    string s; cin >> s;
    REP(j, w) ++c[s[j] - 'a'][i][j];
  }
  REP(k, 26) REP(i, h) REP(j, w) cnt[k][i + 1][j + 1] += cnt[k][i + 1][j] + c[k][i][j];
  REP(k, 26) FOR(j, 1, w + 1) FOR(i, 1, h) cnt[k][i + 1][j] += cnt[k][i][j];
  long long ans = 0;
  REP(i, h) REP(j, w) {
    int lb = -1, ub = min(h - i, w - j) - 1;
    int hashi = level(i, j, i + ub, j + ub);
    if (hashi < k) continue;
    while (ub - lb > 1) {
      int mid = (lb + ub) / 2, l = level(i, j, i + mid, j + mid);
      (l >= k ? ub : lb) = mid;
    }
    int tmp = ub;
    lb = -1; ub = min(h - i, w - j);
    if (hashi > k) {
      --ub;
      while (ub - lb > 1) {
        int mid = (lb + ub) / 2, l = level(i, j, i + mid, j + mid);
        (l > k ? ub : lb) = mid;
      }
    }
    ans += ub - tmp;
    // cout << i << ' ' << j << ' ' << tmp << ' ' << ub << '\n';
  }
  cout << ans << '\n';
  return 0;
}
0