Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2021 /round1 /traffic_control_sol.md
wjomlex's picture
2021 Problems
d3f4f72 verified

Any path from one corner of the grid to the opposite corner must include at least (K = N + M - 1) cells and therefore have a minimum duration of (K). Therefore, if (A < K) or (B < K), no valid grid exists.

Otherwise, consider a grid with a wait time of (A - (N + M - 2)) for the top-left cell, a wait time of (B - (N + M - 2)) for the top-right cell, and wait times of (1) for all remaining cells. In such a grid, the minimum duration of a path from the top-left to the bottom-right corner includes the top-left cell along with (K - 1) cells with wait times of (1), for a total of (A - (N + M - 2) + (N + M - 2) = A). The minimum duration of a path from the top-right to the bottom-left corner is similarly (B). Therefore, such a grid constitutes a valid output.

See David Harmeyer's solution video here.