結果

問題 No.2411 Reverse Directions
ユーザー TKTYITKTYI
提出日時 2023-08-11 22:17:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,677 bytes
コンパイル時間 4,881 ms
コンパイル使用メモリ 274,656 KB
実行使用メモリ 10,832 KB
最終ジャッジ日時 2024-04-29 13:16:43
合計ジャッジ時間 9,053 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 3 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 3 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
5,376 KB
testcase_20 WA -
testcase_21 AC 9 ms
5,888 KB
testcase_22 WA -
testcase_23 AC 3 ms
5,376 KB
testcase_24 WA -
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 7 ms
5,376 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 16 ms
6,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef pair<ll,ll> pi;
typedef pair<ll,pi> ppi;
typedef pair<ll,ppi> pppi;
typedef pair<ll,pppi> ppppi;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,l,r) for(ll i=r-1;i>=l;i--)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define F first
#define S second
#define BS(A,x) binary_search(ALL(A),x)
#define LB(A,x) (ll)(lower_bound(ALL(A),x)-A.begin())
#define UB(A,x) (ll)(upper_bound(ALL(A),x)-A.begin())
#define COU(A,x) (UB(A,x)-LB(A,x))
#define sz(c) ((ll)(c).size())
/*
#include<boost/multiprecision/cpp_int.hpp>
namespace mp=boost::multiprecision;
using Bint=mp::cpp_int;
*/
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.F<<" "<<p.S;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.F>>p.S;return is;}
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){REP(i,sz(v))os<<v[i]<<(i+1!=sz(v)?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;}
ld dist(ld x1,ld y1,ld x2,ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
//*
using mint=modint998244353;
const ll mod=998244353;
const ld EPS=1e-8;
//*/
/*
using mint=modint1000000007;
const ll mod=1000000007;
//*/
//using mint=modint;
//*
typedef vector<mint> vm;
typedef vector<vm> vvm;
typedef vector<vvm> vvvm;
typedef vector<vvvm> vvvvm;
ostream&operator<<(ostream&os,mint&a){os<<a.val();return os;}
//*/
vector<pi>M={pi(0,1),pi(0,-1),pi(1,0),pi(-1,0)};
string dir="RLDU";
int main(){
  ll H,W,K,L,R;cin>>H>>W>>K>>L>>R;
  vector<string>S(H);
  cin>>S;
  if((R-L+1)%2){cout<<"No"<<endl;return 0;}
  vector<vector<ll>>D(H,vector<ll>(W,1e18));
  D[0][0]=0;
  queue<pi>Q;
  Q.emplace(pi(0,0));
  while(sz(Q)){
  	ll x=Q.front().F,y=Q.front().S;Q.pop();
  	for(auto[dx,dy]:M){
  		if(x+dx>=0&&x+dx<H&&y+dy>=0&&y+dy<W&&S[x+dx][y+dy]!='#'&&chmin(D[x+dx][y+dy],D[x][y]+1))Q.emplace(pi(dx+x,dy+y));
  	}
  }
  auto D1=D;
  REP(i,H)REP(j,W)D[i][j]=1e18;
  D[H-1][W-1]=0;
  Q.emplace(pi(H-1,W-1));
  while(sz(Q)){
  	ll x=Q.front().F,y=Q.front().S;Q.pop();
  	for(auto[dx,dy]:M){
  		if(x+dx>=0&&x+dx<H&&y+dy>=0&&y+dy<W&&S[x+dx][y+dy]!='#'&&chmin(D[x+dx][y+dy],D[x][y]+1))Q.emplace(pi(dx+x,dy+y));
  	}
  }
  auto D2=D;
  REP(i,H)REP(j,W)if(D1[i][j]<L&&(L-D1[i][j])%2){
  	bool l,r;
  	if(i&&S[i-1][j]!='#'&&i+1<H&&S[i+1][j]!='#')l=1;
  	if(j&&S[i][j-1]!='#'&&j+1<W&&S[i][j+1]!='#')r=1;
  	if(!(l||r))continue;
  	if(D2[i][j]<=K-R&&(D2[i][j]-K+R)%2==0){
  		cout<<"Yes"<<endl;
  		string ans;
  		{
  			ll x=i,y=j;
  			while(x!=0||y!=0){
  				REP(i,4){
  					ll dx=M[i].F,dy=M[i].S;
  					if(x+dx>=0&&x+dx<H&&y+dy>=0&&y+dy<W&&D1[x+dx][y+dy]==D1[x][y]-1){x+=dx;y+=dy;ans+=dir[i^1];}
  				}
  			}
  			reverse(ALL(ans));
  		}
  		//D1[i][j]回
  		REP(_,K-D2[i][j]-D1[i][j]){
  			if(l)ans+=(_%2?'U':'D');
  			else ans+=(_%2?'L':'R');
  		}
  		//回
  		{
  			ll x=i,y=j;
  			while(x!=H-1||y!=W-1){
  				REP(i,4){
  					ll dx=M[i].F,dy=M[i].S;
  					if(x+dx>=0&&x+dx<H&&y+dy>=0&&y+dy<W&&D2[x+dx][y+dy]==D2[x][y]-1){x+=dx;y+=dy;ans+=dir[i];}
  				}
  			}
  		}
  		cout<<ans<<endl;
  		return 0;
  	}
  }
  cout<<"No"<<endl;
  return 0;
}
0