Editorial for Baltic OI '08 P5 - Grid
Submitting an official solution before solving the problem yourself is a bannable offence.
Subtask 1
The simplest solution is to consider all placings of lines.
Time Complexity:
Subtask 2
If we fix the placing of lines going in one direction, then the optimal placing of lines going in the other direction can be computed much faster. There are two possible approaches:
We can use binary search to find an optimal computing time. Given a candidate for an optimal computing time and placing of all horizontal lines, we can place the vertical lines from the leftmost to the rightmost one using greedy approach: each vertical line should be put as far to the right as possible. This solution runs in
time, where
is the sum of all computation times for individual squares.
Another approach considers all
placings of horizontal lines. For each placing, it calculates the minimal processing time using dynamic programming. Let
be the minimal processing time of
first columns divided with
meridians. The array
can be easily filled in
time. The overall running time is
.
Time Complexity: or
Comments