Submission #968233

# Submission time Handle Problem Language Result Execution time Memory
968233 2024-04-23T08:37:18 Z ShauryaTheShep Robots (APIO13_robots) C++14
Compilation error
0 ms 0 KB
struct State {
    int x1, y1, x2, y2, moves;
};

int simulateMove(int x, int y, int direction) {
    while (is_inside(x + dx[direction], y + dy[direction]) && grid[x + dx[direction]][y + dy[direction]] != 'x') {
        x += dx[direction];
        y += dy[direction];
    }
    return {x, y};
}

int bfs(pair<int, int> start1, pair<int, int> start2) {
    queue<State> q;
    set<tuple<int, int, int, int>> visited;
    q.push({start1.first, start1.second, start2.first, start2.second, 0});
    visited.insert({start1.first, start1.second, start2.first, start2.second});

    while (!q.empty()) {
        auto [x1, y1, x2, y2, moves] = q.front(); q.pop();

        if (x1 == x2 && y1 == y2) return moves;

        // Generate all possible moves for both robots
        for (int dir = 0; dir < 4; dir++) {
            auto [nx1, ny1] = simulateMove(x1, y1, dir);
            if (visited.insert({nx1, ny1, x2, y2}).second) {
                q.push({nx1, ny1, x2, y2, moves + 1});
            }
            auto [nx2, ny2] = simulateMove(x2, y2, dir);
            if (visited.insert({x1, y1, nx2, ny2}).second) {
                q.push({x1, y1, nx2, ny2, moves + 1});
            }
        }
    }

    return -1;
}

Compilation message

robots.cpp: In function 'int simulateMove(int, int, int)':
robots.cpp:6:26: error: 'dx' was not declared in this scope; did you mean 'x'?
    6 |     while (is_inside(x + dx[direction], y + dy[direction]) && grid[x + dx[direction]][y + dy[direction]] != 'x') {
      |                          ^~
      |                          x
robots.cpp:6:45: error: 'dy' was not declared in this scope; did you mean 'y'?
    6 |     while (is_inside(x + dx[direction], y + dy[direction]) && grid[x + dx[direction]][y + dy[direction]] != 'x') {
      |                                             ^~
      |                                             y
robots.cpp:6:12: error: 'is_inside' was not declared in this scope
    6 |     while (is_inside(x + dx[direction], y + dy[direction]) && grid[x + dx[direction]][y + dy[direction]] != 'x') {
      |            ^~~~~~~~~
robots.cpp:6:63: error: 'grid' was not declared in this scope
    6 |     while (is_inside(x + dx[direction], y + dy[direction]) && grid[x + dx[direction]][y + dy[direction]] != 'x') {
      |                                                               ^~~~
robots.cpp:10:17: error: cannot convert '<brace-enclosed initializer list>' to 'int' in return
   10 |     return {x, y};
      |                 ^
robots.cpp: At global scope:
robots.cpp:13:9: error: 'pair' was not declared in this scope
   13 | int bfs(pair<int, int> start1, pair<int, int> start2) {
      |         ^~~~
robots.cpp:13:14: error: expected primary-expression before 'int'
   13 | int bfs(pair<int, int> start1, pair<int, int> start2) {
      |              ^~~
robots.cpp:13:19: error: expected primary-expression before 'int'
   13 | int bfs(pair<int, int> start1, pair<int, int> start2) {
      |                   ^~~
robots.cpp:13:32: error: 'pair' was not declared in this scope
   13 | int bfs(pair<int, int> start1, pair<int, int> start2) {
      |                                ^~~~
robots.cpp:13:37: error: expected primary-expression before 'int'
   13 | int bfs(pair<int, int> start1, pair<int, int> start2) {
      |                                     ^~~
robots.cpp:13:42: error: expected primary-expression before 'int'
   13 | int bfs(pair<int, int> start1, pair<int, int> start2) {
      |                                          ^~~
robots.cpp:13:53: error: expression list treated as compound expression in initializer [-fpermissive]
   13 | int bfs(pair<int, int> start1, pair<int, int> start2) {
      |                                                     ^