102441: [AtCoder]ABC244 B - Go Straight and Turn Right

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

Description

Score : $200$ points

Problem Statement

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

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

  • If $t_i =$ S, Takahashi advances in the current direction by distance $1$.
  • If $t_i =$ R, Takahashi turns $90$ 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 $x$-axis) before he turns, he will face south (in the negative direction of the $y$-axis) after he turns.
    • If he is facing south (in the negative direction of the $y$-axis) before he turns, he will face west (in the negative direction of the $x$-axis) after he turns.
    • If he is facing west (in the negative direction of the $x$-axis) before he turns, he will face north (in the positive direction of the $y$-axis) after he turns.
    • If he is facing north (in the positive direction of the $y$-axis) before he turns, he will face east (in the positive direction of the $x$-axis) after he turns.

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

Constraints

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

Input

Input is given from Standard Input in the following format:

$N$
$T$

Output

Print the coordinates $(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:

$x$ $y$

Sample Input 1

4
SSRS

Sample Output 1

2 -1

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

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

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


Sample Input 2

20
SRSRSSRSSSRSRRRRRSRR

Sample Output 2

0 1

Input

题意翻译

在平面上,分别以正东($x$ 轴)、正北($y$ 轴)为正方向建立平面直角坐标系。高桥现在在这个坐标系的原点处,面东而立(也就是说他正对着 $x$ 轴的正方向)。 现在由输入给出一个正整数 $n$ 和一个长为 $n$ 且完全由`S`和`R`构成的字符串 $t$。高桥按照 $i=1,2,...,n$ 的顺序做如下动作($t$ 的下标从 $1$ 开始): - $t_i=$`S`时:高桥向他的正前方走一个单位长度。 - $t_i=$`R`时:高桥原地向右转 $90°$。 请在高桥完成全部移动后,输出他所在当前位置的坐标($x$ 先 $y$ 后,中间以单个空格隔开)。数据保证 $1 \le n \le 10^5$。

Output

分数:200分

问题描述

考虑一个xy坐标系。x轴的正方向朝东,y轴的正方向朝北。
Takahashi 初始位于点(x, y) = (0, 0),面向东(即x轴的正方向)。

给你一个长度为N的字符串T = t_1t_2\ldots t_N,由SR组成。 Takahashi 将按照以下顺序对每个i = 1, 2, \ldots, N执行以下操作。

  • 如果t_i = S,Takahashi 将沿当前方向前进距离1
  • 如果t_i = R,Takahashi 将不改变位置地顺时针转90度。结果,Takahashi 的方向将如下改变。
    • 如果他在转弯前面向东(即x轴的正方向),则他在转弯后将面向南(即y轴的负方向)。
    • 如果他在转弯前面向南(即y轴的负方向),则他在转弯后将面向西(即x轴的负方向)。
    • 如果他在转弯前面向西(即x轴的负方向),则他在转弯后将面向北(即y轴的正方向)。
    • 如果他在转弯前面向北(即y轴的正方向),则他在转弯后将面向东(即x轴的正方向)。

打印在按照问题描述中的所有步骤完成后,Takahashi 所在的位置坐标。

约束条件

  • 1 \leq N \leq 10^5
  • N为整数。
  • T是一个长度为N的字符串,由SR组成。

输入

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

N
T

输出

按照以下格式打印在按照问题描述中的所有步骤完成后,Takahashi 所在的位置坐标(x, y),中间用空格隔开:

x y

样例输入 1

4
SSRS

样例输出 1

2 -1

Takahashi 初始位于(0, 0)面向东。然后,他按照以下方式移动。

  1. t_1 = S,所以他向正东方向前进距离1,到达(1, 0)
  2. t_2 = S,所以他向正东方向前进距离1,到达(2, 0)
  3. t_3 = R,所以他顺时针转90度,结果面向南。
  4. t_4 = S,所以他向正南方向前进距离1,到达(2, -1)

因此,应打印Takahashi 的最终位置(x, y) = (2, -1)


样例输入 2

20
SRSRSSRSSSRSRRRRRSRR

样例输出 2

0 1

加入题单

算法标签: