#abc244b. B - Go Straight and Turn Right

B - Go Straight and Turn Right

Score : 200200 points

问题描述

考虑一个 xyxy-平面。xx 轴的正方向指向东方,yy 轴的正方向指向北方。 高桥初始位于点 (x,y)=(0,0)(x, y) = (0, 0) 并面向东方(沿 xx 轴正方向)。

给定一个长度为 NN 的字符串 T=t1t2tNT = t_1t_2\ldots t_N,由字符 SR 组成。高桥将按照以下顺序对每个 i=1,2,,Ni = 1, 2, \ldots, N 执行以下移动操作。

  • ti=t_i = S,高桥将在当前朝向前进距离 11
  • ti=t_i = R,高桥将在不改变位置的情况下顺时针旋转 9090 度。结果,高桥的方向会发生如下变化:
    • 如果他在转向前面向东(沿 xx 轴正方向),则转向后他将面向南(沿 yy 轴负方向)。
    • 如果他在转向前面向南(沿 yy 轴负方向),则转向后他将面向西(沿 xx 轴负方向)。
    • 如果他在转向前面向西(沿 xx 轴负方向),则转向后他将面向北(沿 yy 轴正方向)。
    • 如果他在转向前面向北(沿 yy 轴正方向),则转向后他将面向东(沿 xx 轴正方向)。

请输出执行完上述所有步骤后高桥所处的坐标。

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

Problem Statement

Consider an xyxy-plane. The positive direction of the xx-axis is in the direction of east, and the positive direction of the yy-axis is in the direction of north.
Takahashi is initially at point (x,y)=(0,0)(x, y) = (0, 0) and facing east (in the positive direction of the xx-axis).

You are given a string T=t1t2tNT = t_1t_2\ldots t_N of length NN consisting of S and R. Takahashi will do the following move for each i=1,2,,Ni = 1, 2, \ldots, N in this order.

  • If ti=t_i = S, Takahashi advances in the current direction by distance 11.
  • If ti=t_i = R, Takahashi turns 9090 degrees clockwise without changing his position. As a result, Takahashi's direction changes as follows.
    • If he is facing east (in the positive direction of the xx-axis) before he turns, he will face south (in the negative direction of the yy-axis) after he turns.
    • If he is facing south (in the negative direction of the yy-axis) before he turns, he will face west (in the negative direction of the xx-axis) after he turns.
    • If he is facing west (in the negative direction of the xx-axis) before he turns, he will face north (in the positive direction of the yy-axis) after he turns.
    • If he is facing north (in the positive direction of the yy-axis) before he turns, he will face east (in the positive direction of the xx-axis) after he turns.

Print the coordinates Takahashi is at after all the steps above have been done.

Constraints

  • 1N1051 \leq N \leq 10^5
  • NN is an integer.
  • TT is a string of length NN consisting of S and R.

Input

Input is given from Standard Input in the following format:

NN

TT

Output

Print the coordinates (x,y)(x, y) Takahashi is at after all the steps described in the Problem Statement have been completed, in the following format, with a space in between:

xx yy

Sample Input 1

4
SSRS

Sample Output 1

2 -1

Takahashi is initially at (0,0)(0, 0) facing east. Then, he moves as follows.

  1. t1=t_1 = S, so he advances in the direction of east by distance 11, arriving at (1,0)(1, 0).
  2. t2=t_2 = S, so he advances in the direction of east by distance 11, arriving at (2,0)(2, 0).
  3. t3=t_3 = R, so he turns 9090 degrees clockwise, resulting in facing south.
  4. t4=t_4 = S, so he advances in the direction of south by distance 11, arriving at (2,1)(2, -1).

Thus, Takahashi's final position, (x,y)=(2,1)(x, y) = (2, -1), should be printed.

Sample Input 2

20
SRSRSSRSSSRSRRRRRSRR

Sample Output 2

0 1

update @ 2024/3/10 10:28:45