QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#333333#7751. Palindrome PathwullaaaWA 1ms3936kbC++141.4kb2024-02-19 20:15:362024-02-19 20:15:37

Judging History

你现在查看的是最新测评结果

  • [2024-02-19 20:15:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3936kb
  • [2024-02-19 20:15:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,cnt,a[35][35],s1,s2,t1,t2;
bool vis[35][35];
int step_x[4]={0,0,1,-1},step_y[4]={1,-1,0,0};
char s[4]={'R','L','D','U'};
string ans;
void check(int x,int y){
    if(!a[x][y]||vis[x][y]) return ;
    --cnt,vis[x][y]=true;
    for(int i=0;i<4;++i) check(x+step_x[i],y+step_y[i]);
}
void work(int k){
    for(int i=1;;++i){
        if(!a[t1+i*step_x[k]][t2+i*step_y[k]]){
            ans+=string(i-1,s[k^1])+string(i,s[k]);
            break;
        }
        if(!a[s1-i*step_x[k]][s2-i*step_y[k]]){
            ans+=string(i,s[k^1])+string(i,s[k]);
            break;
        }
    }
    s1+=step_x[k],s2+=step_y[k];
}
void solve(int k){
    vis[s1][s2]=true;
    if(k&&abs(s1-t1)+abs(s2-t2)<2){
        cout<<ans;
        if(s1==t1+1) putchar('L');
        if(s1==t1-1) putchar('R');
        if(s2==t2+1) putchar('U');
        if(s2==t2-1) putchar('D');
        reverse(begin(ans),end(ans));
        cout<<ans; exit(0);
    }
    for(int i=0;i<4;++i) if(a[s1+step_x[i]][s2+step_y[i]]&&!vis[s1+step_x[i]][s2+step_y[i]]) work(i),solve(k),work(i^1);
    
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i){ getchar(); for(int j=1;j<=m;++j) cnt+=(a[i][j]=getchar()-'0'); }
    scanf("%d%d%d%d",&s1,&s2,&t1,&t2);
    check(s1,s2);
    if(cnt) return puts("-1"),0;
    memset(vis,0,sizeof(vis)),solve(0);
    memset(vis,0,sizeof(vis)),solve(1);


    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3668kb

input:

2 2
11
11
1 1 2 2

output:

RDRLRDURLRRRLRUDRLRDR

result:

ok Valid Solution (Length = 21).

Test #2:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

2 2
10
01
1 1 2 2

output:

-1

result:

ok No Solution.

Test #3:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

1 1
1
1 1 1 1

output:


result:

ok Valid Solution (Length = 0).

Test #4:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

5 4
1111
1111
1111
1111
1111
4 2 4 2

output:

LLRRLLRRRUDDRLRLLRLLDUDDUULRLLRRLLRRRDDDUUURLRLLRLLDDDUUUULRLLRRLLRRRRLRLLRLLUDLRLLRRLLRRRUDDRLRLLRLLUDDUDDLRLLRRLLRRRDURLRLLLLRLRUDRRRLLRRLLRLDDUDDULLRLLRLRDDURRRLLRRLLRLDULLRLLRLRRRRLLRRLLRLUUUUDDDLLRLLRLRUUUDDDRRRLLRRLLRLUUDDUDLLRLLRLRDDURRRLLRRLL

result:

ok Valid Solution (Length = 250).

Test #5:

score: 0
Accepted
time: 0ms
memory: 3936kb

input:

5 5
11111
10101
11111
10101
11111
1 4 5 5

output:

RDDRLRRLLRRRLLLRRRRLLLLDDRRRRDUDRLRRLLDUDRRRLLLRRRRLLLLDUDDUUDDDUUUDDDDUUUURRDDDDDUUUURRRLLLRRRRLLLLDDRRRRDDDUUUDDDDUUUURLRDDRLRRLLRRRLLLRRRRLLLLDDRRRDRRRDDLLLLRRRRLLLRRRLLRRLRDDRLRUUUUDDDDUUUDDDRRRRDDLLLLRRRRLLLRRRUUUUDDDDDRRUUUUDDDDUUUDDDUUDDUDLLLLRRRRLLLRRRDUDLLRRLRDUDRRRRDDLLLLRRRRLLLRRRLLRRLRDDR

result:

ok Valid Solution (Length = 301).

Test #6:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

5 3
111
100
111
001
111
4 3 3 2

output:

DRLRLLLRLRRUURLRLLUULRLRRRLRLLDDLRLRRDDRLRLLLRLRRUUUUURRLRLLLRLRDDRRLRLDDLLRLRRRLRLUULLRLRUURRLRLLLRLRD

result:

ok Valid Solution (Length = 103).

Test #7:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

5 4
1001
1101
1111
0011
0010
2 2 1 1

output:

LUUDDRRRUUDDDLUUDDURUUUUDUUDDLLLUUUDRLLLRDUUULLLDDUUDUUUURUDDUULDDDUURRRDDUUL

result:

ok Valid Solution (Length = 77).

Test #8:

score: 0
Accepted
time: 0ms
memory: 3684kb

input:

5 3
101
111
100
111
100
4 1 2 2

output:

LRLRRRLRLLDUUULRLRRUDRLRLLUDDDLRLRRRLRLLDUUUDUUUDLLRLRRRLRLDDDULLRLRDURRLRLUUUDLLRLRRRLRL

result:

ok Valid Solution (Length = 89).

Test #9:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

5 5
01110
10110
11110
11011
11100
2 4 5 1

output:

LDLLRRRDLRLDULLLDLRDLLRRLLLRDULDDUUDDDUUUDLRLLRRDUDDUULLRRLLLRDLRLDLLRRRDLRLDULLLDRDLLLUDLRLDRRRLLDLRLDRLLLRRLLUUDDUDRRLLRLDUUUDDDUUDDLUDRLLLRRLLDRLDLLLUDLRLDRRRLLDL

result:

ok Valid Solution (Length = 165).

Test #10:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

5 3
011
111
110
111
011
3 1 2 1

output:

LRUUDDDLLRRUDLLRULLLRUULLRRULLRUDLLLRUUDDLLLDDUURLLLDURLLURRLLUURLLLURLLDURRLLDDDUURL

result:

ok Valid Solution (Length = 85).

Test #11:

score: 0
Accepted
time: 0ms
memory: 3696kb

input:

4 5
11111
11111
11111
11111
3 2 1 3

output:

LLRRLLRRRLLRRRUUUDDDRLRRLLRRLLLRRLLLUULRLLRRLLRRRLLRRRURLRRLLRRLLLRRLLLLRLLRRLLRRRLLRRRUDRLRRLLRRLLLRRLLLUUDDUUUDDDLRLLRRLLRRRLLRRRURLRRLLRRLLLLLRRLLRRRLLRRRUUUDDDRLRRLLRRLLLRRLLLUULRLLRRLRRLLRLUULLLRRLLLRRLLRRLRDDDUUURRRLLRRRLLRRLLLLLRRLLRRLRURRRLLRRRLLRRLLRLDDDUUUDDUULLLRRLLLRRLLRRLRDURRRLLRRRLLRR...

result:

ok Valid Solution (Length = 375).

Test #12:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

5 5
11111
10101
11111
10101
11111
2 5 1 1

output:

UUDDLLLLUUUDDDUUUUDDDDLRLLRRLLLRRRLLLLRRRRUUUUUDDDDLLUUUUUDDDDLLUUUULRLLRRLLLRRRLLLLRRRRLLUDULLUDUUDDLRLLRRLLLRRRLLLLRRRRUUUDDLLLLUUUDDDUUUUDDDDLRLLRRLLLRRRLLLLRRRRUUUUUDDDDLLUUUUUDDDDLLUUULUUULLDDDDUUUUULLDDDDUUUUURRRRLLLLRRRLLLRRLLRLDDDDUUUUDDDUUULLLLDDUUURRRRLLLLRRRLLLRRLLRLDDUUDULLUDULLRRRRLLLLR...

result:

ok Valid Solution (Length = 379).

Test #13:

score: 0
Accepted
time: 0ms
memory: 3692kb

input:

4 5
11111
10000
11111
00001
1 3 4 5

output:

RRLLLLDDRRRRDDULLLLDUDUURRRRLLLLDDRRRRRRRRRDDLLLLRRRRUUDUDLLLLUDDRRRRDDLLLLRR

result:

ok Valid Solution (Length = 77).

Test #14:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

3 5
10100
00010
00111
1 3 1 1

output:

-1

result:

ok No Solution.

Test #15:

score: 0
Accepted
time: 0ms
memory: 3700kb

input:

4 5
10001
11111
11100
11111
4 5 3 1

output:

LLLLDULRLLRRDDUULLRRRLLRRRDUUDLLLLDDUUUUDLRLLRRUDLLUDDLRLLRRLLRRRLLRRRLLLLLLLLLRRRLLRRRLLRRLLRLDDULLDURRLLRLDUUUUDDLLLLDUUDRRRLLRRRLLUUDDRRLLRLUDLLLL

result:

ok Valid Solution (Length = 149).

Test #16:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

3 5
11111
10100
11111
1 2 3 5

output:

RRRRLRRLLDDRRRLRRLLRRRLLLRRRRLLLLUUDDRRUURRRLLLRRRRLRRLLDDRDRDDLLRRLRRRRLLLRRRUURRDDUULLLLRRRRLLLRRRLLRRLRRRDDLLRRLRRRR

result:

ok Valid Solution (Length = 119).

Test #17:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

4 5
01110
10101
11011
10111
1 3 2 3

output:

-1

result:

ok No Solution.

Test #18:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

5 5
11111
11111
11111
11111
11111
1 3 5 2

output:

LLLRRRLLLRRRRDRLRLLRLLRLLDLRLLRRLLLRRRLLLRRRRDRLRLLRLLRLLDLRLLRRLLLRRRLLLRRRRRLRLLRLLRLLDULRLLRRLLLRRRLLLRRRRDDUURLRLLRLLRLLDDDUUUDDDDUUUULRRLLDLRLLRRLLLRRRLLLRRRRDDDDUUUURLRLLLLLRRRLLLRRRRDRLRLLRLLRLLDLRLLRRLLLRRRLLLRRRRDRLRLLRLLRLLRLLRLRDRRRRLLLRRRLLLRRLLRLDLLRLLRLLRLRDRRRRLLLRRRLLLLLRLRUUUUDDDDRR...

result:

ok Valid Solution (Length = 461).

Test #19:

score: -100
Wrong Answer
time: 0ms
memory: 3684kb

input:

5 5
11111
10101
11111
10101
11111
5 1 2 3

output:

RRRRDUDUULLLLUUUDDDDUUDUUDUURRRRUDDUULLUDDUULLUDUUDDRRUUUDDDDUURRUUUDDDUUUDDDDLLLLRRRRDUDUULLLLLUUDUDRRRRLLLLDDDDUUUDDDUUURRUUDDDDUUURRDDUUDULLUUDDULLUUDDURRRRUUDUUDUUDDDDUUULLLLUUDUDRRRR

result:

wrong answer End Point Is (2,1), Not (er = 2, ec = 3)