QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#536941#7516. Robot ExperimentJEdwardWA 0ms3852kbC++171.4kb2024-08-29 18:11:592024-08-29 18:12:08

Judging History

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

  • [2024-08-29 18:12:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3852kb
  • [2024-08-29 18:11:59]
  • 提交

answer

#include <bits/stdc++.h>
#define endl "\n"
#define pii pair<int,int>
using namespace std;

int n;
string s;

set<pii> res;
map<pii,int> mp;

inline void dfs(int cur, int x, int y){
	if(cur==n+1){
		res.insert({x,y});
		return ;
	}
	
	if(s[cur]=='L'){
		if(mp.count({x-1,y})){
			if(mp[{x-1,y}]==-1) dfs(cur+1,x,y);
			else dfs(cur+1,x-1,y), dfs(cur+1,x,y);
		}else{
			mp[{x-1,y}] = -1;
			dfs(cur+1,x,y);
			
			mp[{x-1,y}] = 1;
			dfs(cur+1,x,y);
			dfs(cur+1,x-1,y);
		}
	}
	if(s[cur]=='R'){
		if(mp.count({x+1,y})){
			if(mp[{x+1,y}]==-1) dfs(cur+1,x,y);
			else dfs(cur+1,x+1,y), dfs(cur+1,x,y);
		}else{
			mp[{x+1,y}] = -1;
			dfs(cur+1,x,y);
			
			mp[{x+1,y}] = 1;
			dfs(cur+1,x,y);
			dfs(cur+1,x+1,y);
		}
	}
	if(s[cur]=='D'){
		if(mp.count({x,y-1})){
			if(mp[{x,y-1}]==-1) dfs(cur+1,x,y);
			else dfs(cur+1,x,y-1), dfs(cur+1,x,y);
		}else{
			mp[{x,y-1}] = -1;
			dfs(cur+1,x,y);
			
			mp[{x,y-1}] = 1;
			dfs(cur+1,x,y);
			dfs(cur+1,x,y-1);
		}
	}
	if(s[cur]=='U'){
		if(mp.count({x,y+1})){
			if(mp[{x,y+1}]==-1) dfs(cur+1,x,y);
			else dfs(cur+1,x,y+1), dfs(cur+1,x,y);
		}else{
			mp[{x,y+1}] = -1;
			dfs(cur+1,x,y);
			
			mp[{x,y+1}] = 1;
			dfs(cur+1,x,y);
			dfs(cur+1,x,y+1);
		}
	}
}


signed main(){
	mp[{0,0}]=1;
	cin >> n;
	cin >> s;
	s = " " +s;
	dfs(1,0,0);
	cout << res.size() << endl;
	for(auto k:res){
		cout << k.first << " " << k.second << endl;
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
RU

output:

4
0 0
0 1
1 0
1 1

result:

ok 5 lines

Test #2:

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

input:

4
LRUD

output:

9
-1 -1
-1 0
-1 1
0 -1
0 0
0 1
1 -1
1 0
1 1

result:

wrong answer 1st lines differ - expected: '4', found: '9'