Editorial for IOI '14 Practice Task 1 - Square
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
This problem can be solved by dynamic programming. We define a function
- If
then will be if the grid at is usable, and will be if the grid at is defective. - If
, then it is easy to see that is . - If either
or is , i.e., it is at the top row or right column, then is if the grid is usable, or otherwise.
It is easy to see that the dynamic programming runs in
Comments
Fun fact: you can also AC using a sparse table and binary search in
time.
https://dmoj.ca/submission/4369199