测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A10099. Marbles

编程题 普及/提高-

题目描述

The first line of the input contains a single integer $n$ ( $2<=n<=1000000$ ) — the length of the paths.

The second line of the input contains a string consisting of $n-1$ characters (each of which is either 'N', 'E', 'S', or 'W') — the first grid path. The characters can be thought of as the sequence of moves needed to traverse the grid path. For example, the example path in the problem statement can be expressed by the string "NNESWW".

The third line of the input contains a string of $n-1$ characters (each of which is either 'N', 'E', 'S', or 'W') — the second grid path.

输入格式

Print "YES" (without quotes) if it is possible for both marbles to be at the end position at the same time. Print "NO" (without quotes) otherwise. In both cases, the answer is case-insensitive.

输出格式

In the first sample, the first grid path is the one described in the statement. Moreover, the following sequence of moves will get both marbles to the end: NNESWWSWSW.

In the second sample, no sequence of moves can get both marbles to the end.

输入输出样例

输入 #1
7
NNESWW
SWSWSW
输出 #1
YES
输入 #2
3
NN
SS
输出 #2
NO

说明/提示

In the first sample, the first grid path is the one described in the statement. Moreover, the following sequence of moves will get both marbles to the end: NNESWWSWSW.

In the second sample, no sequence of moves can get both marbles to the end.
上一题 去做题 下一题