Command Sequence

TimeLimit:1000MS  MemoryLimit:262144KB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description
There is a robot that can move by receiving a sequence of commands.

There are four types of command in the command sequence:


  • $U$: robot moves one unit up.

  • $D$: robot moves one unit down.

  • $L$: robot moves one unit left.

  • $R$: robot moves one unit right.



Now, given a command sequence of length $n$. You need to find out how many substrings of the command sequence satisfy that if the robot execute the substring command, it can return to the starting position.

A substring is a contiguous sequence of characters within a string. For instance, "the best of" is a substring of "It was the best of times". For example, "Itwastimes" is a subsequence of "It was the best of times", but not a substring.
Input
This problem contains multiple test cases.

The first line contains an integer $t$ $(1 \leq t \leq 20)$ indicating the number of test cases.

For each test case, the first line contains one integer $n$ ($2 \leq n \leq 10 ^ 5$).

The second line contains a $UDLR$ string of length $n$.
Output
For each test case, output one line one integer indicating the answer.
SampleInput
1
6
URLLDR
SampleOutput
2
Submit
题目统计信息详细
总AC数6
通过人数6
尝试人数6
总提交量10
AC率60.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: