結果
問題 | No.2657 Falling Block Game |
ユーザー |
![]() |
提出日時 | 2025-01-11 19:49:05 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 194 ms / 2,000 ms |
コード長 | 3,095 bytes |
コンパイル時間 | 4,659 ms |
コンパイル使用メモリ | 314,300 KB |
実行使用メモリ | 24,552 KB |
最終ジャッジ日時 | 2025-01-11 19:49:17 |
合計ジャッジ時間 | 11,093 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
#ifdef t9unkubj #include"debug.cpp" //#include"template_no_debug.h" #else #define dbg(...) 199958 #endif #undef _GLIBCXX_DEBUG #pragma GCC optimize("O3") using namespace std; #include<bits/stdc++.h> using ll=long long; using ull=unsigned long long; template<class T>using vc=vector<T>; template<class T>using vvc=vc<vc<T>>; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++) #define DREP(i,n,m) for(ll i=(n);i>=(m);i--) #define drep(i,n) for(ll i=((n)-1);i>=0;i--) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() template<class T,class F> bool chmin(T &x, F y){ if(x>y){ x=y; return true; } return false; } template<class T, class F> bool chmax(T &x, F y){ if(x<y){ x=y; return true; } return false; } double pass_time=0; #include<vector> #include<functional> template<class T> struct sparse_table{ std::vector<std::vector<T>>data; std::vector<int>table; using F=std::function<T(T,T)>; F op; vector<T>a; int n; sparse_table()=default; sparse_table(int n,F op):n(n),a(n),op(op){} sparse_table(int n,std::vector<T>a,F op):n(n),op(op),a(a){ build(); } void set(int i,T x){ a[i]=x; } void build(){ int log{1}; while((1<<log)<=n)log++; data=std::vector<vector<T>>(log,std::vector<T>(n)); data[0]=a; for(int i=1;i<log;i++){ for(int j=0;j<n;j++){ if(j+(1<<(i-1))<n)data[i][j]=op(data[i-1][j],data[i-1][j+(1<<(i-1))]); } } table.resize(n+1); for(int i=1;i<=n;i++){ for(int j=0;j<=log+1;j++){ if((1<<j)<=i){ table[i]=j; } } } } //[l,r) T prod(int l,int r){ int len=r-l; int lg=table[len]; return op(data[lg][l],data[lg][r-(1<<lg)]); } }; void solve(){ int h,w; cin>>h>>w; vc<string>s(h); rep(i,h)cin>>s[i]; vc<set<int>>st(h,{-1,w}); rep(i,h)rep(j,w)if(s[i][j]=='#')st[i].insert(j); auto op=[&](int a,int b){ return min(a,b); }; sparse_table<int> dp(w,op); rep(j,w){ if(s[h-1][j]=='.'){ dp.set(j,0); }else dp.set(j,1e9); } drep(i,h-1){ dp.build(); sparse_table<int>ndp(w,op); rep(j,w){ if(s[i][j]=='.'){ int ac=w,wa=-1; while(ac-wa>1){ int wj=ac+wa>>1; int l=max(0ll,j-wj); int r=min<ll>(w,j+wj+1); auto it1=st[i].lower_bound(j); if(it1!=st[i].begin())chmax(l,*prev(it1)+1); if(it1!=st[i].end())chmin(r,*it1); if(dp.prod(l,r)<=wj){ ac=wj; }else wa=wj; } ndp.set(j,ac); }else ndp.set(j,1e9); } dp=move(ndp); } rep(i,w){ cout<<dp.a[i]<<"\n"; } } signed main(){ cin.tie(0)->sync_with_stdio(0); pass_time=clock(); int t=1; //cin>>t; while(t--)solve(); pass_time=clock()-pass_time; dbg(pass_time/CLOCKS_PER_SEC); }