結果

問題 No.866 レベルKの正方形
ユーザー mkawa2mkawa2
提出日時 2021-03-02 11:50:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,254 bytes
コンパイル時間 2,547 ms
コンパイル使用メモリ 197,728 KB
実行使用メモリ 443,264 KB
最終ジャッジ日時 2024-04-14 04:31:46
合計ジャッジ時間 67,473 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
38,876 KB
testcase_01 AC 11 ms
44,892 KB
testcase_02 AC 9 ms
38,876 KB
testcase_03 AC 11 ms
46,812 KB
testcase_04 AC 11 ms
48,860 KB
testcase_05 AC 10 ms
42,716 KB
testcase_06 AC 10 ms
42,716 KB
testcase_07 AC 10 ms
40,924 KB
testcase_08 AC 3,113 ms
443,120 KB
testcase_09 AC 3,315 ms
442,992 KB
testcase_10 AC 5,262 ms
442,996 KB
testcase_11 AC 5,086 ms
443,200 KB
testcase_12 AC 5,158 ms
443,140 KB
testcase_13 AC 4,946 ms
443,124 KB
testcase_14 AC 4,083 ms
443,040 KB
testcase_15 AC 4,274 ms
443,132 KB
testcase_16 AC 5,659 ms
443,164 KB
testcase_17 AC 4,729 ms
443,008 KB
testcase_18 AC 4,915 ms
443,264 KB
testcase_19 AC 3,874 ms
443,008 KB
testcase_20 AC 3,085 ms
443,028 KB
testcase_21 WA -
testcase_22 AC 5 ms
18,136 KB
testcase_23 AC 5 ms
18,264 KB
testcase_24 AC 12 ms
54,872 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;

int cs[26][2005][2005];
int ld[2005][2005];
int rd[2005][2005];

int cnt(int const i,int const j,int const d){
  int res=0;
  rep(a,26) if(cs[a][i][j]+cs[a][i+d][j+d]-cs[a][i+d][j]-cs[a][i][j+d]) res++;
  // cout<<i<<" "<<j<<" "<<d<<" "<<res<<" "<<endl;
  return res;
}

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

  int h, w, k;
  cin >> h >> w >> k;
  rep(i, h){
    string s;
    cin >> s;
    rep(j,w) cs[s[j] - '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){
    int l,r;
    l=max(0,ld[i][j]-1);
    r=max(0,rd[i][j]-1);
    while(i+l<h && j+l<w && cnt(i,j,l+1)<k) l++;
    r=max(l,r);
    while(i+r<h && j+r<w && cnt(i,j,r+1)<=k) r++;
    ans+=r-l;
    // cout<<i<<" "<<j<<" "<<l<<" "<<r<<" "<<endl;
    ld[i+1][j+1]=l;
    rd[i+1][j+1]=r;
  }
  cout << ans << endl;
  return 0;
}
0