結果

問題 No.2657 Falling Block Game
ユーザー otoshigootoshigo
提出日時 2024-03-02 19:48:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 634 ms / 2,000 ms
コード長 2,778 bytes
コンパイル時間 2,321 ms
コンパイル使用メモリ 210,004 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-02 19:48:50
合計ジャッジ時間 11,530 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 27 ms
6,676 KB
testcase_05 AC 626 ms
6,676 KB
testcase_06 AC 277 ms
6,676 KB
testcase_07 AC 634 ms
6,676 KB
testcase_08 AC 294 ms
6,676 KB
testcase_09 AC 116 ms
6,676 KB
testcase_10 AC 309 ms
6,676 KB
testcase_11 AC 310 ms
6,676 KB
testcase_12 AC 319 ms
6,676 KB
testcase_13 AC 310 ms
6,676 KB
testcase_14 AC 309 ms
6,676 KB
testcase_15 AC 313 ms
6,676 KB
testcase_16 AC 316 ms
6,676 KB
testcase_17 AC 311 ms
6,676 KB
testcase_18 AC 315 ms
6,676 KB
testcase_19 AC 312 ms
6,676 KB
testcase_20 AC 94 ms
6,676 KB
testcase_21 AC 94 ms
6,676 KB
testcase_22 AC 94 ms
6,676 KB
testcase_23 AC 94 ms
6,676 KB
testcase_24 AC 94 ms
6,676 KB
testcase_25 AC 94 ms
6,676 KB
testcase_26 AC 94 ms
6,676 KB
testcase_27 AC 94 ms
6,676 KB
testcase_28 AC 93 ms
6,676 KB
testcase_29 AC 93 ms
6,676 KB
testcase_30 AC 113 ms
6,676 KB
testcase_31 AC 114 ms
6,676 KB
testcase_32 AC 113 ms
6,676 KB
testcase_33 AC 116 ms
6,676 KB
testcase_34 AC 114 ms
6,676 KB
testcase_35 AC 114 ms
6,676 KB
testcase_36 AC 114 ms
6,676 KB
testcase_37 AC 114 ms
6,676 KB
testcase_38 AC 113 ms
6,676 KB
testcase_39 AC 113 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

template <typename M>
struct segment_tree {
    using T = typename M::T;

public:
    explicit segment_tree() {}
    explicit segment_tree(int N) : segment_tree(std::vector<T>(N, M::e())) {}

    explicit segment_tree(const std::vector<T>& v) {
        int N = (int)v.size();
        n = N;
        size = 1;
        while (size < N) size <<= 1;
        data.resize(2 * size, M::e());
        for (int i = 0; i < N; i++) data[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) update(i);
    };

    void set(int p, T x) {
        assert(0 <= p && p < n);
        p += size;
        data[p] = x;
        while (p > 1) {
            p >>= 1;
            update(p);
        }
    }

    T get(int p) {
        assert(0 <= p && p < n);
        p += size;
        return data[p];
    }

    T prod(int l, int r) {
        assert(0 <= l && l <= r && r <= n);
        T vl = M::e(), vr = M::e();
        l += size;
        r += size;
        while (l < r) {
            if (l & 1) vl = M::op(vl, data[l++]);
            if (r & 1) vr = M::op(data[--r], vr);
            l >>= 1;
            r >>= 1;
        }
        return M::op(vl, vr);
    }

    T all_prod() { return data[1]; }

private:
    int n, size;
    std::vector<T> data;
    void update(int p) { data[p] = M::op(data[2 * p], data[2 * p + 1]); }
};

const int INF=1<<30;

struct M{
    using T=int;
    static T op(T l,T r){return min(l,r);}
    static T e(){return INF;}
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin>>H>>W;
    vector<string>S(H);
    for(int i=0;i<H;i++)cin>>S[i];
    segment_tree<M>seg(W);
    for(int j=0;j<W;j++)seg.set(j,0);
    for(int i=H-1;i>=0;i--){
        for(int j=0;j<W;j++){
            if(S[i][j]=='#')seg.set(j,M::e());
        }
        segment_tree<M>seg2(W);
        int l=0,r=0;
        while(l<W){
            if(S[i][l]=='.'){
                r=l;
                while(r<W&&S[i][r]=='.')r++;
                for(int j=l;j<r;j++){
                    int ok=0,ng=H*W+1;
                    while(ng-ok>1){
                        int mid=(ok+ng)/2;
                        if(seg.prod(max(l,j-mid+1),min(r,j+mid))>=mid)ok=mid;
                        else ng=mid;
                    }
                    seg2.set(j,ok);
                }
                l=r;
            }else{
                l++;
            }
        }
        swap(seg,seg2);
    }
    for(int j=0;j<W;j++)cout<<seg.get(j)<<"\n";
}
0