CF1644E.Expand the Path
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The first line contains a single integer t ( 1≤t≤104 ) — the number of testcases.
The first line of each testcase contains the single integer n ( 2≤n≤108 ) — the number of rows and columns in the grid.
The second line of each testcase contains a non-empty string s , consisting only of characters D and R, — the initial path of the robot. This path doesn't lead the robot outside the grid.
The total length of strings s over all testcases doesn't exceed 2⋅105 .
输入格式
For each testcase, print a single integer — the number of cells such that there exists at least one sequence of modifications that the robot visits this cell on the modified path and doesn't move outside the grid.
输出格式
In the first testcase, it's enough to consider the following modified paths:
- RD → RRD → RRRD → RRRDD → RRRDDD — this path visits cells (1,1) , (1,2) , (1,3) , (1,4) , (2,4) , (3,4) and (4,4) ;
- RD → RRD → RRDD → RRDDD — this path visits cells (1,1) , (1,2) , (1,3) , (2,3) , (3,3) and (4,3) ;
- RD → RDD → RDDD — this path visits cells (1,1) , (1,2) , (2,2) , (3,2) and (4,2) .
Thus, the cells that are visited on at least one modified path are: (1,1) , (1,2) , (1,3) , (1,4) , (2,2) , (2,3) , (2,4) , (3,2) , (3,3) , (3,4) , (4,2) , (4,3) and (4,4) .
In the second testcase, there is no way to modify the sequence without moving the robot outside the grid. So the only visited cells are the ones that are visited on the path DRDRDRDR.
In the third testcase, the cells that are visited on at least one modified path are: (1,1) , (2,1) and (3,1) .
Here are the cells for all testcases:
输入输出样例
输入#1
3 4 RD 5 DRDRDRDR 3 D
输出#1
13 9 3
说明/提示
In the first testcase, it's enough to consider the following modified paths:
- RD → RRD → RRRD → RRRDD → RRRDDD — this path visits cells (1,1) , (1,2) , (1,3) , (1,4) , (2,4) , (3,4) and (4,4) ;
- RD → RRD → RRDD → RRDDD — this path visits cells (1,1) , (1,2) , (1,3) , (2,3) , (3,3) and (4,3) ;
- RD → RDD → RDDD — this path visits cells (1,1) , (1,2) , (2,2) , (3,2) and (4,2) .
Thus, the cells that are visited on at least one modified path are: (1,1) , (1,2) , (1,3) , (1,4) , (2,2) , (2,3) , (2,4) , (3,2) , (3,3) , (3,4) , (4,2) , (4,3) and (4,4) .
In the second testcase, there is no way to modify the sequence without moving the robot outside the grid. So the only visited cells are the ones that are visited on the path DRDRDRDR.
In the third testcase, the cells that are visited on at least one modified path are: (1,1) , (2,1) and (3,1) .
Here are the cells for all testcases: