This is an extension of othscc4p5. In this version, the constraints and input format are different.
Aether is travelling across Teyvat, which can be represented by a by
grid, where each cell
is either empty
.
or contains a teleporter x
. Due to terrain and weather reasons, he can only move down and to the right. Formally, if he is at the cell , he can go to
if
, and he can go to
if
.
Whenever he is at a cell containing a teleporter, he can choose to teleport to any other cell containing a teleporter. Each teleporter can be used an unlimited number of times.
There will be teleporters in total, the
of which is located at
. No
teleporters will be at the same cell.
Since Aether likes exploring new areas, he would like to know, what is the maximum number of unique cells that he can visit if he starts at the top-leftmost cell
?
Constraints
No teleporters will be at the same cell.
Subtask 1 [85%]
Subtask 2 [15%]
No additional constraints.
Input Specification
The first line of input contains space-separated integers,
and
, representing the dimensions of the grid and the number of teleporters respectively.
The next lines of input each contain
space-separated integers,
and
, representing the location of the
teleporter.
Output Specification
Output integer, the maximum number of unique cells that Aether can visit.
Sample Input 1
3 2
2 3
3 2
Sample Output 1
6
Explanation for Sample 1
The grid looks like this:
...
..x
.x.
The following path visits unique cells:
- Start at
- Go to
- Go to
- Go to
- Teleport to
- Go to
It can be proven that this is the maximum number of unique cells Aether can visit.
Sample Input 2
5 5
1 1
2 2
3 4
5 2
5 5
Sample Output 2
25
Explanation for Sample 2
The grid looks like this:
x....
.x...
...x.
.....
.x..x
Comments