結果
問題 | No.2411 Reverse Directions |
ユーザー | eQe |
提出日時 | 2023-08-11 23:19:20 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 8,597 bytes |
コンパイル時間 | 7,481 ms |
コンパイル使用メモリ | 336,160 KB |
実行使用メモリ | 15,008 KB |
最終ジャッジ日時 | 2024-11-18 18:42:41 |
合計ジャッジ時間 | 8,169 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 10 ms
8,548 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 11 ms
9,728 KB |
testcase_08 | AC | 3 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 26 ms
15,008 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 30 ms
10,316 KB |
testcase_13 | AC | 3 ms
5,248 KB |
testcase_14 | AC | 10 ms
6,684 KB |
testcase_15 | AC | 5 ms
5,516 KB |
testcase_16 | AC | 3 ms
5,248 KB |
testcase_17 | AC | 11 ms
6,072 KB |
testcase_18 | AC | 7 ms
5,744 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 9 ms
5,376 KB |
testcase_21 | AC | 4 ms
5,248 KB |
testcase_22 | AC | 21 ms
9,256 KB |
testcase_23 | AC | 3 ms
5,248 KB |
testcase_24 | AC | 27 ms
9,088 KB |
testcase_25 | AC | 3 ms
5,248 KB |
testcase_26 | AC | 3 ms
5,248 KB |
testcase_27 | AC | 3 ms
5,248 KB |
testcase_28 | AC | 19 ms
9,820 KB |
testcase_29 | AC | 30 ms
12,248 KB |
testcase_30 | AC | 21 ms
10,496 KB |
testcase_31 | AC | 4 ms
5,248 KB |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> #define eb emplace_back #define all(a) (a).begin(),(a).end() #define done(...) return pp(__VA_ARGS__) #define RD(T,...) T __VA_ARGS__;li(__VA_ARGS__) #define LL(...) RD(ll,__VA_ARGS__) #define VE(a,...) auto a=vec(__VA_ARGS__) #define JO(a,b) a##b #define jo(a,b) JO(a,b) #define uqsymb(a) jo(a,__LINE__) #define FE(v,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):v) #define FO(n) for(ll uqsymb(i)=n;uqsymb(i)-->0;) #define FOR(i,...) for(auto[i,i##O,i##E]=rng(0,__VA_ARGS__);i<i##O;i+=i##E) #define fe(v,...) FE(v,__VA_ARGS__) #define fo(i,...) FO##__VA_OPT__(R)(i __VA_OPT__(,__VA_ARGS__)) #define of(i,...) for(auto[i,i##O,i##E]=rng(1,__VA_ARGS__);i>=i##O;i-=i##E) using std::cin,std::cout,std::begin,std::end,std::rbegin; using std::swap,std::move,std::abs,std::prev,std::next; using std::tuple,std::bitset,std::minmax,std::get; using vo=void;using bo=bool; vo solve(); using is=std::istream;using os=std::ostream; using dd=long double;using ll=long long;using ull=unsigned long long; using lll=__int128_t;using ulll=__uint128_t;using str=std::string; using namespace atcoder;using ml=modint;auto&operator<<(os&o,const ml&x){return o<<x.val();} constexpr ll oo=3e18; constexpr ll dx[]{-1,0,1,0,-1,1,1,-1},dy[]{0,-1,0,1,-1,-1,1,1}; constexpr char sp=32; constexpr char nl=10; auto yes(bo y){return y?"Yes":"No";} auto no(){return yes(0);} auto rng(bo s,ll a,ll b=oo,ll c=1){if(b==oo)b=a,(s?b:a)=0;return tuple{a-s,b,c};} bo odd(ll x){return x&1;} bo eve(ll x){return~x&1;} ll pw2(ll n){return 1LL<<n;} template<class T>bo at2(T x,ll i){return x>>i&1;} template<class T,class U,class V>bo in(T l,U m,V r){return l<=m&&m<r;} template<class T>T zz(T x){return x<0?-x:x;} template<class T>ll len(const T&a){return a.size();} struct edg{ ll t,w; edg(){} edg(ll t,ll w=1):t(t),w(w){} friend os&operator<<(os&o,const edg&e){return o<<e.t<<sp<<e.w;} }; template<class A,class B=A>struct cp{ A a={};B b={}; cp(){} cp(A a,B b):a(a),b(b){} cp(std::pair<A,B>p):a(p.first),b(p.second){} bo operator==(const cp&c)const{return a==c.a&&b==c.b;} bo operator<(const cp&c)const{return a!=c.a?a<c.a:b<c.b;} bo operator>(const cp&c)const{return a!=c.a?a>c.a:b>c.b;} friend is&operator>>(is&i,cp&c){return i>>c.a>>c.b;} friend os&operator<<(os&o,const cp&c){return o<<c.a<<sp<<c.b;} };using cl=cp<ll>; template<class A,class B=A,class C=A>struct tr{ A a={};B b={};C c={}; tr(){} tr(A a,B b,C c):a(a),b(b),c(c){} bo operator==(const tr&t)const{return a==t.a&&b==t.b&&c==t.c;} auto operator<(const tr&t)const{return a!=t.a?a<t.a:b!=t.b?b<t.b:c<t.c;} friend is&operator>>(is&i,tr&t){return i>>t.a>>t.b>>t.c;} friend os&operator<<(os&o,const tr&t){return o<<t.a<<sp<<t.b<<sp<<t.c;} };using tl=tr<ll>; template<class T>T&rv(T&a){reverse(all(a));return a;} template<class T>decltype(auto)rb(T&a){return*rbegin(a);} template<class T>auto pot(T&a){auto r=a.top();a.pop();return r;} template<class T>struct deq:std::deque<T>{ using std::deque<T>::deque; deq(const std::vector<T>&a={}){fe(a,e)this->eb(e);} friend os&operator<<(os&o,const deq&q){fe(q,e)o<<e<<str(&e!=&q.back(),sp);return o;} }; template<class V>struct ve; template<class V>constexpr bo isv=0; template<class V>constexpr bo isv<ve<V>> =1; template<class V>constexpr bo isv<std::vector<V>> =1; template<class V>auto rawv(V){if constexpr(isv<V>)return rawv(V(1)[0]);else return V();} template<class V>struct ve:std::vector<V>{ using std::vector<V>::vector; using T=decltype(rawv(V())); template<class U>ve(const std::vector<U>&v={}){fe(v,e)this->eb(e);} auto&operator+=(const ve&u){auto&v=*this;fo(i,len(v))v[i]+=u[i];return v;} auto&operator-=(const ve&u){auto&v=*this;fo(i,len(v))v[i]-=u[i];return v;} auto&operator^=(const ve&u){fe(u,e)this->eb(e);return*this;} auto&operator+=(const T&x){auto&v=*this;fe(v,e)e+=x;return v;} auto&operator-=(const T&x){auto&v=*this;fe(v,e)e-=x;return v;} auto&operator*=(const T&x){auto&v=*this;fe(v,e)e*=x;return v;} template<size_t n>auto&operator+=(const bitset<n>&a){fo(i,n)(*this)[i]+=a[i];return*this;} template<size_t n>auto&operator-=(const bitset<n>&a){fo(i,n)(*this)[i]-=a[i];return*this;} auto operator+(const ve&u){return ve(*this)+=u;} auto operator-(const ve&u){return ve(*this)-=u;} auto operator^(const ve&u){return ve(*this)^=u;} auto operator+(const T&x){return ve(*this)+=x;}auto&operator++(){return*this+=1;} auto operator-(const T&x){return ve(*this)-=x;}auto&operator--(){return*this-=1;} auto operator*(const T&x){return ve(*this)*=x;}auto operator-(){return ve(*this)*=-1;} auto lower_bound(const V&x)const{return std::lower_bound(all(*this),x);} auto upper_bound(const V&x)const{return std::upper_bound(all(*this),x);} auto de(const str&b="a"){std::conditional_t<isv<V>,ve<str>,str>r;fe(*this,e)if constexpr(isv<V>)r.eb(e.de(b));else r+=len(b)==1?e+b[0]:b[e];return r;} }; template<class T=ll,size_t n,size_t i=0>auto vec(const ll(&s)[n],T x={}){if constexpr(n==i+1)return ve<T>(s[i],x);else{auto X=vec<T,n,i+1>(s,x);return ve<decltype(X)>(s[i],X);}} template<ll n,class...A>vo setsize(const ll(&l)[n],A&...a){((a=vec(l,rawv(a))),...);} template<class T>using vve=ve<ve<T>>;using vl=ve<ll>;using vvl=vve<ll>; using gl=ve<ve<ll>>;using ge=ve<ve<edg>>; struct io{io(){cin.tie(0)->sync_with_stdio(0); cout<<std::fixed<<std::setprecision(15);std::cerr<<nl;}}io; os&operator<<(os&o,const ulll&x){return(x<10?o:o<<x/10)<<ll(x%10);} os&operator<<(os&o,const lll&x){return o<<str(x<0,'-')<<ulll(zz(x));} template<size_t n>os&operator<<(os&o,const bitset<n>&b){fo(i,n)o<<b[i];return o;} template<class...A>os&operator<<(os&o,const tuple<A...>&t){ apply([&](const auto&...a){ll i=0;(((o<<a<<str(++i!=sizeof...(a),sp))),...);},t);return o;} template<class V>os&operator<<(os&o,const std::vector<V>&v){fe(v,e)o<<e<<str(&e!=&rb(v),isv<V>?nl:sp);return o;} template<char c=sp,class...A>vo pp(const A&...a){ll i=0;((cout<<a<<str(++i!=sizeof...(a),c)),...);cout<<nl;} template<class V>is&operator>>(is&i,std::vector<V>&v){fe(v,e)i>>e;return i;} template<class...A>vo li(A&...a){(cin>>...>>a);} vl sien(const str&b="a"){str s;li(s);vl r;fe(s,e)r.eb(len(b)==1?e-b[0]:b.find_first_of(e));return r;} vvl sien(ll n,const str&b="a"){vvl r;fo(n)r.eb(sien(b));return r;} template<class F>struct rec:F{rec(F&&f):F(std::forward<F>(f)){}template<class...A>decltype(auto)operator()(A&&...a)const{return F::operator()(*this,std::forward<A>(a)...);}}; vve<ll>bfs_on_grid(const vve<ll>&g,ll sx=0,ll sy=0){ ll h=len(g),w=len(g[0]); vve<ll>d(h,ve<ll>(w,oo));d[sx][sy]=0; deq<cl>q{{sx,sy}}; while(len(q)){ auto[x,y]=q.front();q.pop_front(); fo(k,4){ ll nx=x+dx[k],ny=y+dy[k]; if(nx<0||ny<0||nx>=h||ny>=w)continue; if(g[nx][ny])continue; if(d[nx][ny]==oo)d[nx][ny]=d[x][y]+1,q.eb(nx,ny); } } return d; } int main(){ll T=1;fo(T)solve();} vo solve(){ LL(H,W,K,L,R); vvl s=sien(H,".#"); if(odd(H+W-2+K))done(no()); if(odd(R-L+1))done(no()); VE(safe,{H,W},short()); fo(i,H)fo(j,W)if(!s[i][j]){ ll t=0; fo(k,4){ ll ni=i+dx[k],nj=j+dy[k]; if(!in(0,ni,H)||!in(0,nj,W))continue; if(s[ni][nj])continue; t|=pw2(k); } if(at2(t,0)&&at2(t,2))safe[i][j]=1; if(at2(t,1)&&at2(t,3))safe[i][j]=2; } vvl dist1=bfs_on_grid(s,0,0); vvl dist2=bfs_on_grid(s,H-1,W-1); if(dist1[H-1][W-1]==oo)done(no()); fo(i,H)fo(j,W)if(safe[i][j]){ if(dist1[i][j]<L&&dist2[i][j]<=K-R&&eve(i+j+L-1)){ vl res; ll cx=i,cy=j; while(cx||cy){ fo(k,4){ ll nx=cx+dx[k],ny=cy+dy[k]; if(!in(0,nx,H)||!in(0,ny,W))continue; if(s[nx][ny])continue; if(dist1[nx][ny]+1==dist1[cx][cy]){ cx=nx,cy=ny; res.eb((k+2)%4); break; } } } rv(res); while(len(res)<R){ if(safe[i][j]==1)res.eb(0),res.eb(2); if(safe[i][j]==2)res.eb(1),res.eb(3); } cx=i,cy=j; while(cx!=H-1||cy!=W-1){ fo(k,4){ ll nx=cx+dx[k],ny=cy+dy[k]; if(!in(0,nx,H)||!in(0,ny,W))continue; if(s[nx][ny])continue; if(dist2[nx][ny]+1==dist2[cx][cy]){ cx=nx,cy=ny; res.eb(k); break; } } } fo(k,4){ ll nx=H-1+dx[k],ny=W-1+dy[k]; if(!in(0,nx,H)||!in(0,ny,W))continue; if(s[nx][ny])continue; while(len(res)<K)res.eb(k),res.eb((k+2)%4); break; } pp(yes(1)); done(res.de("ULDR")); } } pp(no()); }