QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#513051#7516. Robot ExperimentSk1uaWA 1ms3828kbC++171.4kb2024-08-10 16:45:242024-08-10 16:45:25

Judging History

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

  • [2024-08-10 16:45:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3828kb
  • [2024-08-10 16:45:24]
  • 提交

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) {
        if (obs.find({nx, ny}) == obs.end()) {
            vis[{nx,ny}] = true;
            dfs(nx, ny, idx + 1, obs,vis);
            vis[{nx,ny}] = false;
        }
        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: 3612kb

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: 3828kb

input:

4
LRUD

output:

4
0 -1
0 0
1 -1
1 0

result:

ok 5 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3524kb

input:

20
LLLRLRLRLLLRLLRLRLLR

output:

8
-6 0
-5 0
-4 0
-3 0
-2 0
-1 0
0 0
1 0

result:

ok 9 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

1
D

output:

2
0 -1
0 0

result:

ok 3 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

20
UUUUUUUUUUUUUUUUUUUU

output:

21
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 10
0 11
0 12
0 13
0 14
0 15
0 16
0 17
0 18
0 19
0 20

result:

ok 22 lines

Test #6:

score: 0
Accepted
time: 1ms
memory: 3616kb

input:

20
LRUDDULRUDRLLRDURLUD

output:

22
-2 0
-2 1
-1 -2
-1 -1
-1 0
-1 1
-1 2
0 -2
0 -1
0 0
0 1
0 2
1 -2
1 -1
1 0
1 1
1 2
2 -2
2 -1
2 0
2 1
2 2

result:

ok 23 lines

Test #7:

score: 0
Accepted
time: 0ms
memory: 3752kb

input:

20
UUDUDUUDUDUDUDUDLLRL

output:

12
-2 -1
-2 0
-2 1
-2 2
-1 -1
-1 0
-1 1
-1 2
0 -1
0 0
0 1
0 2

result:

ok 13 lines

Test #8:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

20
DUUDDUDUUDUDDUUDUDDU

output:

3
0 -1
0 0
0 1

result:

ok 4 lines

Test #9:

score: -100
Wrong Answer
time: 1ms
memory: 3756kb

input:

20
RUDLUULDRURLDURLDURR

output:

31
-3 3
-3 4
-2 2
-2 3
-2 4
-1 1
-1 2
-1 3
-1 4
0 -1
0 0
0 1
0 2
0 3
0 4
1 -1
1 0
1 1
1 2
1 3
2 -1
2 0
2 1
2 2
2 3
3 -1
3 0
3 1
3 2
4 0
4 1

result:

wrong answer 1st lines differ - expected: '29', found: '31'