QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#513038 | #7516. Robot Experiment | Sk1ua | WA | 0ms | 3536kb | C++17 | 1.3kb | 2024-08-10 16:42:03 | 2024-08-10 16:42:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
const int N = 1e5 + 10;
typedef pair<int, int> PII;
int n;string s;
map<char, PII> mp = {{'L', {-1, 0}}, {'R', {1, 0}}, {'D', {0, -1}}, {'U', {0, 1}}};
set<PII> pos;
set<PII> obs;
map<PII,bool> vis;
void dfs(int x, int y, int idx, set<PII> &obs,map<PII,bool> &vis) {
if (idx == s.size()) {
pos.insert({x, y});
return;
}
int nx = x + mp[s[idx]].first;
int ny = y + mp[s[idx]].second;
if(vis[{nx,ny}] == false) {
vis[{nx,ny}] = true;
if (obs.find({nx, ny}) == obs.end()) {
dfs(nx, ny, idx + 1, obs,vis);
}
if(!(nx == 0 && ny ==0)) {
obs.insert({nx,ny});
dfs(x, y, idx + 1, obs,vis);
obs.erase({nx, ny});
}
} else {
if (obs.find({nx, ny}) == obs.end()) {
dfs(nx, ny, idx + 1, obs,vis);
}
}
}
void solve() {
cin >> n;
cin >> s;
dfs(0, 0, 0,obs,vis);
cout << pos.size() << endl;
if(pos.size() >= 2) {
for (auto p : pos) {
cout << p.first << " " << p.second << endl;
}
}
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
while (_--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
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: 3468kb
input:
4 LRUD
output:
4 0 -1 0 0 1 -1 1 0
result:
ok 5 lines
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3536kb
input:
20 LLLRLRLRLLLRLLRLRLLR
output:
2 -6 0 -5 0
result:
wrong answer 1st lines differ - expected: '8', found: '2'