QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#578228 | #7521. Find the Gap | LittleYoo# | WA | 0ms | 3684kb | C++20 | 1.0kb | 2024-09-20 17:31:13 | 2024-09-20 17:31:13 |
Judging History
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;
}
详细
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'