結果

問題 No.866 レベルKの正方形
ユーザー ccppjsrbccppjsrb
提出日時 2020-06-10 11:34:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,032 ms / 6,000 ms
コード長 1,577 bytes
コンパイル時間 1,514 ms
コンパイル使用メモリ 165,880 KB
実行使用メモリ 253,724 KB
最終ジャッジ日時 2023-09-05 02:11:23
合計ジャッジ時間 17,079 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 944 ms
253,548 KB
testcase_09 AC 889 ms
253,532 KB
testcase_10 AC 1,032 ms
253,532 KB
testcase_11 AC 993 ms
253,668 KB
testcase_12 AC 822 ms
253,588 KB
testcase_13 AC 956 ms
253,548 KB
testcase_14 AC 771 ms
253,668 KB
testcase_15 AC 948 ms
253,588 KB
testcase_16 AC 905 ms
253,724 KB
testcase_17 AC 906 ms
253,536 KB
testcase_18 AC 965 ms
253,652 KB
testcase_19 AC 729 ms
253,592 KB
testcase_20 AC 628 ms
253,604 KB
testcase_21 AC 775 ms
253,508 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
5,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

unsigned int sq[2001][2001][16];

int level(int y, int x, int m){
    int z = 32-__builtin_clz((unsigned int)m);
    int zz = 1<<(z-1);
    return __builtin_popcount(sq[y][x][z-1]|sq[y+m-zz][x][z-1]|sq[y][x+m-zz][z-1]|sq[y+m-zz][x+m-zz][z-1]);
}
long long rangek(int y, int x, int h, int w, int k){
    long long ret = 0ll;
    int mx = min(h-y, w-x);
    long long lowers[2001][2];
    for(int i = 0; i < mx; i++){
        lowers[i][0] = 0;
        lowers[i][1] = 0;
    }
    for(int i = 0; i < 2; i++){
        int l = 0;
        for(int r = 1; r < mx + 1; r++){
            for(;r>l;){
                if(level(y+l,x+l,r-l) < k + i){
                    break;
                }
                l++;
            }
            lowers[r-1][i] = l;
            ret += lowers[r-1][0] - lowers[r-1][i];
        }
    }
    return ret;
}
int main() {
    int h,w,k;
    cin>>h>>w>>k;
    string s;
    for(int y = 0; y < h; y++){
        cin >> s;
        for(int x = 0; x < w; x++){
            sq[y][x][0] = 1<<(s[x]-'a');
        }
    }
    int z;
    for(int i = 1; i < 16;i++){
        z = 1<<(i-1);
        for(int y = 0; y < h&&y+(1<<i)<=h; y++){
            for(int x = 0; x < w&&x+(1<<i)<=w; x++){
                sq[y][x][i] = sq[y][x][i-1]|sq[y+z][x][i-1]|sq[y][x+z][i-1]|sq[y+z][x+z][i-1];
            }
        }
    }
    long long ans = 0ll;
    for(int x = 0; x < w; x++){
        ans += rangek(0, x, h, w, k);
    }
    for(int y = 1; y < h; y++){
        ans += rangek(y, 0, h, w, k);
    }
    cout<<ans<<endl;
}
0