Editorial for DMOPC '17 Contest 3 P4 - Solitaire Logic
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
For of the points, brute-forcing over the possible card configurations passes.
Time Complexity:
Consider a card with value placed at the position of the first row. Then it can be seen that the first cards of the first row and the first cards of the second row must contain all the numbers from to . The situation is similar if the card were in the second row.
For the next of the points, we use the above observation. Let be the highest value lower than which has been revealed and be the lowest value higher than which has been revealed. (If is already revealed, then the answer is clearly .) Since we know the region where all the cards from to are, and we know the region where all the cards from to are, we can see that any card with value between and must be in a certain region, specifically the union of two subarrays. Additionally, the positions of the cards with value less than and the cards with value greater than do not affect 's position.
So it is enough to consider these two subarrays containing all cards with value between and . It is not hard to see that the cards which can have value form two subarrays. The boundary points of these subarrays can be found by placing the values in sorted orders and can be directly computed from knowing the positions of and . Alternatively, use the fact that the region of cards with value from to must contain the region of cards from value to and similarly with to find the positions where can be.
Time Complexity:
For the final subtask, and can be found in by using a balanced binary search tree.
Time Complexity:
Comments