提出 #74873834
ソースコード 拡げる
#include<bits/stdc++.h>
#define XAERIC666
// #define int long long
#define pii pair<int,int>
#define fi first
#define se second
#ifndef XAERIC666
#define xaeric(...) {fprintf(stderr,__VA_ARGS__);fflush(stderr);}
#else
#define xaeric(...) 114514
#endif
int read(){
int x=0,f=1;
char c=getchar();
while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
while('0'<=c&&c<='9'){x=x*10+c-48;c=getchar();}
return x*f;
}
// void in(int*a,int n){for(int i=1;i<=n;i++)a[i]=read();}
// void out(int*a,int n){for(int i=1;i<=n;i++)printf("%lld%c",a[i]," \n"[i==n]);}
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define _rep(i,a,b) for(int i=(b);i>=(a);--i)
#define YES puts("YES");
#define NO puts("NO");
void chmax(auto&a,auto b){if(a<b)a=b;}
void chmin(auto&a,auto b){if(a<b)a=b;}
using namespace std;
const int P=998244353;
const int N=1005;
const int NN=N*N*4,M=4*NN;
struct gph{
int to[M],nx[M],hd[NN],t=1,w[M];
void add(int u,int v,int k){
to[++t]=v,nx[t]=hd[u],hd[u]=t,w[t]=k;
}
}g;
int n,m,sy,sx,ey,ex;
char mp[N][N];
int dy[5]={1,0,-1,0};
int dx[5]={0,1,0,-1};
int fd[5]={2,3,0,1};
int hx(int y,int x,int l){
return l*n*m+(y-1)*m+x;
}
int v[NN],lst[NN],pre[NN];
void solve(){
n=read(),m=read();
for(int i=1;i<=n;i++){
scanf("%s",mp[i]+1);
for(int j=1;j<=m;j++){
if(mp[i][j]=='S'){
sy=i;
sx=j;
}
else if(mp[i][j]=='G'){
ey=i;
ex=j;
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(mp[i][j]=='#'){
continue;
}
for(int k=0;k<4;k++){
int ny=i+dy[k];
int nx=j+dx[k];
if(ny<1||ny>n){
continue;
}
if(nx<1||nx>m){
continue;
}
if(mp[ny][nx]=='#'){
continue;
}
if(mp[i][j]=='.'||mp[i][j]=='S'){
for(int l=0;l<4;l++){
g.add(hx(i,j,l),hx(ny,nx,fd[k]),k);
}
}
else if(mp[i][j]=='o'){
g.add(hx(i,j,fd[k]),hx(ny,nx,fd[k]),k);
}
else if(mp[i][j]=='x'){
for(int l=0;l<4;l++){
if(l!=fd[k]){
g.add(hx(i,j,l),hx(ny,nx,fd[k]),k);
}
}
}
}
}
}
queue<int>q;
q.push(hx(sy,sx,1));
q.push(hx(sy,sx,2));
q.push(hx(sy,sx,3));
q.push(hx(sy,sx,0));
v[hx(sy,sx,1)]=1;
v[hx(sy,sx,2)]=1;
v[hx(sy,sx,3)]=1;
v[hx(sy,sx,0)]=1;
while(q.size()){
auto u=q.front();
// xaeric(" %lld\n",u);
q.pop();
for(int i=g.hd[u];i;i=g.nx[i]){
if(!v[g.to[i]]){
q.push(g.to[i]);
// xaeric(" ! %lld\n",g.to[i]);
v[g.to[i]]=1;
lst[g.to[i]]=g.w[i];
pre[g.to[i]]=u;
}
}
}
int ans=0;
if(v[hx(ey,ex,1)]){
ans=hx(ey,ex,1);
}
if(v[hx(ey,ex,2)]){
ans=hx(ey,ex,2);
}
if(v[hx(ey,ex,3)]){
ans=hx(ey,ex,3);
}
if(v[hx(ey,ex,0)]){
ans=hx(ey,ex,0);
}
if(!ans){
puts("No");
return;
}
puts("Yes");
vector<int>aa;
// aa.push_back();
while(1){
// xaeric(" %lld %lld\n",ans,pre[ans]);
aa.push_back(lst[ans]);
ans=pre[ans];
if(ans==hx(sy,sx,1)){
break;
}
if(ans==hx(sy,sx,2)){
break;
}
if(ans==hx(sy,sx,3)){
break;
}
if(ans==hx(sy,sx,0)){
break;
}
}
// xaeric("%lld %lld %lld %lld",hx(sy,sx,0),hx(sy,sx,1),hx(sy,sx,2),hx(sy,sx,3));
reverse(aa.begin(),aa.end());
for(auto i:aa){
if(i==0){
printf("D");
}
else if(i==1){
printf("R");
}
else if(i==2){
printf("U");
}
else{
printf("L");
}
}
puts("");
}
signed main(){
int TTTT=1;
// int TTTT=read();
while(TTTT--){
solve();
}
}
提出情報
| 提出日時 |
|
| 問題 |
D - Go Straight |
| ユーザ |
Xaeric |
| 言語 |
C++23 (GCC 15.2.0) |
| 得点 |
425 |
| コード長 |
3862 Byte |
| 結果 |
AC |
| 実行時間 |
263 ms |
| メモリ |
254560 KiB |
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
425 / 425 |
| 結果 |
|
|
| セット名 |
テストケース |
| 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 |
| ケース名 |
結果 |
実行時間 |
メモリ |
| example_00.txt |
AC |
1 ms |
3876 KiB |
| example_01.txt |
AC |
1 ms |
3816 KiB |
| example_02.txt |
AC |
1 ms |
3864 KiB |
| hand_00.txt |
AC |
263 ms |
254560 KiB |
| hand_01.txt |
AC |
41 ms |
79040 KiB |
| hand_02.txt |
AC |
157 ms |
122456 KiB |
| hand_03.txt |
AC |
155 ms |
122244 KiB |
| hand_04.txt |
AC |
1 ms |
3740 KiB |
| hand_05.txt |
AC |
259 ms |
254268 KiB |
| hand_06.txt |
AC |
76 ms |
118172 KiB |
| hand_07.txt |
AC |
259 ms |
254560 KiB |
| hand_08.txt |
AC |
3 ms |
4776 KiB |
| hand_09.txt |
AC |
1 ms |
3776 KiB |
| random_00.txt |
AC |
54 ms |
86632 KiB |
| random_01.txt |
AC |
150 ms |
133656 KiB |
| random_02.txt |
AC |
138 ms |
124696 KiB |
| random_03.txt |
AC |
53 ms |
85292 KiB |
| random_04.txt |
AC |
143 ms |
133432 KiB |
| random_05.txt |
AC |
112 ms |
112288 KiB |
| random_06.txt |
AC |
52 ms |
79660 KiB |
| random_07.txt |
AC |
51 ms |
78912 KiB |
| random_08.txt |
AC |
125 ms |
122856 KiB |
| random_09.txt |
AC |
131 ms |
128488 KiB |
| random_10.txt |
AC |
109 ms |
107556 KiB |
| random_11.txt |
AC |
121 ms |
115364 KiB |
| random_12.txt |
AC |
123 ms |
116776 KiB |
| random_13.txt |
AC |
45 ms |
71076 KiB |
| random_14.txt |
AC |
121 ms |
114936 KiB |
| random_15.txt |
AC |
35 ms |
50212 KiB |
| random_16.txt |
AC |
25 ms |
30468 KiB |
| random_17.txt |
AC |
5 ms |
9312 KiB |
| random_18.txt |
AC |
27 ms |
36408 KiB |
| random_19.txt |
AC |
31 ms |
39528 KiB |
| random_20.txt |
AC |
25 ms |
28736 KiB |
| random_21.txt |
AC |
27 ms |
44580 KiB |
| random_22.txt |
AC |
25 ms |
29536 KiB |
| random_23.txt |
AC |
29 ms |
35768 KiB |
| random_24.txt |
AC |
43 ms |
60124 KiB |
| random_25.txt |
AC |
15 ms |
29032 KiB |
| random_26.txt |
AC |
27 ms |
32660 KiB |
| random_27.txt |
AC |
99 ms |
93848 KiB |
| random_28.txt |
AC |
28 ms |
36016 KiB |
| random_29.txt |
AC |
23 ms |
46308 KiB |
| random_30.txt |
AC |
73 ms |
88104 KiB |
| random_31.txt |
AC |
63 ms |
81300 KiB |
| random_32.txt |
AC |
35 ms |
47528 KiB |