Problem V
Portal
Languages
en
is
You think it would be funny to prank your best friend by
placing them on cell
As part of the prank, you want to trick your friend into not noticing that there are portals at all. The only thing your friend sees is the colour of the cell they are currently at, so you should make sure that from your friend’s perspective the colours of the tiles never change. In particular, if your friend thinks they have entered a cell more than once (for example by moving left and then immediately right), they should see the same colour as the first time they think they entered the cell.
Note: when your friend steps on a portal, they will see both the colour of the cell they step on, and the one they are teleported to. You will therefore need to colour all portal cells the same colour to avoid teleportations being immediately obvious.
A simple solution would be to colour all cells the same colour. But colours are nice! So you would like to use as many colours as you can.
Let’s consider an example where the portals are placed at
cells
![\includegraphics[width=0.95\textwidth ]{portal_explanation_en.png}](/problems/portal/file/statement/en/img-0001.png)
After the sequence of moves the friend thinks that they’re
back at the starting cell
There is no sequence of moves where your friend would think
that they end up on cell
Below you can see a colouring with 4 colours for the example above. It is not possible to use more than 4 colours for this example.
![\includegraphics[width=0.5\textwidth ]{portal_coloring.png}](/problems/portal/file/statement/en/img-0002.png)
Let’s consider a different example with portals at cells
Note that there was nothing special about our initial choice
of cell
Task
Calculate the maximum number of colours you can use while making sure that your friend won’t notice the existence of portals.
Input
The first line contains the integer
The next
Output
Print a single integer - the maximum number of colours that
can be used without your friend noticing the portals, or
Constraints
-
-
(for all ) -
No two portals share the same coordinates.
Subtasks
No. |
Points |
Additional constraints |
1 |
1 |
|
2 |
10 |
|
3 |
10 |
For all integers |
4 |
29 |
|
5 |
15 |
|
6 |
35 |
No additional constraints. |
Examples
First example discussed in the task description.
Second example discussed in the task description.
In the third example, your friend can only be “teleported” to the same cell that the portal is located in, so there is no way for them to notice the existence of portals even if every cell is coloured differently.
Sample Input 1 | Sample Output 1 |
---|---|
3 1 1 1 3 3 2 |
4 |
Sample Input 2 | Sample Output 2 |
---|---|
5 0 0 1 0 -1 0 0 1 0 -1 |
1 |
Sample Input 3 | Sample Output 3 |
---|---|
1 1 -1 |
-1 |