D - FT Robot Editorial /

Time Limit: 2 sec / Memory Limit: 512 MB

配点 : 500500

問題文

二次元平面の原点にロボットが置かれています。 最初、ロボットは xx 軸の正の向きを向いています。

このロボットに命令列 ss が与えられます。 ss は次の 22 文字のみからなり、先頭から末尾まで順に実行されます。

  • F : 今向いている向きに長さ 11 だけ移動する。
  • T : 時計回りまたは反時計回りの好きな方向に 9090 度だけ向きを変える。

ロボットの目標は、命令列をすべて実行し終わった後に座標 (x,y)(x, y) にいることです。 この目標が達成可能か判定してください。

制約

  • ssF, T のみからなる。
  • 1s8 0001 \leq |s| \leq 8\ 000
  • xx, yy は整数である。
  • x,ys|x|, |y| \leq |s|

入力

入力は以下の形式で標準入力から与えられる。

ss
xx yy

出力

目標が達成可能ならば Yes を出力し、達成不可能ならば No を出力せよ。


入力例 1Copy

Copy
FTFFTFFF
4 2

出力例 1Copy

Copy
Yes

11 番目の T で反時計周りに 9090 度だけ向きを変え、22 番目の T で時計周りに 9090 度だけ向きを変えればよいです。


入力例 2Copy

Copy
FTFFTFFF
-2 -2

出力例 2Copy

Copy
Yes

11 番目の T で時計周りに 9090 度だけ向きを変え、22 番目の T で時計周りに 9090 度だけ向きを変えればよいです。


入力例 3Copy

Copy
FF
1 0

出力例 3Copy

Copy
No

入力例 4Copy

Copy
TF
1 0

出力例 4Copy

Copy
No

入力例 5Copy

Copy
FFTTFF
0 0

出力例 5Copy

Copy
Yes

例えば、11 番目の T で反時計周りに 9090 度だけ向きを変え、22 番目の T で反時計周りに 9090 度だけ向きを変えればよいです。


入力例 6Copy

Copy
TTTT
1 0

出力例 6Copy

Copy
No

Score : 500500 points

Problem Statement

A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive xx-axis direction.

This robot will be given an instruction sequence ss. ss consists of the following two kinds of letters, and will be executed in order from front to back.

  • F : Move in the current direction by distance 11.
  • T : Turn 9090 degrees, either clockwise or counterclockwise.

The objective of the robot is to be at coordinates (x,y)(x, y) after all the instructions are executed. Determine whether this objective is achievable.

Constraints

  • ss consists of F and T.
  • 1s81 \leq |s| \leq 8 000000
  • xx and yy are integers.
  • x,ys|x|, |y| \leq |s|

Input

Input is given from Standard Input in the following format:

ss
xx yy

Output

If the objective is achievable, print Yes; if it is not, print No.


Sample Input 1Copy

Copy
FTFFTFFF
4 2

Sample Output 1Copy

Copy
Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T.


Sample Input 2Copy

Copy
FTFFTFFF
-2 -2

Sample Output 2Copy

Copy
Yes

The objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T.


Sample Input 3Copy

Copy
FF
1 0

Sample Output 3Copy

Copy
No

Sample Input 4Copy

Copy
TF
1 0

Sample Output 4Copy

Copy
No

Sample Input 5Copy

Copy
FFTTFF
0 0

Sample Output 5Copy

Copy
Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T.


Sample Input 6Copy

Copy
TTTT
1 0

Sample Output 6Copy

Copy
No


2025-03-14 (Fri)
10:52:14 +00:00