Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B

Grid with 4 rows and 3 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .GG G.G .G. ... Each step, which is a move to an adjacent cell or waiting one unit in place, takes exactly 1 time unit. A gate may only be occupied at an even time (t = 0, 2, 4, …); normal cells can be occupied at any time. You start at the top-left cell at time 0. What is the earliest time you can stand on the bottom-right cell?

  1. A. 5
  2. B. 10
  3. C. 6
  4. D. 11

Correct answer: C. 6

BFS over (cell, time parity) states, with waiting allowed, gives 6: a gate can only be entered at an even time, so one wait is needed. Ignoring the gate rule gives the plain shortest path 5; waiting after every move gives 10, and 11 visits every cell.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic