LaKsHiTh_'s blog

By LaKsHiTh_, history, 5 years ago, In English

Recently i tried to solve the Amazing Robots task in IOI 2003.My first Idea was to run dijsktra while updating weights by calculating the position of guards. As we cannot wait in a position without a command this won't work. After that i have no idea how to solve this.

I googled for a solution and this is the only one i found from here .

Do a BFS on the state space.

Naive state space is

Position of robots in each grid.
Position of each guard.
This is too large (state space is 400 × 400 × ....).

Instead, compute the guards' positions as a function of time. In this case, we need to maintain:

Position of robots in each grid.
Current time T.
State space is still 400 × 400 × N, where N is the number of steps till they get out, which may become too large.

Observe that the guards' beats are of length 2, 3 or 4. Thus, each guard returns to his starting position after 2, 4 or 6 moves. Thus, we only need to keep track of time T modulo 2, 4 and 6. Since lcm(2,4,6) is 12, if we keep track of T modulo 12, we can recover all these three values.

In this problem, it is important to recognize that the path lengths for the guards allow you to cut down the state space of the BFS dramatically, to bring it within limits. Also, the number of edges is small because each node has at most 4 neighbours, corresponding to the N-S-E-W moves.

But i don't know what the State Space means. And i'm having hard time understanding how the BFS works here. (Edit: I understand how a simple BFS works) Again i googled and searched here for the state space of a BFS but found nothing.

Can someone help me understand what State Space of a BFS means and how can we use it to Solve this problem.

Thank you very much for your time.

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by LaKsHiTh_ (previous revision, new revision, compare).

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Imagine a grid, with the third dimension as time. Now at every step the grid is moving forward in time. Time states are cyclic, because the guards keep on moving back and forth, so we only need to keep track of their position in the current cycle, and is independent of the number of cycles that have happened till now. We are using BFS to find the least number of moves to reach each state, which can be uniquely represented by the states of the robot, and which part of the cycle we are at.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thankyou. I'm sorry it's still unclear for me. So if there are 2 units of time in cycle and 400 (20x20) in the 2d grid, resulting grid will be 400 x 2 ?

    And each state means these 400 x 2 positions ? So we need to calculate distance to each of them.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      You must maintain the position of both robots in both grids. So we have 400 possibilities for the first robot, another 400 for the second, and 12 for the time. The number 12 is not arbitrary, it is the LCM of all possible cycle lengths a guard can have. So we also need to save the time modulo 12.