結果

問題 No.2411 Reverse Directions
ユーザー 👑 kmjpkmjp
提出日時 2023-08-11 21:52:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 2,446 bytes
コンパイル時間 2,211 ms
コンパイル使用メモリ 209,120 KB
実行使用メモリ 13,780 KB
最終ジャッジ日時 2024-04-29 12:46:45
合計ジャッジ時間 3,948 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 6 ms
13,056 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 19 ms
13,780 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 26 ms
11,392 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 10 ms
11,576 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 5 ms
8,192 KB
testcase_17 AC 10 ms
6,272 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 10 ms
6,784 KB
testcase_21 AC 10 ms
8,064 KB
testcase_22 AC 20 ms
10,880 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 27 ms
12,672 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 9 ms
5,888 KB
testcase_28 AC 15 ms
8,320 KB
testcase_29 AC 27 ms
10,544 KB
testcase_30 AC 18 ms
8,960 KB
testcase_31 AC 20 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int H,W,K,L,R;
string S[555];

ll D[2][555][555];
char from[2][555][555];
int fromdy[2][555][555];
int fromdx[2][555][555];
string A[2]={"RLDU","LRUD"};

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>K>>L>>R;
	FOR(y,H) cin>>S[y];
	
	if((R-L)%2==0) {
		cout<<"No"<<endl;
		return;
	}
	
	FOR(y,H) FOR(x,W) {
		D[0][y][x]=D[1][y][x]=1LL<<60;
	}
	D[0][0][0]=D[1][H-1][W-1]=0;
	queue<int> Q;
	Q.push(0);
	Q.push(H*W+(H-1)*W+W-1);
	while(Q.size()) {
		int id=Q.front()/H/W;
		int cy=Q.front()/W%H;
		int cx=Q.front()%W;
		Q.pop();
		FOR(i,4) {
			int dy[]={0,0,1,-1};
			int dx[]={1,-1,0,0};
			int ty=cy+dy[i];
			int tx=cx+dx[i];
			if(ty<0||ty>=H||tx<0||tx>=W||S[ty][tx]=='#') continue;
			if(D[id][ty][tx]==1LL<<60) {
				D[id][ty][tx]=D[id][cy][cx]+1;
				from[id][ty][tx]=A[id][i];
				fromdy[id][ty][tx]=-dy[i];
				fromdx[id][ty][tx]=-dx[i];
				Q.push(id*H*W+ty*W+tx);
			}
		}
	}
	
	FOR(y,H) FOR(x,W) {
		if(D[0][y][x]>L||(D[0][y][x]%2==L%2)) continue;
		if(D[1][y][x]>K-R||(D[1][y][x]%2!=(K-R)%2)) continue;
		int t=0;
		if(y&&y+1<H&&S[y-1][x]=='.'&&S[y+1][x]=='.') t=1;
		if(x&&x+1<W&&S[y][x-1]=='.'&&S[y][x+1]=='.') t=2;
		if(t==0) continue;
		
		int cy=y,cx=x;
		string S;
		while(cy||cx) {
			S+=from[0][cy][cx];
			int dy=fromdy[0][cy][cx];
			int dx=fromdx[0][cy][cx];
			cy+=dy;
			cx+=dx;
		}
		reverse(ALL(S));
		while(S.size()<K-D[1][y][x]) {
			if(t==1) S+="UD";
			if(t==2) S+="LR";
		}
		cy=y,cx=x;
		
		while(cy<H-1||cx<W-1) {
			S+=from[1][cy][cx];
			int dy=fromdy[1][cy][cx];
			int dx=fromdx[1][cy][cx];
			cy+=dy;
			cx+=dx;
		}
		cout<<"Yes"<<endl;
		cout<<S<<endl;
		return;
		
	}
	cout<<"No"<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0