結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
26,596 KB
testcase_01 AC 8 ms
26,712 KB
testcase_02 AC 11 ms
26,720 KB
testcase_03 AC 9 ms
26,584 KB
testcase_04 AC 9 ms
26,720 KB
testcase_05 AC 8 ms
26,852 KB
testcase_06 AC 8 ms
26,720 KB
testcase_07 AC 8 ms
26,724 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];
  }

  int ans = 0;
  rep(i, h) rep(j, w) {
    auto ok=[&](int const m,int const diff) {
      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-diff;
    };
    int l = 0, r = min(h - i, w - j) + 1;
    while (l + 1 < r) {
      int m = (l + r) / 2;
      if (ok(m,0))
        l = m;
      else
        r = m;
    }
    int R=l;

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