Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B
Grid with 4 rows and 4 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?
- A. 6
- B. 12
- C. 15
- D. 7
Correct answer: D. 7
BFS over (cell, time parity) states, with waiting allowed, gives 7: a gate can only be entered at an even time, so one wait is needed. Ignoring the gate rule gives the plain shortest path 6; waiting after every move gives 12, and 15 visits every cell.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- An undirected graph has the vertices C, D, F, K, W, Y and the edges D–W, D–F, D–Y, D–K, W–Y, C–Y, C–K, F–Y, Y–K. What is its chromatic…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→D (9), S→B (6), D→B (9), D→T (4), E→D (3), E→T…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→B (7), S→T (6), A→B (5), A→T (3), E→B (2), B→C…
- Starting from the integer 3, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {4, 5, 6} and s ≤ the pile size. The player who…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {2, 3, 5} and s ≤ the pile size. The player who…