結果

問題 No.2411 Reverse Directions
ユーザー tailstails
提出日時 2023-08-12 01:46:24
言語 cLay
(20240104-1)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,272 bytes
コンパイル時間 2,730 ms
コンパイル使用メモリ 176,708 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-29 16:31:05
合計ジャッジ時間 4,519 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 5 ms
8,064 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 10 ms
10,880 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 12 ms
9,728 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 7 ms
7,936 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 5 ms
5,504 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 5 ms
5,504 KB
testcase_21 AC 5 ms
6,144 KB
testcase_22 AC 10 ms
8,704 KB
testcase_23 AC 8 ms
8,192 KB
testcase_24 AC 12 ms
9,984 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 4 ms
5,376 KB
testcase_28 AC 8 ms
7,296 KB
testcase_29 AC 12 ms
9,344 KB
testcase_30 AC 9 ms
7,936 KB
testcase_31 AC 9 ms
8,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

ll h,w,k,l,r;
char s[512][512];
char z[6d5];
ll d[512][512],e[][];
ll q[1d6];

void f(ll sy,ll sx,ll d[512][512]){
	d[sy][sx]=1;
	ll i=0,j=0;
	q[j++]=sy;
	q[j++]=sx;
	while(i<j){
		ll y=q[i++];
		ll x=q[i++];
		rep(a,4){
			ll y2=y-(a==0)+(a==1);
			ll x2=x-(a==2)+(a==3);
			if(y2>=0&&y2<h&&x2>=0&&x2<w&&s[y2][x2]=='.'&&!d[y2][x2]){
				d[y2][x2]=d[y][x]+1;
				q[j++]=y2;
				q[j++]=x2;
			}
		}
	}
}

void g(ll y,ll x,ll d[512][512],ll p,ll t){
	while(d[y][x]!=1){
		rep(a,4){
			ll y2=y-(a==0)+(a==1);
			ll x2=x-(a==2)+(a==3);
			if(y2>=0&&y2<h&&x2>=0&&x2<w&&d[y2][x2]==d[y][x]-1){
				y=y2;
				x=x2;
				z[p]="UDLR"[t<0?a^1:a];
				p+=t;
				break;
			}
		}
	}
}

{
	rd(h,w,k,l,r,s(h));
	f(0,0,d);
	f(h-1,w-1,e);
	if(r-l+1&1||h+w+k&1||!e[0][0]){
		wt("No");
		exit(0);
	}
	rep(y,h){
		rep(x,w){
			if(x+y+l&1&&d[y][x]&&d[y][x]-1<=l-1&&e[y][x]-1<=k-r&&(y>0&&y<h-1&&d[y-1][x]&&d[y+1][x]||x>0&&x<w-1&&d[y][x-1]&&d[y][x+1])){
				g(y,x,d,d[y][x]-2,-1);
				g(y,x,e,k-e[y][x]+1,1);
				ll p=d[y][x]-1;
				ll n=k-d[y][x]-e[y][x]+2>>1;
				if(y>0&&y<h-1&&d[y-1][x]&&d[y+1][x]){
					rep(n){
						z[p++]='D';
						z[p++]='U';
					}
				}else{
					rep(n){
						z[p++]='R';
						z[p++]='L';
					}
				}
				wt("Yes");
				wt(z);
				exit(0);
			}
		}
	}
	wt("No");
}
0