Naval battle

시간 제한3초메모리 제한1024 MB

요약
짝수 좌표에서 네 방향으로 움직이는 배들이 충돌로 사라지는 과정을 시뮬레이션하고, 살아남은 배의 번호를 출력한다.
난이도

어려움10점 중 8점

유형
정렬, 시뮬레이션, 수학, 해시맵
정답자
아직 제출이 없습니다

문제

Ondra has recently been promoted to Grand admiral of the Czech Navy. However, when he finally started thinking he had a secure job, the government announced budget cuts including dissolution of the Navy.

So Ondra decided to show the government how important the Czech Navy is. He knows from his spies about an upcoming naval battle of four great fleets. If he could win it, it would surely make enough of a demonstration.

Unfortunately, the Czech Navy has neither warships nor sea ports. But if Ondra's spies took over some ships he might have a chance. If only he knew which ships will survive the battle…

A naval battle goes as follows: Initially ship ii starts on square (x_i,y_i)(x\_i, y\_i), where both x_ix\_i and y_iy\_i are even. Additionally, the ship belongs to one of the four fleets: Northern, Southern, Eastern or Western. Then the battle proceeds in steps. In each step:

  • First, each ship simultaneously moves one square in the direction corresponding to its fleet.
  • If two or more ships now occupy the same square, they sink and disappear from the map.

The battle ends when no crashes are possible anymore. A surviving ship is a ship that remains on the map after the end of the battle.

A ship moves according to the direction of its fleet. The movement in each direction changes its coordinates as follows:

  • Northern — decreases the yy coordinate by 1
  • Southern — increases the yy coordinate by 1
  • Eastern — increases the xx coordinate by 1
  • Western — decreases the xx coordinate by 1

입력

The first line of inputs contains an integer NN. Then NN lines follow, each containing x_ix\_i, y_iy\_i, and d_id\_i, separated by spaces. The integers x_ix\_i and y_iy\_i are the coordinates of the ii-th ship. The character d_id\_i is either N, S, E or W, describing the direction of the ii-th ship's fleet.

No two ships initially have the same coordinates. That is, for ships ii and jj (i≠ji \neq j) either x_i≠x_jx\_i \neq x\_j or y_i≠y_jy\_i \neq y\_j.

출력

For each surviving ship, output a single line containing the integer ii (1≤i≤N1 \leq i \leq N) — the number of the ship. You can output the numbers of surviving ships in any order.

If there are no surviving ships, the output should be empty.

제한

  • 2≤N≤2⋅1052 \leq N \leq 2 \cdot 10^5
  • 0≤x_i,y_i≤1090 \leq x\_i, y\_i \leq 10^9 (for each ii such that 1≤i≤N1 \leq i \leq N) and x_i,y_ix\_i, y\_i are even.

예제2

  1. 예제 1

    입력
    7
    0 6 E
    0 8 E
    2 4 E
    4 2 S
    6 0 S
    6 2 S
    6 4 S
    
    예상 출력
    7
    
  2. 예제 2

    입력
    5
    4 0 S
    0 2 E
    2 2 E
    4 4 N
    6 6 W
    
    예상 출력
    5
    2