#P10801. [CEOI 2024] 海战
[CEOI 2024] 海战
Problem Description
This problem is translated from CEOI 2024 Day 1 Task 1「Naval battle」.
Ondra, the commander of the Czech Navy, has just been promoted to Grand Marshal and is enjoying the peace of his new position, when the government suddenly informs him that the navy will be disbanded.
Ondra is determined to prove how important the Czech Navy is. Through his spies, he learns that a massive naval battle between four countries is about to take place. If he can win this battle, it will surely be strong evidence to show the government the navy’s value.
However, the Czech Navy has neither warships nor ports. But Ondra thinks that if his spies can seize a few of the ships taking part in the battle, there may still be a chance. The key question is: how can he predict which ships will survive this naval battle?
The rules of the naval battle are as follows:
- Before the battle, the -th warship is located at coordinates , where both and are even. Each warship belongs to exactly one of the four fleets: North, South, East, or West.
- The battle proceeds in rounds. In each round:
- Every warship simultaneously moves one cell in the direction of its fleet.
- If two or more warships occupy the same cell, they collide, sink, and disappear from the map.
- The battle ends when no more collisions occur. Surviving warships are those that remain on the map after the battle ends.
The movement directions and coordinate changes for each fleet are:
- North fleet: decreases by .
- South fleet: increases by .
- East fleet: increases by .
- West fleet: decreases by .
Input Format
The first line contains an integer , the total number of warships participating in the battle. The next lines each contain three space-separated values . Here, and give the initial position of the -th warship, and the character indicates the direction of the fleet it belongs to; it is one of N, S, E, or W.
Initially, no two warships share the same coordinates. In other words, for any two different warships and , it is impossible that both their -coordinates are equal and their -coordinates are also equal.
Output Format
For each surviving warship, output one line containing its index . You may output the indices of surviving warships in any order.
If no warships survive, the output should be empty.
7
0 6 E
0 8 E
2 4 E
4 2 S
6 0 S
6 2 S
6 4 S
7
5
4 0 S
0 2 E
2 2 E
4 4 N
6 6 W
2
5
Hint
Sample Explanation 1
The initial placement of warships is shown in the figure below:
Battle process:
- In round , warships and collide at .
- In round , warships and collide at , and warships and collide at .
In the end, only warship survives.
Sample Explanation 2
The initial placement of warships is shown in the figure below:
In round , warships , , and collide at , and warships and survive.
Constraints and Notes
For all input data, it holds that:
- , and are both even.
The detailed additional constraints and scores for subtasks are given in the table below.
| Subtask | Additional Constraints | Score |
|---|---|---|
is S or E |
||
| No additional constraints. |
Translated by ChatGPT 5