結果
| 問題 |
No.2657 Falling Block Game
|
| コンテスト | |
| ユーザー |
hamamu
|
| 提出日時 | 2024-02-02 15:31:48 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 32,627 bytes |
| コンパイル時間 | 849 ms |
| コンパイル使用メモリ | 63,052 KB |
| 最終ジャッジ日時 | 2025-02-19 01:04:40 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:14:10: fatal error: testlib.h: No such file or directory
14 | #include "testlib.h"
| ^~~~~~~~~~~
compilation terminated.
ソースコード
#if !defined(MYLOCAL)//提出時用テンプレート
#pragma GCC optimize("Ofast")
#if defined(NDEBUG)
#undef NDEBUG
#endif
#include "bits/stdc++.h"
#if !defined(_MSC_VER) && __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define _HAS_STD_BYTE 0//testlibのbyteがstd::byteと競合するため、std::byteを無効化
#define FOR_LINUX
#include "testlib.h"
using namespace std;
using ll=long long; using dd=double;
using vll=vector< ll>; using vdd=vector< dd>;
using vvll=vector< vll>; using vvdd=vector<vdd>;
using vvvll=vector< vvll>; using vvvdd=vector<vvdd>;
using vvvvll=vector<vvvll>;
using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; using qll=tuple<ll,ll,ll,ll>;
using vpll=vector< pll>; using vtll=vector< tll>; using vqll=vector< qll>;
using vvpll=vector<vpll>; using vvtll=vector<vtll>; using vvqll=vector<vqll>;
using namespace chrono;
constexpr ll INF = 1001001001001001001;
struct Fast{ Fast(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(numeric_limits<double>::max_digits10); } } fast;
#define REPS(i, S, E) for (ll i = (S); i <= (E); i++)
#define REP(i, N) REPS(i, 0, (N)-1)
#define DEPS(i, S, E) for (ll i = (E); i >= (S); i--)
#define DEP(i, N) DEPS(i, 0, (N)-1)
#define EXPAND( x ) x//VS用おまじない
#define overload3(_1,_2,_3,name,...) name
#define overload4(_1,_2,_3,_4,name,...) name
#define overload5(_1,_2,_3,_4,_5,name,...) name
#define rep3(i, S, E) for (ll i = (S); i <= (E); i++)
#define rep4(i, S, E, t) for (ll i = (S); i <= (E); i+=(t))
#define rep(...) EXPAND(overload4(__VA_ARGS__,rep4,rep3,_,_)(__VA_ARGS__))
#define dep3(i, E, S) for (ll i = (E); i >= (S); i--)
#define dep4(i, E, S, t) for (ll i = (E); i >= (S); i-=(t))
#define dep(...) EXPAND(overload4(__VA_ARGS__, dep4, dep3,_,_)(__VA_ARGS__))
#define each2(e,v) for (auto && e:v)
#define each3(a,b,v) for (auto &&[a,b]:v)
#define each4(a,b,c,v) for (auto &&[a,b,c]:v)
#define each5(a,b,c,d,v) for (auto &&[a,b,c,d]:v)
#define each(...) EXPAND(overload5(__VA_ARGS__,each5,each4,each3,each2,_)(__VA_ARGS__))
#define ALL1(v) (v).begin(), (v).end()
#define ALL2(v,E) (v).begin(), (v).begin()+((E)+1)
#define ALL3(v,S,E) (v).begin()+(S), (v).begin()+((E)+1)
#define ALL(...) EXPAND(overload3(__VA_ARGS__, ALL3, ALL2, ALL1)(__VA_ARGS__))
#define all ALL
#define RALL1(v) (v).rbegin(), (v).rend()
#define RALL2(v,E) (v).rbegin(), (v).rbegin()+((E)+1)
#define RALL3(v,S,E) (v).rbegin()+(S), (v).rbegin()+((E)+1)
#define RALL(...) EXPAND(overload3(__VA_ARGS__, RALL3, RALL2, RALL1)(__VA_ARGS__))
#define rall RALL
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }
template<class T> inline T MaxE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmax(m,v[i]); return m; }
template<class T> inline T MinE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmin(m,v[i]); return m; }
template<class T> inline T MaxE(vector<T> &v) { return MaxE(v,0,(ll)v.size()-1); }
template<class T> inline T MinE(vector<T> &v) { return MinE(v,0,(ll)v.size()-1); }
template<class T> inline auto maxe(T &&v,ll S,ll E){ return *max_element(ALL(v,S,E)); }
template<class T> inline auto maxe(T &&v){ return *max_element(ALL(v)); }
template<class T> inline auto mine(T &&v,ll S,ll E){ return *min_element(ALL(v,S,E)); }
template<class T> inline auto mine(T &&v){ return *min_element(ALL(v)); }
template<class T> inline T Sum(vector<T> &v,ll S,ll E){ T s=T(); rep(i,S,E)s+=v[i]; return s; }
template<class T> inline T Sum(vector<T> &v) { return Sum(v,0,v.size()-1); }
template<class T,class U=typename remove_reference<T>::type::value_type>
inline U sum(T &&v,ll S,ll E) {return accumulate(all(v,S,E),U());}
template<class T> inline auto sum(T &&v) {return sum(v,0,v.end()-v.begin()-1);}
template<class T> inline ll sz(T &&v){ return (ll)v.size(); }
inline ll CEIL(ll a,ll b){ return (a<0) ? -(-a/b) : (a+b-1)/b; } //負もOK
inline ll FLOOR(ll a,ll b){ return -CEIL(-a,b); } //負もOK
//pair用テンプレート
template<class T,class S> inline pair<T,S>& operator+=(pair<T,S> &a,const pair<T,S> &b){ a.first+=b.first; a.second+=b.second; return a; }
template<class T,class S> inline pair<T,S>& operator-=(pair<T,S> &a,const pair<T,S> &b){ a.first-=b.first; a.second-=b.second; return a; }
template<class T,class S> inline pair<T,S>& operator*=(pair<T,S> &a,const pair<T,S> &b){ a.first*=b.first; a.second*=b.second; return a; }
template<class T,class S> inline pair<T,S>& operator/=(pair<T,S> &a,const pair<T,S> &b){ a.first/=b.first; a.second/=b.second; return a; }
template<class T,class S> inline pair<T,S>& operator%=(pair<T,S> &a,const pair<T,S> &b){ a.first%=b.first; a.second%=b.second; return a; }
template<class T,class S,class R> inline pair<T,S>& operator+=(pair<T,S> &a,R b){ a.first+=b; a.second+=b; return a; }
template<class T,class S,class R> inline pair<T,S>& operator-=(pair<T,S> &a,R b){ a.first-=b; a.second-=b; return a; }
template<class T,class S,class R> inline pair<T,S>& operator*=(pair<T,S> &a,R b){ a.first*=b; a.second*=b; return a; }
template<class T,class S,class R> inline pair<T,S>& operator/=(pair<T,S> &a,R b){ a.first/=b; a.second/=b; return a; }
template<class T,class S,class R> inline pair<T,S>& operator%=(pair<T,S> &a,R b){ a.first%=b; a.second%=b; return a; }
template<class T,class S,class R> inline pair<T,S> operator+(const pair<T,S> &a,R b){ pair<T,S> c=a; return c+=b; }
template<class T,class S,class R> inline pair<T,S> operator-(const pair<T,S> &a,R b){ pair<T,S> c=a; return c-=b; }
template<class T,class S,class R> inline pair<T,S> operator*(const pair<T,S> &a,R b){ pair<T,S> c=a; return c*=b; }
template<class T,class S,class R> inline pair<T,S> operator/(const pair<T,S> &a,R b){ pair<T,S> c=a; return c/=b; }
template<class T,class S,class R> inline pair<T,S> operator%(const pair<T,S> &a,R b){ pair<T,S> c=a; return c%=b; }
template<class T,class S,class R> inline pair<T,S> operator-(R b,const pair<T,S> &a){ pair<T,S> c=-a; return c+=b; }
template<class T,class S> inline pair<T,S> operator-(const pair<T,S> &a,const pair<T,S> &b){ pair<T,S> c=a; return c-=b; }
template<class T,class S> inline pair<T,S> operator-(const pair<T,S> &a){ pair<T,S> c=a; return c*=(-1); }
template<class T,class S> inline ostream &operator<<(ostream &os,const pair<T,S> &a){ return os << a.first << ' ' << a.second; }
//tuple用テンプレート 出力用のみ
template<class T,class S,class R> inline ostream &operator<<(ostream &os,const tuple<T,S,R> &a){ return os << get<0>(a) << ' ' << get<1>(a) << ' ' << get<2>(a); }
template<class T,class S,class R,class Q> inline ostream &operator<<(ostream &os,const tuple<T,S,R,Q> &a){ return os << get<0>(a) << ' ' << get<1>(a) << ' ' << get<2>(a) << ' ' << get<3>(a); }
//vector用テンプレート
template<class T> inline ostream &operator<<(ostream &os,const vector<T> &a){ for (ll i=0; i<(ll)a.size(); i++) os<<(i>0?" ":"")<<a[i]; return os; }
//array用テンプレート
template<class T,size_t S> inline array<T,S>& operator+=(array<T,S> &a,const array<T,S> &b){ for (ll i=0; i<(ll)S; i++) a[i]+=b[i]; return a; }
template<class T,size_t S> inline array<T,S>& operator-=(array<T,S> &a,const array<T,S> &b){ for (ll i=0; i<(ll)S; i++) a[i]-=b[i]; return a; }
template<class T,size_t S> inline array<T,S>& operator*=(array<T,S> &a,const array<T,S> &b){ for (ll i=0; i<(ll)S; i++) a[i]*=b[i]; return a; }
template<class T,size_t S> inline array<T,S>& operator/=(array<T,S> &a,const array<T,S> &b){ for (ll i=0; i<(ll)S; i++) a[i]/=b[i]; return a; }
template<class T,size_t S> inline array<T,S>& operator%=(array<T,S> &a,const array<T,S> &b){ for (ll i=0; i<(ll)S; i++) a[i]%=b[i]; return a; }
template<class T,size_t S,class R> inline array<T,S>& operator+=(array<T,S> &a,R b){ for (T &e: a) e+=b; return a; }
template<class T,size_t S,class R> inline array<T,S>& operator-=(array<T,S> &a,R b){ for (T &e: a) e-=b; return a; }
template<class T,size_t S,class R> inline array<T,S>& operator*=(array<T,S> &a,R b){ for (T &e: a) e*=b; return a; }
template<class T,size_t S,class R> inline array<T,S>& operator/=(array<T,S> &a,R b){ for (T &e: a) e/=b; return a; }
template<class T,size_t S,class R> inline array<T,S>& operator%=(array<T,S> &a,R b){ for (T &e: a) e%=b; return a; }
template<class T,size_t S,class R> inline array<T,S> operator+(const array<T,S> &a,R b){ array<T,S> c=a; return c+=b; }
template<class T,size_t S,class R> inline array<T,S> operator-(const array<T,S> &a,R b){ array<T,S> c=a; return c-=b; }
template<class T,size_t S,class R> inline array<T,S> operator*(const array<T,S> &a,R b){ array<T,S> c=a; return c*=b; }
template<class T,size_t S,class R> inline array<T,S> operator/(const array<T,S> &a,R b){ array<T,S> c=a; return c/=b; }
template<class T,size_t S,class R> inline array<T,S> operator%(const array<T,S> &a,R b){ array<T,S> c=a; return c%=b; }
template<class T,size_t S,class R> inline array<T,S> operator-(R b,const array<T,S> &a){ array<T,S> c=-a; return c+=b; }
template<class T,size_t S> inline array<T,S> operator-(const array<T,S> &a,const array<T,S> &b){ array<T,S> c=a; return c-=b; }
template<class T,size_t S> inline array<T,S> operator-(const array<T,S> &a){ array<T,S> c=a; return c*=(-1); }
template<class T,size_t S> inline ostream &operator<<(ostream &os,const array<T,S> &a){ for (ll i=0; i<(ll)S; i++) os<<(i>0?" ":"")<<a[i]; return os; }
#endif//テンプレートend
#if defined(_MSC_VER) && __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
struct{
system_clock::time_point st = system_clock::now();
ll operator()()const{return duration_cast<microseconds>(system_clock::now()-st).count()/1000;}
} timeget;
//////////////////////////////////////////
template<long long MOD> struct mll_{
using Int = long long;
using ll = long long;
ll val_=0;
/*---- utility ----*/
mll_ &norm(){ return normR().normS(); }//正規化
mll_ &normR(){ val_%=MOD; return *this; }//剰余正規化のみ
mll_ &normS(){ if (val_<0) val_+=MOD; return *this; }//正負正規化のみ
mll_ &normP(){ if (val_>=MOD) val_-=MOD; return *this; }//加算時正規化
mll_ &invsg(){ val_=-val_; return normS(); }//正負反転
ll modinv(int a){//a^-1 mod MOD
int ypre=0,y=1,apre=MOD;
while (a>1){
int t=apre/a;
apre-=a*t,swap(a,apre);
ypre-=y*t,swap(y,ypre);
}
return y<0 ? y+MOD: y;
}
/*---- I/F ----*/
mll_(){}
mll_(ll v): val_(v){ norm(); }
mll_(ll v,bool b): val_(v){} //正規化無のコンストラクタ
Int val()const{ return (Int)val_; }
bool isnone() const { return val_==-1; } //true:値なし
mll_ &none() { val_=-1; return *this; } //値なしにする
mll_ &inv(){ val_=modinv((int)val_); return *this; }
mll_ &operator+=(mll_ b){ val_+=b.val_; return normP(); }
mll_ &operator-=(mll_ b){ val_-=b.val_; return normS(); }
mll_ &operator*=(mll_ b){ val_*=b.val_; return normR(); }
mll_ &operator/=(mll_ b){ return *this*=b.inv(); }
mll_ &operator+=(ll b){ return *this+=mll_(b); }
mll_ &operator-=(ll b){ return *this-=mll_(b); }
mll_ &operator*=(ll b){ return *this*=mll_(b); }
mll_ &operator/=(ll b){ return *this/=mll_(b); }
mll_ operator-()const{ return mll_(*this).invsg(); }
mll_ operator+(mll_ b)const{ return mll_(*this)+=b; }
mll_ operator-(mll_ b)const{ return mll_(*this)-=b; }
mll_ operator*(mll_ b)const{ return mll_(*this)*=b; }
mll_ operator/(mll_ b)const{ return mll_(*this)/=b; }
mll_ operator+(ll b)const{ return mll_(*this)+=b; }
mll_ operator-(ll b)const{ return mll_(*this)-=b; }
mll_ operator*(ll b)const{ return mll_(*this)*=b; }
mll_ operator/(ll b)const{ return mll_(*this)/=b; }
friend mll_ operator+(ll a,mll_ b){ return b+a; }
friend mll_ operator-(ll a,mll_ b){ return -b+a; }
friend mll_ operator*(ll a,mll_ b){ return b*a; }
friend mll_ operator/(ll a,mll_ b){ return mll_(a)/b; }
bool operator==(mll_ b)const{ return val_==b.val_; }
bool operator!=(mll_ b)const{ return val_!=b.val_; }
bool operator==(ll b)const{ return *this==mll_(b); }
bool operator!=(ll b)const{ return *this!=mll_(b); }
friend bool operator==(ll a,mll_ b){ return mll_(a)==b; }
friend bool operator!=(ll a,mll_ b){ return mll_(a)!=b; }
friend ostream &operator<<(ostream &os,mll_ a){ return os << a.val_; }
friend istream &operator>>(istream &is,mll_ &a){ return is >> a.val_; }
mll_ pow(ll k)const{
mll_ ret(1,false),a(*this);
for (; k>0; k>>=1,a*=a) if (k&1)ret*=a;
return ret;
}
static constexpr int mod() { return MOD; }
//enum{ modll=MOD };
};
#if 0
#define MODLL (1000000007LL)
#else
#define MODLL (998244353LL)
#endif
using mll = mll_<MODLL>;
//using mll = fraction;
using vmll = std::vector<mll>;
using vvmll = std::vector<vmll>;
using vvvmll = std::vector<vvmll>;
using vvvvmll = std::vector<vvvmll>;
template<class T> struct Vector: vector<T>{
using Int = long long;
using vT=vector<T>;
using cvT=const vector<T>;
using cT=const T;
using vT::vT; //親クラスのコンストラクタの隠蔽を回避
using vT::begin,vT::end,vT::insert,vT::erase;
auto it(Int i){ return begin()+i; }
auto it(Int i)const{ return begin()+i; }
Vector(cvT& b):vT(b){}
Vector(vT&& b):vT(move(b)){}
Vector(Int n,T s,T d){ iota(n,s,d); }
template<class S> Vector &operator+=(S x){ for (T &e: *this) e+=x; return *this; }
template<class S> Vector &operator-=(S x){ for (T &e: *this) e-=x; return *this; }
template<class S> Vector &operator*=(S x){ for (T &e: *this) e*=x; return *this; }
template<class S> Vector &operator/=(S x){ for (T &e: *this) e/=x; return *this; }
template<class S> Vector &operator%=(S x){ for (T &e: *this) e%=x; return *this; }
template<class S> Vector operator+(S x)const{ return Vector(*this)+=x; }
template<class S> Vector operator-(S x)const{ return Vector(*this)-=x; }
template<class S> Vector operator*(S x)const{ return Vector(*this)*=x; }
template<class S> Vector operator/(S x)const{ return Vector(*this)/=x; }
template<class S> Vector operator%(S x)const{ return Vector(*this)%=x; }
Vector operator-()const{ return Vector(*this)*=-1; }
template<class S> friend Vector operator-(S x,const Vector &a){ return -a+=x; }
Int size()const{ return (Int)vT::size(); }
Vector &push_back(cT& x){ vT::push_back(x); return *this; }
Vector &pop_back(){ vT::pop_back(); return *this; }
Vector &push_front(cT& x){ insert(begin(),x); return *this; }
Vector &pop_front(){ erase(0); return *this; }
Vector &insert(Int i,cT& x){ insert(it(i),x); return *this; }
Vector &insert(Int i,cvT& b){ insert(it(i),b.begin(),b.end()); return *this; }
Vector &erase(Int i){ erase(it(i)); return *this; }
Vector &erase(Int l,Int r){ erase(it(l),it(r+1)); return *this; }
Vector &concat(cvT &b){ insert(end(),b.begin(),b.end()); return *this; }
Vector &concat(cvT &b,Int n){ for (int i=0;i<n;++i) concat(b); return *this; }
Vector &repeat(Int n){ concat(vT(*this),n-1); return *this; }
Vector &reverse(){ std::reverse(begin(),end()); return *this; }
Vector &sort(){ std::sort(begin(),end()); return *this; }
Vector &rsort(){ std::sort(vT::rbegin(),vT::rend()); return *this; }
template<class Pr> Vector &sort(Pr pr){ std::sort(begin(),end(),pr); return *this; }
Vector &uniq(){ erase(unique(begin(),end()),end()); return *this; }
Vector &sortq(){ return sort().uniq(); }
Vector &fill(Int l,Int r,cT& x){ std::fill(it(l),it(r+1),x); return *this; }
template<class S=Int> Vector &iota(Int n,T s=0,S d=1){
vT::resize(n);
if (n==0) return *this;
(*this)[0]=s;
for (int i=1;i<n;++i) (*this)[i]=(*this)[i-1]+d;
return *this;
}
Int count(cT& x)const{ return Int(std::count(begin(),end(),x)); }
Int count(Int l,Int r,cT& x)const{ return Int(std::count(it(l),it(r+1),x)); }
template<class Pr> Int countif(Pr pr)const{ return Int(count_if(begin(),end(),pr)); }
template<class Pr> Int countif(Int l,Int r,Pr pr)const{ return Int(count_if(it(l),it(r+1),pr)); }
Int find(cT& x)const{ return Int(std::find(begin(),end(),x)-begin()); }
Int find(Int l,Int r,cT& x)const{ return Int(std::find(it(l),it(r+1),x)-begin()); }
template<class Pr> Int findif(Pr pr)const{ return Int(find_if(begin(),end(),pr)-begin()); }
template<class Pr> Int findif(Int l,Int r,Pr pr)const{ return Int(find_if(it(l),it(r+1),pr)-begin()); }
Vector<Int> findall(cT& x)const{ return findall(0,size()-1,x); }
Vector<Int> findall(Int l,Int r,cT& x)const{ return findallif(l,r,[&](cT& y){return y==x;}); }
template<class Pr> Vector<Int> findallif(Pr pr)const{ return findallif(0,size()-1,pr); }
template<class Pr> Vector<Int> findallif(Int l,Int r,Pr pr)const{
Vector<Int> ret;
for (Int i=l;i<=r;++i) if (pr((*this)[i])) ret.push_back(i);
return ret;
}
Int flooridx(cT& x)const{ return Int(upper_bound(begin(),end(),x)-begin()-1); }
Int ceilidx(cT& x)const{ return Int(lower_bound(begin(),end(),x)-begin()); }
Int leftnmof(cT& x)const{ return flooridx(x)+1; }
Int rightnmof(cT& x)const{ return size()-ceilidx(x); }
bool contains(cT& x)const{ Int i=flooridx(x); return i>=0 && (*this)[i]==x; }
template<class Pr> Int flooridx(cT& x,Pr pr)const{ return Int(upper_bound(begin(),end(),x,pr)-begin()-1); }
template<class Pr> Int ceilidx(cT& x,Pr pr)const{ return Int(lower_bound(begin(),end(),x,pr)-begin()); }
template<class Pr> Int leftnmof(cT& x,Pr pr)const{ return flooridx(x,pr)+1; }
template<class Pr> Int rightnmof(cT& x,Pr pr)const{ return size()-ceilidx(x,pr); }
template<class Pr> bool contains(cT& x,Pr pr)const{ Int i=flooridx(x,pr); return i>=0 && (*this)[i]==x; }
};
/*
vll a={9,8,7},b={1,2,3};
vpll p={{5,3},{7,8},{0,2},};
- -------- 操作系 --------
a+=x a-=x a*=x a/=x a%=x a+x a-x a*x a/x a%x -a x-a //∀i a[i]にxを演算
a.push_front(x);
a.push_back(x);
a.pop_front();
a.pop_back();
a.insert(i,x); //a[i]にx挿入
a.insert(i,b); //a[i]にvll b挿入
a.erase(i); //a[i]削除
a.erase(l,r); //区間[l,r]削除
a.concat(b); //aにbを結合
a.concat(b,n); //aにbをn回結合
a.repeat(n); //aをn回繰り返す
a.reverse(); //反転
a.sort(); //ソート
a.rsort(); //逆順ソート
p.sort([&](pll x,pll y){return x.second<y.second;});//比較関数指定ソート
a.uniq(); //連続同値を1つにする
a.sortq(); //ソートしてユニーク
a.fill(l,r,x); //[l,r]にx代入
a.iota(n,s,d); //aを等差数列にする 長さn,初項s,公差d
vll a(n,s,d); //コンストラクタ版iota
- -------- 検索系 --------
auto pr=[&](auto &x){ return x>0; }; //検索条件
ll m=a.count(x); //xの個数
ll m=a.count(l,r,x); //xの個数in[l,r]
ll m=a.countif(pr); //条件満たす個数
ll m=a.countif(l,r,pr); //条件満たす個数in[l,r]
ll i=a.find(x); //xの最左位置i ない時N(配列長)
ll i=a.find(l,r,x); //xの最左位置i in[l,r] ない時r+1
ll i=a.findif(pr); //条件満たす最左位置i ない時N(配列長)
ll i=a.findif(l,r,pr); //条件満たす最左位置i in[l,r] ない時r+1
vll is=a.findall(x); //xの位置i列挙
vll is=a.findall(l,r,x); //xの位置i列挙in[l,r]
vll is=a.findallif(pr); //条件満たす位置i列挙
vll is=a.findallif(l,r,pr); //条件満たす位置i列挙in[l,r]
- -------- 昇順sort済み配列用 --------
ll i=a.flooridx(x); //x以下の最近傍位置i ない時-1
ll i=a.ceilidx(x); //x以上の最近傍位置i ない時N(配列長)
ll m=a.leftnmof(x); //x以下の個数
ll m=a.rightnmof(x); //x以上の個数
bool b=a.contains(x); //xを含む
- -------- 比較関数prでsort済みの配列用 --------
auto pr=[&](auto &x,auto &y){ return x>y; }; //降順ソート時
ll i=a.flooridx(x,pr); //x以左の最近傍位置i ない時-1
ll i=a.ceilidx(x,pr); //x以右の最近傍位置i ない時N(配列長)
ll m=a.leftnmof(x,pr); //x以左の個数
ll m=a.rightnmof(x,pr); //x以右の個数
bool b=a.contains(x,pr); //xを含む
a.concat(b,n).pop_back().rsort().uniq(); //連続適用できる
*/
namespace SolvingSpace{
template<class T> using vector = Vector<T>;
using vll=vector< ll>; using vmll=vector< mll>; using vdd=vector< dd>;
using vvll=vector< vll>; using vvmll=vector< vmll>; using vvdd=vector< vdd>;
using vvvll=vector< vvll>; using vvvmll=vector< vvmll>; using vvvdd=vector<vvdd>;
using vvvvll=vector<vvvll>; using vvvvmll=vector<vvvmll>;
using vpll=vector< pll>; using vtll=vector< tll>; using vqll=vector< qll>;
using vvpll=vector< vpll>; using vvtll=vector< vtll>; using vvqll=vector<vqll>;
template <class T,class E> struct LazySegmentTree{
using F = function<T(T,T)>;
using G = function<T(T,E)>;
using H = function<E(E,E)>;
F f; //!< データ同士の合成関数
G g; //!< 作用関数
H h; //!< 作用素同士の合成関数
T ti; //!< データの単位元 実際の単位元をセットしないとだめ
E ei; //!< 作用素の単位元 実際の単位元ではなくても、使わない値ならOK
ll n=1; //!< データ数の2べき上界
vector<T> dat;
vector<E> laz;
LazySegmentTree() {}
LazySegmentTree(vector<T> &v,F f,G g,H h,T ti,E ei) { Init(v,f,g,h,ti,ei); }
void Init(vector<T> &v,F f,G g,H h,T ti,E ei){
this->f=f; this->g=g; this->h=h; this->ti=ti; this->ei=ei;
while (n<(ll)v.size()) n<<=1;
dat.resize(2*n-1,ti);
laz.resize(2*n-1,ei);
for (ll i=0; i<(ll)v.size(); i++) dat[n-1+i] = v[i];
for (ll i=n-2; i>=0; i--) dat[i] = f(dat[2*i+1],dat[2*i+2]);
}
void set(ll i,E x){ set(i,i,x); }
void set(ll a,ll b,E x){ Set(a,b+1,x,0,0,n); } //[a,b]にxを作用
void Set(ll a,ll b,E x,ll k,ll l,ll r){ //注目ノードk=[l,r)
if (r<=a || b<=l) eval(k); //[l,r)が[a,b)と重ならない時
else if (a<=l && r<=b){ //[l,r)が[a,b)の内側の時
laz[k] = h(laz[k],x);
eval(k); //親ノードが後でdat[k]を見るため、ここで評価しておく必要あり
}
else { //[l,r)が[a,b)から一部はみ出す時
eval(k); //子ノードを処理する前に評価しておく必要あり
Set(a,b,x,k*2+1,l,(l+r)/2);
Set(a,b,x,k*2+2,(l+r)/2,r);
dat[k] = f(dat[k*2+1],dat[k*2+2]);
}
}
T operator [] (ll i) { return get(i,i); }
T get(ll a,ll b) { return Get(a,b+1,0,0,n); }//[a,b]の値を取得
T Get(ll a,ll b,ll k,ll l,ll r){ //注目ノードk=[l,r)
if (r<=a || b<=l) return ti; //[l,r)が[a,b)と重ならない時
eval(k); //自分や子の値を見る前に評価が必要
if (a<=l && r<=b) return dat[k];//[l,r)が[a,b)の内側の時
return f(Get(a,b,k*2+1,l,(l+r)/2),Get(a,b,k*2+2,(l+r)/2,r));
//[l,r)が[a,b)から一部はみ出す時
}
template<class C> ll searchl(ll a,ll b,C c){//[a,p](a≦p≦b)がtrueな最左のp
auto [pos,ignore]=SearchL(a,c,ti,0,0,n); return min(pos,b+1);
}
template<class C> ll searchr(ll a,ll b,C c){//[p,b](a≦p≦b)がtrueな最右のp
auto [pos,ignore]=SearchR(b+1,c,ti,0,0,n); return max(pos,a-1);
}
template<class C> pair<ll,T> SearchL(ll a,C c,T s,ll k,ll l,ll r){
if (r<=a) return {r,s};
eval(k);
T ss=f(s,dat[k]);
if (a<=l && !c(ss)) return {r,ss};//現セル丸ごとがfalseの時
if (n-1 <= k) return {l,s};//葉の時
ll pos,m=(l+r)/2;
; tie(pos,s)=SearchL(a,c,s,2*k+1,l,m);
if (pos==m) tie(pos,s)=SearchL(a,c,s,2*k+2,m,r);
return {pos,s};
}
template<class C> pair<ll,T> SearchR(ll b,C c,T s,ll k,ll l,ll r){
if (b<=l) return {l-1,s};
eval(k);
T ss=f(dat[k],s);
if (r<=b && !c(ss)) return {l-1,ss};//現セル丸ごとがfalseの時
if (n-1 <= k) return {l,s};//葉の時
ll pos,m=(l+r)/2;
; tie(pos,s)=SearchR(b,c,s,2*k+2,m,r);
if (pos==m-1) tie(pos,s)=SearchR(b,c,s,2*k+1,l,m);
return {pos,s};
}
ll findpeakl(ll l,ll r){
T m=get(l,r);
return searchl(l,r,[&](T x){return f(x,m)==x;});
}
ll findpeakr(ll l,ll r){
T m=get(l,r);
return searchr(l,r,[&](T x){return f(x,m)==x;});
}
void eval(ll k){
if (laz[k] == ei) return;
if (k<=n-2){ //子に作用素を配る
laz[k*2+1] = h(laz[k*2+1],laz[k]);
laz[k*2+2] = h(laz[k*2+2],laz[k]);
}
//自分に作用させる
dat[k] = g(dat[k],laz[k]);
laz[k] = ei;
}
#if defined(_DEBUG)
void dump(char deli=' '){ for (ll i=0;i<n;i++) cerr<<(*this)[i]<<deli; cerr<<'\n'; }
void dump_tree(ll w=5){
auto disp=[&](ll x){
if (x==-INF) cerr << setw(w) << "-INF";
else if (x== INF) cerr << setw(w) << "INF";
else cerr << setw(w) << x;
};
REP(i,n) for (ll k=i+n-1,m=1,p=1; k>=0; p=m,m*=k%2,k=(k==0)?-1:(k-1)/2){
if (m){
cerr << ((k<n-1)?" ┬ ":""); disp(dat[k]); cerr<<" /"; disp(laz[k]);
}
else{
cerr << ((p&~m) ?" ┘ ":"");
}
if (k==0) cerr << '\n';
} cerr << '\n';
}
#else
void dump(char deli=' '){}
void dump_tree(ll w=5){}
#endif
};
template<class T> struct findchar{
using Int = long long;
using S = typename T::value_type;
T data;
vector<vector<Int>> idxss; //idxss[x]: data[i]=xであるiの配列
S offset=0;//vの要素の最小値
/*---- utility ----*/
bool out(const S& c){ return c<offset || offset+(S)idxss.size()<=c; }
vector<Int> &idxsOf(const S& c){ return idxss[c-offset]; }
Int numOf(const S& c,Int r){//区間[0,r]のcの個数
if (out(c))return 0;
vector<Int> &idxs=idxsOf(c);
return upper_bound(idxs.begin(),idxs.end(),r) - idxs.begin();
}
/*---- I/F ----*/
findchar(){}
findchar(const T& v,const S& offset_=0){ init(v,offset_); }
void init(const T& v,const S& offset_=0){
data=v;
offset=offset_;
if (data.empty()) return;
auto [mnit,mxit]=minmax_element(v.begin(),v.end());
assert(offset<=*mnit && *mxit<offset+100000000LL);
idxss.resize((*mxit)-offset+1);
for (Int i=0;i<size();++i) idxsOf(v[i]).push_back(i);
}
bool empty()const{ return data.empty(); }
Int size()const{ return (Int)data.size(); }
void clear(){ data.clear(); idxss.clear(); }
Int nextIdxOf(const S& c,Int i){//位置iの次の文字c位置 なければ-1
if (out(c))return -1;
vector<Int> &idxs=idxsOf(c);
auto it=upper_bound(idxs.begin(),idxs.end(),i);
return it==idxs.end() ? -1 : *it;
}
Int prevIdxOf(const S& c,Int i){//位置iの前の文字c位置 なければ-1
if (out(c))return -1;
vector<Int> &idxs=idxsOf(c);
auto it=lower_bound(idxs.begin(),idxs.end(),i);
return it==idxs.begin() ? -1 : *prev(it);
}
Int cycleNextIdxOf(const S& c,Int i){//次の文字c位置(循環) なければ-1
if (out(c))return -1;
Int ret=nextIdxOf(c,i);
if (ret==-1) ret=nextIdxOf(c,-1);
return ret;
}
Int cyclePrevIdxOf(const S& c,Int i){//前の文字c位置(循環) なければ-1
if (out(c))return -1;
Int ret=prevIdxOf(c,i);
if (ret==-1) ret=prevIdxOf(c,size());
return ret;
}
Int ceilIdxOf(const S& c,Int i){ return nextIdxOf(c,i-1); }//i以降
Int floorIdxOf(const S& c,Int i){ return prevIdxOf(c,i+1); }//i以前
Int cycleCeilIdxOf(const S& c,Int i){ return cycleNextIdxOf(c,i-1); }
Int cycleFloorIdxOf(const S& c,Int i){ return cyclePrevIdxOf(c,i+1); }
Int numOf(const S& c,Int l,Int r){//区間[l,r]のcの個数
return numOf(c,r)-numOf(c,l-1);
}
Int idxOf(const S& c,Int r){//r番目(0-indexed)のcの位置 なければ-1
if (out(c))return -1;
vector<Int> &idxs=idxsOf(c);
return (Int)idxs.size()<=r ? -1 : idxs[r];
}
void push_back(const S& c){
assert(offset<=c);
if ((S)idxss.size()<=c-offset) idxss.resize(c-offset+1);
idxsOf(c).push_back(size());
data.push_back(c);
}
void push_back(const T& v){ for (const S& c: v) push_back(c); }
void pop_back(){
if (empty())return;
idxsOf(data.back()).pop_back();
data.pop_back();
}
};
/*
- 定義 ↓string,vll等
findchar fc(s);
. ↓最小要素指定
findchar fc(s,'a');
findchar fc(v,-100);
- 複数定義
vector<findchar<vll>> vfc(n);
vector<findchar<string>> vfc(n);
for (auto &&e: vfc) e.init("",'a'); //後から初期化
- 使用
ll n=fc.size();
bool b=fc.empty();
fc.clear();
ll j=fc.nextIdxOf(c,i); //位置iの次の文字c位置 なければ-1
ll j=fc.prevIdxOf(c,i); //位置iの前の文字c位置 なければ-1
ll j=fc.cycleNextIdxOf(c,i); //位置iの次の文字c位置(循環) なければ-1
ll j=fc.cyclePrevIdxOf(c,i); //位置iの前の文字c位置(循環) なければ-1
ll j=fc.ceilIdxOf(c,i); //位置i以降の文字c位置 なければ-1
ll j=fc.floorIdxOf(c,i); //位置i以前の文字c位置 なければ-1
ll j=fc.cycleCeilIdxOf(c,i); //位置i以降の文字c位置(循環) なければ-1
ll j=fc.cycleFloorIdxOf(c,i);//位置i以前の文字c位置(循環) なければ-1
ll nm=fc.numOf(c,l,r); //区間[l,r]の文字cの個数
ll j=fc.idxOf(c,r); //r番目の文字cの位置
fc.push_back(c); //末尾に文字c追加
fc.push_back(s); //string,vll等でまとめて末尾追加
fc.pop_back(); //末尾削除
*/
auto solve(
ll h,ll w,vector<string> S
){
S.reverse();
vll dp(w);
vll ini(w,INF);
LazySegmentTree<ll,ll> sgtini(ini,
[](ll x,ll y){ return min(x,y); }, //データ同士の合成関数
[](ll x,ll y){ return min(x,y); }, //データxに作用素yを作用させる関数
[](ll x,ll y){ return min(x,y); }, //作用素の合成関数
INF,INF);
rep(i,0,h-2){
findchar fc(S[i+1],'#');
LazySegmentTree<ll,ll> sgt=sgtini;
rep(j,0,w-1){
if (dp[j]>INF/2)continue;
ll L=fc.floorIdxOf('#',j)+1;
ll R=fc.ceilIdxOf ('#',j)-1;
if (R==-2) R=w-1;
chmax(L,j-dp[j]);
chmin(R,j+dp[j]);
if (L>R) continue;
sgt.set(L,R,dp[j]);
}
rep(j,0,w-1) dp[j]=sgt[j];
rep(j,1,w-1){
if (S[i+1][j]=='.') chmin(dp[j],dp[j-1]+1);
}
dep(j,w-2,0) if (S[i+1][j]=='.') chmin(dp[j],dp[j+1]+1);
}
for (auto&& e: dp){
if (e>INF/2) e=-1;
}
return dp;
}
ll binarysearch(ll ng,ll ok,function<bool(ll)> isok){
while (abs(ok-ng)>1){
ll x=(ng+ok)/2;
if (isok(x)) ok=x; else ng=x;
}
return ok;
}
dd binarysearchreal(dd ng,dd ok,function<bool(dd)> isok){
for (ll i=0;i<100;++i){
dd x=(ok+ng)/2.;
if (isok(x)) ok=x; else ng=x;
}
return ok;
}
ll binarysearchrank(ll r,ll xmin,ll xmax,function<ll(ll)> numOfLessThan){
//x以下の個数≧rとなる最小のxを得る
ll ng=xmin-1,ok=xmax;
while (abs(ok-ng)>1){
ll x=(ng+ok)/2;
if (numOfLessThan(x)>=r) ok=x; else ng=x;
}
return ok;
}
/*
・整数版 二分探索
. ng ok okでtrueを返すラムダ式
ll ans=binarysearch(-1,1000000010,[&](ll x)->bool{return x*x>n;});
・実数版 二分探索
. ng ok okでtrueを返すラムダ式
dd ans=binarysearchreal(0.,1000000000.,[&](dd x)->bool{return x*x>n;});
・r番目(1-origin)の値xを求める
. r番目↓ xの範囲 x以下の個数を返すラムダ式
ll x=binarysearchrank(r,xmin,xmax,[&](ll x){ return x以下の個数; });
*/
auto solve2(
ll h,ll w,vector<string> &S
){
auto isok=[&](ll P,ll k){//マス(0,k)スタート
vvll fd(h,vll(w,INF));
fd[0][k]=0;
rep(i,0,h-2){
//横に伸ばす
rep(j,1,w-1) if (S[i][j]=='.') chmin(fd[i][j],fd[i][j-1]+1);
dep(j,w-2,0) if (S[i][j]=='.') chmin(fd[i][j],fd[i][j+1]+1);
//P以下を下段の0に
rep(j,0,w-1){
if (S[i+1][j]=='.' and fd[i][j]<=P) fd[i+1][j]=0;
}
}
return any_of(ALL(fd[h-1]),[&](auto &x){return x==0;});
};
vll ans;
rep(k,0,w-1){
ll Pmin=binarysearch(-1,w,[&](ll P)->bool{
return isok(P,k);
});
if (Pmin==w) Pmin=-1;
ans.push_back(Pmin);
}
return ans;
}
void solvecomp(
ll h,ll w,vector<string> &S
){
auto coutans=[](auto ans){
/*
出力を書く
*/
each(e,ans) cout << e << '\n';
};
ll st1=timeget();
auto ans=solve(
h,w,S
);
coutans(ans);
cerr << timeget()-st1 <<"ms"<< '\n';
#if 0
cout << "- - - - -\n";
ll st2=timeget();
auto an2=solve2(
h,w,S
);
coutans(an2);
cerr << timeget()-st2 <<"ms"<< '\n';
cout << "================\n";
if (ans!=an2){
//if (true){
cout << "============ input =============\n";
/*
inputファイルの形式で吐き出す
*/
cout << pll(h,w) << '\n';
each(e,S) cout << e << '\n';
cout << "============ input end =========\n\n================\n";
getchar(); rep(i,0,10000000000) i++;//getchar()の代わり
}
#endif
}
void cin2solve(){
/*
cinからの入力を書く
*/
ll h,w;
cin >> h >> w;
vector<string> S;
rep(i,0,h-1){ string S__; cin>>S__; S.push_back(S__); }
solvecomp(
h,w,S
);
}
};//SolvingSpace
//////////////////////////////////////////
int main(){
#if 1
//SolvingSpace::labo();
SolvingSpace::cin2solve();
//SolvingSpace::generand();
#else
ll t; cin >> t;
rep(i,0,t-1){
SolvingSpace::cin2solve();
//SolvingSpace::generand();
}
#endif
cerr << timeget() <<"ms"<< '\n';
return 0;
}
hamamu