#P7193. [COCI 2007/2008 #6] PRINCEZA

    ID: 7504 远端评测题 1000ms 32MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>模拟图论2007O2优化排序COCI(克罗地亚)

[COCI 2007/2008 #6] PRINCEZA

Background

For C and C++, please use cin or scanf for input, otherwise you may get RE\color{purple}\mathsf{RE} and WA\color{red}\mathsf{WA}.

Problem Description

Luka parked his truck by the lake.

Barica lives in the lake, and she jumps across nn plants floating on the lake surface.

Luka knows many folk tales, and he knows that if he kisses Barica, she will turn into a cute girl. However, he must catch her first.

Each plant’s position on the lake can be described by a pair of coordinates. From the plant at (x,y)(x, y), Barica can jump with pp being any positive integer.

  • Direction A: (x+p,y+p)(x + p, y + p).
  • Direction B: (x+p,yp)(x + p, y - p).
  • Direction C: (xp,y+p)(x - p, y + p).
  • Direction D: (xp,yp)(x - p, y - p).

Barica chooses one of the four directions, then jumps along the chosen direction to the first plant.

If there is no plant in the chosen direction, Barica stays where she is.

After Barica jumps away, the plant she jumped from disappears.

Given the positions of the plants and the sequence of directions chosen by Barica, Luka wants to determine the coordinates of the plant where Barica will end up. Luka will wait for her at that position and kiss her.

Write a program to solve Luka’s problem and help him turn Barica into a beautiful princess.

Input Format

The first line contains two positive integers n,kn, k, representing the number of plants and the number of jumps.

The second line contains kk letters, A, B, C, or D, representing the directions of her jumps.

The next nn lines each contain two integers x,yx, y, representing the coordinates of a plant. Barica initially stands on the first plant.

Output Format

The first line contains Barica’s final coordinates.

7 5
ACDBB
5 6
8 9
4 13
1 10
7 4
10 9
3 7

7 4
6 12
AAAAAABCCCDD
1 1
2 2
3 3
4 4
5 3
6 2 

5 3

Hint

Constraints

For 100%100\% of the testdata, 1n,k1051 \le n, k \le 10 ^ 5, 0x,y1090 \le x, y \le 10 ^ 9.

Notes

  • This problem is worth 6060 points.
  • This problem enables the O2 optimization switch by default.
  • Translated from COCI2007-2008 CONTEST #6 T5 PRINCEZA, translator:
    https://www.luogu.com.cn/user/219791

Translated by ChatGPT 5