結果

問題 No.866 レベルKの正方形
ユーザー ccppjsrbccppjsrb
提出日時 2020-06-10 11:58:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 776 ms / 6,000 ms
コード長 1,577 bytes
コンパイル時間 1,925 ms
コンパイル使用メモリ 200,068 KB
実行使用メモリ 175,632 KB
最終ジャッジ日時 2023-09-05 03:24:18
合計ジャッジ時間 13,503 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 748 ms
175,380 KB
testcase_09 AC 693 ms
175,372 KB
testcase_10 AC 748 ms
175,360 KB
testcase_11 AC 776 ms
175,360 KB
testcase_12 AC 648 ms
175,372 KB
testcase_13 AC 709 ms
175,408 KB
testcase_14 AC 610 ms
175,432 KB
testcase_15 AC 716 ms
175,436 KB
testcase_16 AC 722 ms
175,416 KB
testcase_17 AC 699 ms
175,368 KB
testcase_18 AC 728 ms
175,380 KB
testcase_19 AC 563 ms
175,352 KB
testcase_20 AC 506 ms
175,352 KB
testcase_21 AC 606 ms
175,632 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

unsigned int sq[2001][2001][11];

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 < 11;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