Submission #74885131


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
string g[35];
int dx[5]={-1,1,0,0};
int dy[5]={0,0,-1,1};
char dc[5]={'U','D','L','R'};
int h,w;
int sx,sy,gx,gy;
string ans;
bool f=false;
bool vis[35][35];
void dfs(int x,int y,int pd,string s){
	if(f)return;
	if(x==gx&&y==gy){
		ans=s;
		f=true;
		return;
	}
	if(vis[x][y]) return;
	vis[x][y]=true;
	for(int d=0;d<4;d++){
		int nx=x+dx[d],ny=y+dy[d];
		if(nx<1||nx>h||ny<1||ny>w||g[nx][ny]=='#')continue;
		if(pd!=-1){
			if(g[x][y]=='o'&&d!=pd)continue;
			if(g[x][y]=='x'&&d==pd)continue;
		}
		dfs(nx,ny,d,s+dc[d]);
	}
	vis[x][y]=false;
}
int main(){
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		cin>>g[i];
		g[i]=' '+g[i];
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(g[i][j]=='S'){
				sx=i;
				sy=j;
			}else if(g[i][j]=='G'){
				gx=i;
				gy=j;
			}
		}
	}
	dfs(sx,sy,-1,"");
	if(f){
		cout<<"Yes"<<endl<<ans;
	}else{
		cout<<"No";
	}
}

Submission Info

Submission Time
Task D - Go Straight
User ywrow
Language C++23 (GCC 15.2.0)
Score 0
Code Size 953 Byte
Status RE
Exec Time 99 ms
Memory 3556 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 425
Status
AC × 2
WA × 1
AC × 4
WA × 1
RE × 41
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3496 KiB
example_01.txt WA 1 ms 3512 KiB
example_02.txt AC 1 ms 3420 KiB
hand_00.txt RE 99 ms 3404 KiB
hand_01.txt RE 96 ms 3332 KiB
hand_02.txt RE 96 ms 3192 KiB
hand_03.txt RE 97 ms 3460 KiB
hand_04.txt AC 1 ms 3468 KiB
hand_05.txt RE 98 ms 3324 KiB
hand_06.txt RE 98 ms 3252 KiB
hand_07.txt RE 97 ms 3428 KiB
hand_08.txt RE 97 ms 3260 KiB
hand_09.txt AC 1 ms 3400 KiB
random_00.txt RE 97 ms 3260 KiB
random_01.txt RE 98 ms 3388 KiB
random_02.txt RE 96 ms 3428 KiB
random_03.txt RE 96 ms 3444 KiB
random_04.txt RE 97 ms 3380 KiB
random_05.txt RE 97 ms 3268 KiB
random_06.txt RE 97 ms 3324 KiB
random_07.txt RE 97 ms 3404 KiB
random_08.txt RE 95 ms 3268 KiB
random_09.txt RE 97 ms 3388 KiB
random_10.txt RE 97 ms 3320 KiB
random_11.txt RE 96 ms 3388 KiB
random_12.txt RE 95 ms 3240 KiB
random_13.txt RE 94 ms 3324 KiB
random_14.txt RE 95 ms 3240 KiB
random_15.txt RE 95 ms 3192 KiB
random_16.txt RE 96 ms 3464 KiB
random_17.txt RE 95 ms 3260 KiB
random_18.txt RE 95 ms 3300 KiB
random_19.txt RE 97 ms 3388 KiB
random_20.txt RE 99 ms 3272 KiB
random_21.txt RE 95 ms 3372 KiB
random_22.txt RE 95 ms 3464 KiB
random_23.txt RE 95 ms 3428 KiB
random_24.txt RE 95 ms 3276 KiB
random_25.txt RE 95 ms 3556 KiB
random_26.txt RE 96 ms 3252 KiB
random_27.txt RE 96 ms 3260 KiB
random_28.txt RE 98 ms 3316 KiB
random_29.txt RE 97 ms 3240 KiB
random_30.txt RE 97 ms 3444 KiB
random_31.txt RE 97 ms 3368 KiB
random_32.txt RE 94 ms 3264 KiB