QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#792003#7516. Robot ExperimentAme_Rain_chanAC ✓14ms3972kbC++141.9kb2024-11-28 22:50:412024-11-28 22:50:49

Judging History

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

  • [2024-11-28 22:50:49]
  • 评测
  • 测评结果:AC
  • 用时:14ms
  • 内存:3972kb
  • [2024-11-28 22:50:41]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=30;
int n,a[N];
int st[60][60];
int can[60][60];
bool use[60][60];
int d[4][2]={
    {-1,0},{1,0},{0,1},{0,-1}
};
struct pt{
    int x,y;
}ans[60*60];int cnt;
//0:30
/*
void debug(int t){
    for(int i=1;i <= n;i++){
        cerr << ((t >> (i-1))&1);
    }
    cerr << "\n";
}
*/
int main(){
    //freopen("explore.in","r",stdin);
    //freopen("explore.out","w",stdout);

    scanf("%d",&n);
    for(int i=1;i <= n;i++){
        int x=getchar();
        while(x == ' ' || x == '\n') x=getchar();
        if(x == 'L') a[i]=0;
        else if(x == 'R') a[i]=1;
        else if(x == 'U') a[i]=2;
        else  a[i]=3;
    }
    for(int t=0;t < (1 << n);t++){
        int tag=t+1;
        int x=30,y=30;
        bool flag=true;
        for(int i=1;i <= n;i++){
            can[x][y]=tag;
            if(!((t >> (i-1))&1)){
                //debug(t);
                int dx=x+d[a[i]][0],dy=y+d[a[i]][1];
                if(can[dx][dy] == tag){
                    flag=false;
                    break;
                }
                if(st[dx][dy] != tag) st[dx][dy]=tag;
            } else {
                int dx=x+d[a[i]][0],dy=y+d[a[i]][1];
                if(st[dx][dy] == tag){
                    flag=false;
                    break;
                }
                x=dx,y=dy;
            }
        }
        if(flag) {
            //debug(t);
            use[x][y]=true;
        }
    }
    for(int i=30-n;i <= 30+n;i++){
        for(int j=30-n;j <= 30+n;j++){
            if(use[i][j]) ans[cnt++]={i-30,j-30};
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<cnt;i++) printf("%d %d\n",ans[i].x,ans[i].y);
    return 0;
}

/*
g++ explore.cpp -o explore -std=c++14 -O2 -static -Wall -Wextra -fsanitize=undefined
./explore < explore.in > explore.out
*/

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
RU

output:

4
0 0
0 1
1 0
1 1

result:

ok 5 lines

Test #2:

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

input:

4
LRUD

output:

4
0 -1
0 0
1 -1
1 0

result:

ok 5 lines

Test #3:

score: 0
Accepted
time: 7ms
memory: 3920kb

input:

20
LLLRLRLRLLLRLLRLRLLR

output:

8
-6 0
-5 0
-4 0
-3 0
-2 0
-1 0
0 0
1 0

result:

ok 9 lines

Test #4:

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

input:

1
D

output:

2
0 -1
0 0

result:

ok 3 lines

Test #5:

score: 0
Accepted
time: 7ms
memory: 3912kb

input:

20
UUUUUUUUUUUUUUUUUUUU

output:

21
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 10
0 11
0 12
0 13
0 14
0 15
0 16
0 17
0 18
0 19
0 20

result:

ok 22 lines

Test #6:

score: 0
Accepted
time: 7ms
memory: 3852kb

input:

20
LRUDDULRUDRLLRDURLUD

output:

22
-2 0
-2 1
-1 -2
-1 -1
-1 0
-1 1
-1 2
0 -2
0 -1
0 0
0 1
0 2
1 -2
1 -1
1 0
1 1
1 2
2 -2
2 -1
2 0
2 1
2 2

result:

ok 23 lines

Test #7:

score: 0
Accepted
time: 7ms
memory: 3952kb

input:

20
UUDUDUUDUDUDUDUDLLRL

output:

12
-2 -1
-2 0
-2 1
-2 2
-1 -1
-1 0
-1 1
-1 2
0 -1
0 0
0 1
0 2

result:

ok 13 lines

Test #8:

score: 0
Accepted
time: 8ms
memory: 3972kb

input:

20
DUUDDUDUUDUDDUUDUDDU

output:

3
0 -1
0 0
0 1

result:

ok 4 lines

Test #9:

score: 0
Accepted
time: 9ms
memory: 3912kb

input:

20
RUDLUULDRURLDURLDURR

output:

29
-3 3
-3 4
-2 2
-2 3
-2 4
-1 1
-1 2
-1 3
-1 4
0 -1
0 0
0 1
0 2
0 3
0 4
1 -1
1 0
1 1
1 2
1 3
2 -1
2 0
2 1
2 2
2 3
3 -1
3 0
3 1
3 2

result:

ok 30 lines

Test #10:

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

input:

20
DLDLDLDLLLDLLDLDLDLR

output:

108
-10 -8
-10 -7
-10 -6
-10 -5
-10 -4
-10 -3
-10 -2
-10 -1
-10 0
-9 -8
-9 -7
-9 -6
-9 -5
-9 -4
-9 -3
-9 -2
-9 -1
-9 0
-8 -8
-8 -7
-8 -6
-8 -5
-8 -4
-8 -3
-8 -2
-8 -1
-8 0
-7 -8
-7 -7
-7 -6
-7 -5
-7 -4
-7 -3
-7 -2
-7 -1
-7 0
-6 -8
-6 -7
-6 -6
-6 -5
-6 -4
-6 -3
-6 -2
-6 -1
-6 0
-5 -8
-5 -7
-5 -6
-5 -...

result:

ok 109 lines

Extra Test:

score: 0
Extra Test Passed