CF1428B.Belted Rooms
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In the snake exhibition, there are n rooms (numbered 0 to n−1) arranged in a circle, with a snake in each room. The rooms are connected by n conveyor belts, and the i-th conveyor belt connects the rooms i and (i+1)modn. In the other words, rooms 0 and 1, 1 and 2, …, n−2 and n−1, n−1 and 0 are connected with conveyor belts.
The i-th conveyor belt is in one of three states:
- If it is clockwise, snakes can only go from room i to (i+1)modn.
- If it is anticlockwise, snakes can only go from room (i+1)modn to i.
- If it is off, snakes can travel in either direction.

Above is an example with 4 rooms, where belts 0 and 3 are off, 1 is clockwise, and 2 is anticlockwise.
Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there?
在蛇类展览中,有 n 个房间(编号为 0 到 n−1),呈环形排列,每个房间中有一条蛇。房间之间由 n 条传送带连接,其中第 i 条传送带连接房间 i 和房间 (i+1)modn。换言之,房间 0 与 1、1 与 2、…、n−2 与 n−1、n−1 与 0 分别由传送带连接。
第 i 条传送带有三种状态之一:
- 若为顺时针状态,则蛇只能从房间 i 移动到房间 (i+1)modn;
- 若为逆时针状态,则蛇只能从房间 (i+1)modn 移动到房间 i;
- 若为关闭状态,则蛇可沿任意方向通行。

上图是一个含 4 个房间的示例:传送带 0 和 3 处于关闭状态,传送带 1 为顺时针,传送带 2 为逆时针。
每条蛇都希望离开自己所在的房间,并在之后返回该房间。若某房间满足:位于其中的蛇能够离开该房间,并通过传送带最终回到该房间,则称该房间为可返回的。问:共有多少个可返回的房间?
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤1000): the number of test cases. The description of the test cases follows.
The first line of each test case description contains a single integer n (2≤n≤300000): the number of rooms.
The next line of each test case description contains a string s of length n, consisting of only '<', '>' and '-'.
- If $s_{i} = $ '>', the i-th conveyor belt goes clockwise.
- If $s_{i} = $ '<', the i-th conveyor belt goes anticlockwise.
- If $s_{i} = $ '-', the i-th conveyor belt is off.
It is guaranteed that the sum of n among all test cases does not exceed 300000.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤1000):测试用例的数量。随后是各测试用例的描述。
每个测试用例描述的第一行包含一个整数 n(2≤n≤300000):房间的数量。
每个测试用例描述的下一行包含一个长度为 n 的字符串 s,仅由字符 '<'、'>' 和 '-' 组成。
- 若 $s_{i} = $ '>',则第 i 个传送带顺时针运行;
- 若 $s_{i} = $ '<',则第 i 个传送带逆时针运行;
- 若 $s_{i} = $ '-',则第 i 个传送带关闭。
保证所有测试用例的 n 值之和不超过 300000。
输出格式
For each test case, output the number of returnable rooms.
对于每个测试用例,输出可返回的房间数量。
输入输出样例
输入#1
4 4 -><- 5 >>>>> 3 <-- 2 <>
输出#1
3 5 3 0
说明/提示
In the first test case, all rooms are returnable except room 2. The snake in the room 2 is trapped and cannot exit. This test case corresponds to the picture from the problem statement.
In the second test case, all rooms are returnable by traveling on the series of clockwise belts.
在第一个测试用例中,除房间 2 外,其余所有房间均可返回。房间 2 中的蛇被困住,无法离开。该测试用例对应题目陈述中的图片。
在第二个测试用例中,所有房间均可通过沿顺时针方向的传送带序列行进而返回。
输入解题思路,AI测评打分。不知道怎么写?