102432: [AtCoder]ABC243 C - Collision 2

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

There are $N$ people in an $xy$-plane. Person $i$ is at $(X_i, Y_i)$. The positions of all people are different.

We have a string $S$ of length $N$ consisting of L and R.
If $S_i =$ R, Person $i$ is facing right; if $S_i =$ L, Person $i$ is facing left. All people simultaneously start walking in the direction they are facing. Here, right and left correspond to the positive and negative $x$-direction, respectively.

For example, the figure below shows the movement of people when $(X_1, Y_1) = (2, 3), (X_2, Y_2) = (1, 1), (X_3, Y_3) =(4, 1), S =$ RRL.

image

We say that there is a collision when two people walking in opposite directions come to the same position. Will there be a collision if all people continue walking indefinitely?

Constraints

  • $2 \leq N \leq 2 \times 10^5$
  • $0 \leq X_i \leq 10^9$
  • $0 \leq Y_i \leq 10^9$
  • $(X_i, Y_i) \neq (X_j, Y_j)$ if $i \neq j$.
  • All $X_i$ and $Y_i$ are integers.
  • $S$ is a string of length $N$ consisting of L and R.

Input

Input is given from Standard Input in the following format:

$N$
$X_1$ $Y_1$
$X_2$ $Y_2$
$\vdots$
$X_N$ $Y_N$
$S$

Output

If there will be a collision, print Yes; otherwise, print No.


Sample Input 1

3
2 3
1 1
4 1
RRL

Sample Output 1

Yes

This input corresponds to the example in the Problem Statement.
If all people continue walking, Person $2$ and Person $3$ will collide. Thus, Yes should be printed.


Sample Input 2

2
1 1
2 1
RR

Sample Output 2

No

Since Person $1$ and Person $2$ walk in the same direction, they never collide.


Sample Input 3

10
1 3
1 4
0 0
0 2
0 4
3 1
2 4
4 2
4 4
3 3
RLRRRLRLRR

Sample Output 3

Yes

Input

题意翻译

平面直角坐标系上有 $n$ 个点,第 $i$ 个点的坐标为 $(x_i,y_i)$ 。有一个字符串 $s$ ( $s$ 的下标从 $1$ 开始),其长度也为 $n$ 。如果 $s_i$ 为`L`,则第 $i$ 个点向左移动;如果 $s_i$ 为`R`,则第 $i$ 个点向右移动。现在,依次输入 $n$ ,所有 $x_i$ 和 $y_i$ 以及 $s$ ,问:是否会有两个点重合在一起? (注:向左移动是指沿 $x$ 轴向负方向移动,向右移动与此相反。)

Output

分数:300分

问题描述

在一个$x$-$y$平面上有$N$个人。第$i$个人位于$(X_i, Y_i)$。所有人的位置都不同。

我们有一个由LR组成的长度为$N$的字符串$S$。
如果$S_i =$ R,那么第$i$个人面朝右;如果$S_i =$ L,那么第$i$个人面朝左。所有人同时开始朝他们面朝的方向行走。这里,右和左分别对应正的$x$方向和负的$x$方向。

例如,下图展示了当$(X_1, Y_1) = (2, 3), (X_2, Y_2) = (1, 1), (X_3, Y_3) =(4, 1), S =$ RRL时,人们移动的情况。

image

当两个朝相反方向行走的人走到同一个位置时,我们称之为发生了碰撞。如果所有人都无限期地继续行走,会发生碰撞吗?

约束

  • $2 \leq N \leq 2 \times 10^5$
  • $0 \leq X_i \leq 10^9$
  • $0 \leq Y_i \leq 10^9$
  • 如果$i \neq j$,那么$(X_i, Y_i) \neq (X_j, Y_j)$。
  • 所有的$X_i$和$Y_i$都是整数。
  • $S$是一个由LR组成的长度为$N$的字符串。

输入

从标准输入以如下格式给出输入:

$N$
$X_1$ $Y_1$
$X_2$ $Y_2$
$\vdots$
$X_N$ $Y_N$
$S$

输出

如果有碰撞,打印Yes;否则,打印No


样例输入1

3
2 3
1 1
4 1
RRL

样例输出1

Yes

此输入对应于问题描述中的示例。
如果所有人都继续行走,第2个人和第3个人会碰撞。因此,应该打印Yes


样例输入2

2
1 1
2 1
RR

样例输出2

No

由于第1个人和第2个人朝同一个方向行走,他们永远不会碰撞。


样例输入3

10
1 3
1 4
0 0
0 2
0 4
3 1
2 4
4 2
4 4
3 3
RLRRRLRLRR

样例输出3

Yes

加入题单

算法标签: