QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#248694#7516. Robot Experimentcciafrino#TL 490ms3452kbC++141.8kb2023-11-11 20:57:552023-11-11 20:57:55

Judging History

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

  • [2023-11-11 20:57:55]
  • 评测
  • 测评结果:TL
  • 用时:490ms
  • 内存:3452kb
  • [2023-11-11 20:57:55]
  • 提交

answer

#include<bits/extc++.h>
#include <ext/pb_ds/assoc_container.hpp>

struct chash {
    int operator()(std::array<int, 2> x) const { return x[0] * 31 + x[1]; }
};

template <typename K, typename V, typename Hash = chash>
using hash_map = __gnu_pbds::gp_hash_table<K, V, Hash>;
int main() {
    using namespace std;
    cin.tie(nullptr)->sync_with_stdio(false);
    int N; cin >> N; string S; cin >> S;

    auto get_nxt = [&](const char c, const array<int, 2> cur) -> array<int, 2> {
        if (c == 'U') {
            return {cur[0], cur[1] + 1};
        }
        if (c == 'R') {
            return {cur[0] + 1, cur[1]};
        }
        if (c == 'D') {
            return {cur[0], cur[1] - 1};
        }
        if (c == 'L') {
            return {cur[0] - 1, cur[1]};
        }
        return {0, 0};
    };

    vector<array<int, 2>> path; path.reserve(1 << N);    
    for (int mask = 0; mask < (1 << N); ++mask) {
        hash_map<array<int, 2>, int> vis;

        array<int, 2> cur = {0, 0};
        bool ok = true;
        vis[cur] = 1;
        for (int x = 0; x < N; ++x) {
            auto nxt = get_nxt(S[x], cur);
            if (mask & (1 << x)) {
                cur = nxt;
                if (vis.find(nxt) != vis.end()) {
                    if (vis[nxt] == 0) ok = false;
                }
                vis[nxt] = 1;
            } else {
                if (vis.find(nxt) != vis.end()) {
                    if (vis[nxt] == 1) ok = false;
                }
                vis[nxt] = 0;
            }
        }
        if (ok) {
            path.push_back(cur);
        }
    }
    sort(path.begin(), path.end());
    path.erase(unique(path.begin(), path.end()), path.end());
    cout << int(path.size()) << '\n';
    for (auto [a, b] : path) {
        cout << a << ' ' << b << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3416kb

input:

2
RU

output:

4
0 0
0 1
1 0
1 1

result:

ok 5 lines

Test #2:

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

input:

4
LRUD

output:

4
0 -1
0 0
1 -1
1 0

result:

ok 5 lines

Test #3:

score: 0
Accepted
time: 490ms
memory: 3452kb

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

input:

1
D

output:

2
0 -1
0 0

result:

ok 3 lines

Test #5:

score: 0
Accepted
time: 480ms
memory: 3452kb

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: -100
Time Limit Exceeded

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: