結果

問題 No.866 レベルKの正方形
ユーザー roarisroaris
提出日時 2021-06-05 22:11:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,024 bytes
コンパイル時間 1,996 ms
コンパイル使用メモリ 200,320 KB
実行使用メモリ 420,820 KB
最終ジャッジ日時 2023-08-14 03:38:46
合計ジャッジ時間 12,058 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
10,844 KB
testcase_01 AC 3 ms
6,556 KB
testcase_02 AC 3 ms
6,736 KB
testcase_03 AC 3 ms
6,464 KB
testcase_04 AC 4 ms
6,440 KB
testcase_05 AC 3 ms
6,528 KB
testcase_06 AC 4 ms
6,644 KB
testcase_07 AC 4 ms
6,676 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 pb push_back
typedef long long ll;

int H, W, K;
char c[2010][2010];
int acc[26][2010][2010];

int calc(int k) {
    int res = 0;
    
    rep(i, H) rep(j, W) {
        int l = 1;
        int r = min(H-i, W-j);
        while (l<=r) {
            int m = (l+r)/2;
            int cnt = 0;
            rep(k, 26) if (acc[k][i+m][j+m]-acc[k][i+m][j]-acc[k][i][j+m]+acc[k][i][j]>0) cnt++;
            if (cnt<=k) l = m+1;
            else r = m-1;
        }
        res += r;
    }
    
    return res;
}

int main() {
    //ループ変数が被っていないか?
    //制約を確認しているか?
    //変数のtypoがないか?
    cin.tie(0); ios::sync_with_stdio(false);
    
    cin >> H >> W >> K;
    rep(i, H) rep(j, W) cin >> c[i][j];
    
    rep(i, 26) rep(j, H) rep(k, W) {
        acc[i][j+1][k+1] = acc[i][j+1][k]+acc[i][j][k+1]-acc[i][j][k]+(c[j][k]-'a'==i);
    }
    
    cout << calc(K)-calc(K-1) << endl;
}
0