結果

問題 No.866 レベルKの正方形
ユーザー milanis48663220milanis48663220
提出日時 2020-06-10 01:02:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,616 bytes
コンパイル時間 1,747 ms
コンパイル使用メモリ 83,584 KB
実行使用メモリ 414,048 KB
最終ジャッジ日時 2023-09-02 07:52:09
合計ジャッジ時間 9,546 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,448 KB
testcase_01 AC 3 ms
4,396 KB
testcase_02 AC 3 ms
4,440 KB
testcase_03 AC 3 ms
4,460 KB
testcase_04 AC 3 ms
4,396 KB
testcase_05 AC 3 ms
4,460 KB
testcase_06 AC 3 ms
4,464 KB
testcase_07 AC 3 ms
4,680 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 <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int cnt[26][2001][2001];
int H, W, K;

bool exist(int h1, int w1, int h2, int w2, char c){
    return cnt[c-'a'][h2+1][w2+1]-cnt[c-'a'][h1][w2+1]-cnt[c-'a'][h2+1][w1]+cnt[c-'a'][h1][w1] > 0;
}

int sum(int h1, int w1, int h2, int w2){
    int ans = 0;
    for(int i = 0; i < 26; i++){
        if(exist(h1, w1, h2, w2, 'a'+i)) ans++;
    }
    return ans;
}

int search_upper(int h1, int w1, int m){
    if(sum(h1, w1, h1+1, w1+1) > m) return 0;
    int r = min(H-h1-1, W-w1-1);
    int l = min(1, r);
    // int l = 1;
    if(sum(h1, w1, h1+r, w1+r) == m) return r;
    while(r-l > 1){
        int c = (l+r)/2;
        if(sum(h1, w1, h1+c, w1+c) > m) r = c;
        else l = c;
    }
    return l;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> H >> W >> K;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            char c;
            cin >> c;
            for(int k = 0; k < 26; k++){
                cnt[k][i+1][j+1] = cnt[k][i+1][j]+cnt[k][i][j+1]-cnt[k][i][j];
                if(c == 'a'+k) cnt[k][i+1][j+1]++;
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            ans += max(0, search_upper(i, j, K)-search_upper(i, j, K-1));
            // cout << i << ' ' << j << ' ' << max(0, search_upper(i, j, K)-search_upper(i, j, K-1)) << endl;
        }
    }
    cout << ans << endl;
}
0