QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578228#7521. Find the GapLittleYoo#WA 0ms3684kbC++201.0kb2024-09-20 17:31:132024-09-20 17:31:13

Judging History

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

  • [2024-09-20 17:31:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3684kb
  • [2024-09-20 17:31:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
string s;
set<pair<int, int>> ans, obs;
map<pair<int, int>, int> vis;
// map<pair<int, int>, int> obs;

void dfs(int now = 0, int x = 0, int y = 0)
{
	// cerr << x << ' ' << y << '\n';
	++vis[{x, y}];
	if(now == s.length()) {
		ans.emplace(x, y);
		--vis[{x, y}];
		return ;
	}
	char c = s[now];
	int nx(x), ny(y);
	if(c == 'R') {
		++nx;
	} else if(c == 'L') {
		--nx;
	} else if(c == 'U') {
		++ny;
	} else {
		--ny;
	}
	if(auto it = obs.find({nx, ny}); it != obs.end()) {
		dfs(now + 1, x, y);
	}
	else {
		dfs(now + 1, nx, ny);
		if(vis[{nx, ny}] == 0){
			obs.emplace(nx, ny);
			dfs(now + 1, x, y);
			obs.erase({nx, ny});
		}
	}
	--vis[{x, y}];
}

void solve()
{
	int n;
	cin >> n;
	cin >> s;
	dfs();
	cout << ans.size() << '\n';
	for(auto &[x, y] : ans)
		cout << x << ' ' << y << '\n';
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T = 1;
	// cin >> T;
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

8
1 1 1
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
2 2 2

output:

2
0 -1
0 0

result:

wrong answer 1st numbers differ - expected: '1.0000000', found: '2.0000000', error = '1.0000000'