結果

問題 No.866 レベルKの正方形
ユーザー mkawa2mkawa2
提出日時 2021-02-27 16:33:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,557 bytes
コンパイル時間 2,422 ms
コンパイル使用メモリ 196,680 KB
実行使用メモリ 418,380 KB
最終ジャッジ日時 2024-04-10 15:42:57
合計ジャッジ時間 10,174 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
47,096 KB
testcase_01 AC 9 ms
42,856 KB
testcase_02 AC 7 ms
36,736 KB
testcase_03 AC 9 ms
46,808 KB
testcase_04 AC 9 ms
46,816 KB
testcase_05 AC 9 ms
40,696 KB
testcase_06 AC 8 ms
40,548 KB
testcase_07 AC 7 ms
38,768 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 <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;

int cs[26][2005][2005];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int h, w, k;
  cin >> h >> w >> k;
  rep(i, h) rep(j, w) {
    char c;
    cin >> c;
    cs[c - 'a'][i + 1][j + 1] = 1;
  }
  rep(a, 26) {
    rep(i, h) rep(j, w) cs[a][i + 1][j + 1] += cs[a][i + 1][j];
    rep(j, w) rep(i, h) cs[a][i + 1][j + 1] += cs[a][i][j + 1];
  }

  auto ok1=[&](int const i, int const j, int const m) {
    int cnt = 0;
    rep(a, 26) if (cs[a][i][j] + cs[a][i + m][j + m] - cs[a][i + m][j] -
                   cs[a][i][j + m]) cnt++;
    return cnt < k;
  };
  auto ok2=[&](int const i, int const j, int const m) {
    int cnt = 0;
    rep(a, 26) if (cs[a][i][j] + cs[a][i + m][j + m] - cs[a][i + m][j] -
                   cs[a][i][j + m]) cnt++;
    return cnt <= k;
  };

  int ans = 0;
  rep(i, h) rep(j, w) {
    int l = 0, r = min(h - i, w - j) + 1;
    while (l + 1 < r) {
      int m = (l + r) / 2;
      if (ok1(i, j, m))
        l = m;
      else
        r = m;
    }
    int L=l;

    r = min(h - i, w - j) + 1;
    while (l + 1 < r) {
      int m = (l + r) / 2;
      if (ok2(i, j, m))
        l = m;
      else
        r = m;
    }
    int R=l;
    ans+=R-L;
    //cout<<i<<" "<<j<<" "<<L<<" "<<R<<" "<<endl;
  }
  cout<<ans<<endl;
  return 0;
}
0