#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 ii-th warship is located at coordinates (xi,yi)(x_i, y_i), where both xix_i and yiy_i 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: yy decreases by 11.
  • South fleet: yy increases by 11.
  • East fleet: xx increases by 11.
  • West fleet: xx decreases by 11.

Input Format

The first line contains an integer NN, the total number of warships participating in the battle. The next NN lines each contain three space-separated values xi,yi,dix_i, y_i, d_i. Here, xix_i and yiy_i give the initial position of the ii-th warship, and the character did_i 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 ii and jj, it is impossible that both their xx-coordinates are equal and their yy-coordinates are also equal.

Output Format

For each surviving warship, output one line containing its index i (1iN)i\ (1 \leq i \leq N). 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-sample1-v2.svg

Battle process:

  • In round 22, warships 33 and 44 collide at (4,4)(4, 4).
  • In round 66, warships 11 and 55 collide at (6,6)(6, 6), and warships 22 and 66 collide at (6,8)(6, 8).

In the end, only warship 77 survives.

Sample Explanation 2

The initial placement of warships is shown in the figure below:

battle-sample2.svg

In round 22, warships 11, 33, and 44 collide at (2,4)(2, 4), and warships 22 and 55 survive.

Constraints and Notes

For all input data, it holds that:

  • 2N21052 \leq N \leq 2 \cdot 10^5
  • 0xi,yi109 (1iN)0 \leq x_i, y_i \leq 10^9\ (1 \leq i \leq N), and xi,yix_i, y_i are both even.

The detailed additional constraints and scores for subtasks are given in the table below.

Subtask Additional Constraints Score
11 N=2N = 2 66
22 N100,xi,yi100 (1iN)N \leq 100, x_i, y_i \leq 100\ (1 \leq i \leq N) 1212
33 N100,xi,yi105 (1iN)N \leq 100, x_i, y_i \leq 10^5\ (1 \leq i \leq N) 88
44 N200N \leq 200 1111
55 N5000N \leq 5\,000 99
66 di (1iN)d_i\ (1 \leq i \leq N) is S or E 3030
77 No additional constraints. 2424

Translated by ChatGPT 5