結果

問題 No.866 レベルKの正方形
ユーザー mkawa2mkawa2
提出日時 2021-05-24 23:58:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 367 ms / 6,000 ms
コード長 1,494 bytes
コンパイル時間 2,183 ms
コンパイル使用メモリ 196,936 KB
実行使用メモリ 161,156 KB
最終ジャッジ日時 2024-04-21 09:25:49
合計ジャッジ時間 7,523 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,600 KB
testcase_01 AC 3 ms
9,856 KB
testcase_02 AC 3 ms
9,600 KB
testcase_03 AC 3 ms
9,472 KB
testcase_04 AC 3 ms
9,600 KB
testcase_05 AC 3 ms
9,728 KB
testcase_06 AC 3 ms
9,604 KB
testcase_07 AC 3 ms
9,600 KB
testcase_08 AC 367 ms
160,812 KB
testcase_09 AC 337 ms
160,828 KB
testcase_10 AC 299 ms
161,156 KB
testcase_11 AC 304 ms
161,016 KB
testcase_12 AC 249 ms
161,096 KB
testcase_13 AC 297 ms
160,984 KB
testcase_14 AC 229 ms
161,084 KB
testcase_15 AC 294 ms
161,144 KB
testcase_16 AC 291 ms
160,944 KB
testcase_17 AC 301 ms
160,920 KB
testcase_18 AC 294 ms
161,008 KB
testcase_19 AC 213 ms
160,916 KB
testcase_20 AC 173 ms
160,848 KB
testcase_21 AC 188 ms
160,836 KB
testcase_22 AC 3 ms
7,660 KB
testcase_23 AC 3 ms
7,524 KB
testcase_24 AC 4 ms
11,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
const int inf = 1e9;
const ll lim = 1e18;

int t[12][2005][2005];
int h, w, k;

int bitsize(int a) {
  int res = 0;
  while (a) {
    res++;
    a >>= 1;
  }
  return res;
}

int cnt(int i, int l, int r) {
  int d = r - l + 1;
  if (i + d > h) return inf;
  if (l == r) return 1;
  int e = bitsize(d - 1) - 1;
  int m = d - (1 << e);
  int s = t[e][i][l] | t[e][i + m][l] | t[e][i][l + m] | t[e][i + m][l + m];
  return __builtin_popcount(s);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w >> k;

  int mxe = bitsize(min(h, w)) - 1;

  rep(i, h) {
    string s;
    cin >> s;
    rep(j, w) t[0][i][j] = 1 << (s[j] - 'a');
  }

  rep(e, mxe) {
    int d = 1 << e;
    rep(i, h) {
      if (i + d * 2 > h) break;
      rep(j, w) {
        if (j + d * 2 > w) break;
        t[e + 1][i][j] =
            t[e][i][j] | t[e][i + d][j] | t[e][i][j + d] | t[e][i + d][j + d];
      }
    }
  }

  ll ans = 0;
  rep(i, h) {
    int r0 = 0, r1 = 0;
    rep(l, w) {
      if (r0 < l) r0 = l;
      while (r0 < w && cnt(i, l, r0) < k) r0++;
      if (r0 == w) break;
      if (r1 < r0) r1 = r0;
      while (r1 < w && cnt(i, l, r1) <= k) r1++;
      ans += r1 - r0;
    }
  }

  cout << ans << endl;
  return 0;
}
0