結果

問題 No.2657 Falling Block Game
ユーザー RubikunRubikun
提出日時 2024-03-01 21:39:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 3,019 bytes
コンパイル時間 2,500 ms
コンパイル使用メモリ 216,164 KB
実行使用メモリ 13,016 KB
最終ジャッジ日時 2024-03-01 21:39:12
合計ジャッジ時間 7,441 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 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 133 ms
12,800 KB
testcase_06 AC 127 ms
8,192 KB
testcase_07 AC 158 ms
12,288 KB
testcase_08 AC 84 ms
6,676 KB
testcase_09 AC 55 ms
6,676 KB
testcase_10 AC 96 ms
13,016 KB
testcase_11 AC 94 ms
13,016 KB
testcase_12 AC 96 ms
13,016 KB
testcase_13 AC 96 ms
13,016 KB
testcase_14 AC 96 ms
13,016 KB
testcase_15 AC 95 ms
13,016 KB
testcase_16 AC 95 ms
13,016 KB
testcase_17 AC 98 ms
13,016 KB
testcase_18 AC 95 ms
13,016 KB
testcase_19 AC 96 ms
13,016 KB
testcase_20 AC 91 ms
6,676 KB
testcase_21 AC 88 ms
6,676 KB
testcase_22 AC 90 ms
6,676 KB
testcase_23 AC 90 ms
6,676 KB
testcase_24 AC 90 ms
6,676 KB
testcase_25 AC 90 ms
6,676 KB
testcase_26 AC 91 ms
6,676 KB
testcase_27 AC 90 ms
6,676 KB
testcase_28 AC 90 ms
6,676 KB
testcase_29 AC 90 ms
6,676 KB
testcase_30 AC 62 ms
6,676 KB
testcase_31 AC 62 ms
6,676 KB
testcase_32 AC 62 ms
6,676 KB
testcase_33 AC 61 ms
6,676 KB
testcase_34 AC 62 ms
6,676 KB
testcase_35 AC 60 ms
6,676 KB
testcase_36 AC 61 ms
6,676 KB
testcase_37 AC 60 ms
6,676 KB
testcase_38 AC 60 ms
6,676 KB
testcase_39 AC 62 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

template<typename T>
struct SparseTable{
    using F=function<T(T,T)>;
    
    int n,logn;
    vector<vector<T>> dat;
    vector<int> loglen;
    F f;
    T ti;
    
    SparseTable(int n_,F f,T ti) :f(f),ti(ti){
        n=1;
        logn=1;
        while(n<n_){
            n*=2;
            logn++;
        }
        loglen.resize(n+3);
        n=n_;
        int j=0;
        for(int i=1;i<n+3;i++){
            loglen[i]=j;
            if(i+1>(1<<(j+1))) j++;
        }
        
        dat.resize(logn);
        
        for(int i=0;i<logn;i++){
            dat[i].assign(n+1,ti);
        }
    }
    
    void set(vector<T> &v){
        for(int j=0;j<n+1;j++){
            if(j<si(v)) dat[0][j]=v[j];
        }
    }
    
    void set(int j,T x){
        dat[0][j]=x;
    }
    
    void built(){
        for(int i=1;i<logn;i++){
            for(int j=0;j<n+1;j++){
                T vl=dat[i-1][j],vr;
                if(j+(1<<(i-1))>=n+1) vr=ti;
                else vr=dat[i-1][j+(1<<(i-1))];
                dat[i][j]=f(vl,vr);
            }
        }
    }
    
    T query(int l,int r){
        if(l>=r) return ti;
        T vl=dat[loglen[r-l]][l],vr=dat[loglen[r-l]][r-(1<<loglen[r-l])];
        return f(vl,vr);
    }
};


int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,W;cin>>H>>W;
    vector<string> S(H);
    for(int i=0;i<H;i++) cin>>S[i];
    
    vector<int> dp(W,0);
    
    for(int i=H-2;i>=0;i--){
        vector<int> nex(W);
        
        SparseTable<int> spa(W,[](int a,int b){return min(a,b);},INF);
        spa.set(dp);
        spa.built();
        
        vector<int> kabe={-1};
        for(int j=0;j<W;j++){
            if(S[i][j]=='#') kabe.push_back(j);
        }
        kabe.push_back(W);
        
        for(int j=0;j<W;j++){
            if(S[i][j]=='#'){
                nex[j]=INF;
                continue;
            }
            
            int L=*prev(lower_bound(all(kabe),j)),R=*lower_bound(all(kabe),j);
            L++;R--;
            
            int left=-1,right=W;
            while(right-left>1){
                int mid=(left+right)/2;
                int l=j-mid,r=j+mid;
                chmax(l,0);
                chmin(r,W-1);
                chmax(l,L);
                chmin(r,R);
                int z=spa.query(l,r+1);
                if(z<=mid) right=mid;
                else left=mid;
            }
            
            nex[j]=right;
        }
        dp=nex;
    }
    
    for(int j=0;j<W;j++) cout<<dp[j]<<"\n";
}

0