QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#237428#7516. Robot Experimentfzj2007AC ✓106ms3944kbC++171.7kb2023-11-04 14:07:172023-11-04 14:07:17

Judging History

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

  • [2023-11-04 14:07:17]
  • 评测
  • 测评结果:AC
  • 用时:106ms
  • 内存:3944kb
  • [2023-11-04 14:07:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
    x=0;
    char ch=getchar();
    bool flag=0;
    while(ch>'9'||ch<'0') flag=flag||ch=='-',ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    x=flag?-x:x;
}
template<typename T,typename ...Args>inline void read(T &x,Args &...args){
    read(x),read(args...);
}
template<typename T>inline void prt(T x){
    if(x>9) prt(x/10);
    putchar(x%10+'0');
}
template<typename T>inline void put(T x){
    if(x<0) putchar('-'),x=-x;
    prt(x);
}
template<typename T>inline void put(char ch,T x){
    put(x),putchar(ch);
}
template<typename T,typename ...Args>inline void put(char ch,T x,Args ...args){
    put(ch,x),put(ch,args...);
}
#define N 23
#define M (1<<20|10)
int n,mp[N<<1][N<<1],w[N];
char st[N];
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
int X[N],Y[N];
pair<int,int> ans[M];
int num;
int main(){
	read(n);
	scanf("%s",st+1);
	for(int i=1;i<=n;i++){
		if(st[i]=='L') w[i]=0;
		else if(st[i]=='R') w[i]=1;
		else if(st[i]=='D') w[i]=2;
		else w[i]=3;
	}
	memset(mp,-1,sizeof(mp));
	for(int s=0;s<(1<<n);s++){
		int x=0,y=0,flag=1,tp=0;
		X[++tp]=0,Y[tp]=0,mp[N][N]=0;
		for(int i=1;i<=n;i++){
			int tx=x+dx[w[i]],ty=y+dy[w[i]];
			if(s>>(i-1)&1){
				if(mp[tx+N][ty+N]==1) flag=0;
				else mp[tx+N][ty+N]=0;
				x=tx,y=ty;
			}else{
				if(mp[tx+N][ty+N]==0) flag=0;
				else mp[tx+N][ty+N]=1;
			}
			X[++tp]=tx,Y[tp]=ty;
		}
		while(tp) mp[X[tp]+N][Y[tp]+N]=-1,tp--;
		if(flag) ans[++num]=make_pair(x,y);
	}
	sort(ans+1,ans+num+1);
	num=unique(ans+1,ans+num+1)-ans-1;
	put('\n',num);
	for(int i=1;i<=num;i++) put(' ',ans[i].first),put('\n',ans[i].second);
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3688kb

input:

4
LRUD

output:

4
0 -1
0 0
1 -1
1 0

result:

ok 5 lines

Test #3:

score: 0
Accepted
time: 105ms
memory: 3756kb

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: 3772kb

input:

1
D

output:

2
0 -1
0 0

result:

ok 3 lines

Test #5:

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

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: 102ms
memory: 3700kb

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: 101ms
memory: 3748kb

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: 101ms
memory: 3620kb

input:

20
DUUDDUDUUDUDDUUDUDDU

output:

3
0 -1
0 0
0 1

result:

ok 4 lines

Test #9:

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

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: 94ms
memory: 3944kb

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