QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#220795 | #7516. Robot Experiment | ammardab3an# | WA | 1ms | 3548kb | C++20 | 1012b | 2023-10-20 20:40:42 | 2023-10-20 20:40:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
map<pair<int, int>, int> mp;
multiset<pair<int, int>> vis;
multiset<pair<int, int>> block;
void go(int i, int j, int idx){
if(idx == n){
mp[{i, j}] = 1;
return;
}
pair<int, int> nxt;
if(s[idx] == 'U') nxt = {i+1, j};
else if(s[idx] == 'D') nxt = {i-1, j};
else if(s[idx] == 'R') nxt = {i, j+1};
else nxt = {i, j-1};
if(vis.find(nxt) == vis.end()){
block.insert(nxt);
go(i, j, idx+1);
block.erase(block.find(nxt));
}
if(block.find(nxt) == block.end()){
vis.insert(nxt);
go(nxt.first, nxt.second, idx+1);
vis.erase(vis.find(nxt));
} else {
assert(nxt != make_pair(0, 0));
}
}
int main()
{
cin >> n >> s;
vis.insert({0, 0});
go(0, 0, 0);
cout << (int)mp.size() << "\n";
for(auto [f, s] : mp) cout << f.first << " " << f.second << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3548kb
input:
2 RU
output:
4 0 0 0 1 1 0 1 1
result:
ok 5 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3428kb
input:
4 LRUD
output:
4 -1 0 -1 1 0 0 0 1
result:
wrong answer 2nd lines differ - expected: '0 -1', found: '-1 0'