結果

問題 No.866 レベルKの正方形
ユーザー mkawa2mkawa2
提出日時 2021-05-24 23:56:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,495 bytes
コンパイル時間 3,654 ms
コンパイル使用メモリ 196,444 KB
実行使用メモリ 167,932 KB
最終ジャッジ日時 2024-04-21 09:24:16
合計ジャッジ時間 9,050 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,596 KB
testcase_01 AC 3 ms
9,472 KB
testcase_02 AC 4 ms
9,856 KB
testcase_03 AC 3 ms
9,728 KB
testcase_04 AC 3 ms
9,852 KB
testcase_05 AC 3 ms
9,472 KB
testcase_06 AC 4 ms
9,728 KB
testcase_07 AC 3 ms
9,856 KB
testcase_08 AC 367 ms
162,052 KB
testcase_09 AC 336 ms
161,700 KB
testcase_10 AC 299 ms
162,068 KB
testcase_11 AC 306 ms
162,076 KB
testcase_12 AC 250 ms
162,164 KB
testcase_13 AC 298 ms
162,156 KB
testcase_14 AC 228 ms
161,816 KB
testcase_15 AC 298 ms
161,840 KB
testcase_16 AC 288 ms
161,940 KB
testcase_17 AC 297 ms
161,372 KB
testcase_18 AC 298 ms
162,068 KB
testcase_19 AC 213 ms
161,928 KB
testcase_20 AC 172 ms
161,928 KB
testcase_21 WA -
testcase_22 AC 2 ms
7,656 KB
testcase_23 AC 2 ms
7,528 KB
testcase_24 AC 4 ms
11,692 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];
      }
    }
  }

  int 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