#P13821. 「Diligent-OI R2 A」蒹葭苍苍
「Diligent-OI R2 A」蒹葭苍苍
Description
On a sufficiently large grid, there are rows of open spaces, where columns to of row are all open spaces. Except for the given open space, all other locations are obstacles.
You will start from the leftmost cell of the first row , and reach the rightmost cell of the last row . Movement is restricted to up, down, or right directions within the grid. Cells may be revisited, but each cell is counted only once.
Determine the maximum number of distinct cells visited during such a path.
Input Format
The first line contains an integer . The second line contains integers .
Output Format
A single integer representing the maximum distinct cells visited.
2
1 2
3
6
1 1 4 5 1 4
9
5
2 2 2 2 2
10
Hint
Sample #1 Explanation:

Path: .
Sample #2 Explanation:

Path: $(1,1)\to(2,1)\to(3,1)\to(4,1)\to(5,1)\to(6,1)\to(6,2)\to(6,3)\to(6,4)$.
Sample #3 Explanation:

Path: $(1,1)\to(2,1)\to(3,1)\to(4,1)\to(5,1)\to(4,1)\to(3,1)\to(2,1)\to(1,1)\to(1,2)\to(2,2)\to(3,2)\to(4,2)\to(5,2)$. (Note: Revisited cells are counted once)
Data Range
All data guarantees: .
- Subtask 1 (20pts): .
- Subtask 2 (20pts): for all .
- Subtask 3 (20pts): for all .
- Subtask 4 (20pts): .
- Subtask 5 (20pts): No additional constraints.
京公网安备 11011102002149号