#abc291c. C - LRUD Instructions 2

C - LRUD Instructions 2

Score : 300300 points

问题描述

Takahashi在一个二维平面上,从原点出发,他进行了 NN 次移动。

NN 次移动由长度为 NN 的字符串 SS 表示,如下所示:

  • Takahashi在第 ii 次移动后的坐标是:

    • 如果第 ii 个字符为 R,则坐标为 (x+1,y)(x+1,y)
    • 如果第 ii 个字符为 L,则坐标为 (x1,y)(x-1,y)
    • 如果第 ii 个字符为 U,则坐标为 (x,y+1)(x,y+1)
    • 如果第 ii 个字符为 D,则坐标为 (x,y1)(x,y-1)

其中 (x,y)(x,y) 是他在移动前的坐标。

确定在 NN 次移动的过程中(包括起点和终点),Takahashi是否多次访问过相同的坐标。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi is on a two-dimensional plane. Starting from the origin, he made NN moves.

The NN moves are represented by a string of length NN as described below:

  • Takahashi's coordinates after the ii-th move are:

    • (x+1,y)(x+1,y) if the ii-th character of SS is R;
    • (x1,y)(x-1,y) if the ii-th character of SS is L;
    • (x,y+1)(x,y+1) if the ii-th character of SS is U; and
    • (x,y1)(x,y-1) if the ii-th character of SS is D,

    where (x,y)(x,y) is his coordinates before the move.

Determine if Takahashi visited the same coordinates multiple times in the course of the NN moves (including the starting and ending points).

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • NN is an integer.
  • SS is a string of length NN consisting of R, L, U, and D.

Input

The input is given from Standard Input in the following format:

NN

SS

Output

Print Yes if Takahashi visited the same coordinates multiple times in the course of the NN moves; print No otherwise.

Sample Input 1

5
RLURU

Sample Output 1

Yes

Takahashi's coordinates change as follows: (0,0)(1,0)(0,0)(0,1)(1,1)(1,2)(0,0)\to (1,0)\to (0,0)\to (0,1)\to (1,1)\to (1,2).

Sample Input 2

20
URDDLLUUURRRDDDDLLLL

Sample Output 2

No

update @ 2024/3/10 12:08:38