CF1428B.Belted Rooms

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In the snake exhibition, there are nn rooms (numbered 00 to n−1n - 1) arranged in a circle, with a snake in each room. The rooms are connected by nn conveyor belts, and the ii-th conveyor belt connects the rooms ii and (i+1) mod n(i+1) \bmod n. In the other words, rooms 00 and 11, 11 and 22, …\ldots, n−2n-2 and n−1n-1, n−1n-1 and 00 are connected with conveyor belts.

The ii-th conveyor belt is in one of three states:

  • If it is clockwise, snakes can only go from room ii to (i+1) mod n(i+1) \bmod n.
  • If it is anticlockwise, snakes can only go from room (i+1) mod n(i+1) \bmod n to ii.
  • If it is off, snakes can travel in either direction.

Above is an example with 44 rooms, where belts 00 and 33 are off, 11 is clockwise, and 22 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?

在蛇类展览中,有 nn 个房间(编号为 00 到 n−1n - 1),呈环形排列,每个房间中有一条蛇。房间之间由 nn 条传送带连接,其中第 ii 条传送带连接房间 ii 和房间 (i+1) mod n(i+1) \bmod n。换言之,房间 00 与 11、11 与 22、…\ldots、n−2n-2 与 n−1n-1、n−1n-1 与 00 分别由传送带连接。

第 ii 条传送带有三种状态之一:

  • 若为顺时针状态,则蛇只能从房间 ii 移动到房间 (i+1) mod n(i+1) \bmod n;
  • 若为逆时针状态,则蛇只能从房间 (i+1) mod n(i+1) \bmod n 移动到房间 ii;
  • 若为关闭状态,则蛇可沿任意方向通行。

上图是一个含 44 个房间的示例:传送带 00 和 33 处于关闭状态,传送带 11 为顺时针,传送带 22 为逆时针。

每条蛇都希望离开自己所在的房间,并在之后返回该房间。若某房间满足:位于其中的蛇能够离开该房间,并通过传送带最终回到该房间,则称该房间为可返回的。问:共有多少个可返回的房间?

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤10001 \le t \le 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 nn (2≤n≤300 0002 \le n \le 300\,000): the number of rooms.

The next line of each test case description contains a string ss of length nn, consisting of only '<', '>' and '-'.

  • If $s_{i} = $ '>', the ii-th conveyor belt goes clockwise.
  • If $s_{i} = $ '<', the ii-th conveyor belt goes anticlockwise.
  • If $s_{i} = $ '-', the ii-th conveyor belt is off.

It is guaranteed that the sum of nn among all test cases does not exceed 300 000300\,000.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000):测试用例的数量。随后是各测试用例的描述。

每个测试用例描述的第一行包含一个整数 nn(2≤n≤300 0002 \le n \le 300\,000):房间的数量。

每个测试用例描述的下一行包含一个长度为 nn 的字符串 ss,仅由字符 '<'、'>' 和 '-' 组成。

  • 若 $s_{i} = $ '>',则第 ii 个传送带顺时针运行;
  • 若 $s_{i} = $ '<',则第 ii 个传送带逆时针运行;
  • 若 $s_{i} = $ '-',则第 ii 个传送带关闭。

保证所有测试用例的 nn 值之和不超过 300 000300\,000。

输出格式

For each test case, output the number of returnable rooms.

对于每个测试用例,输出可返回的房间数量。

输入输出样例

  • 输入#1

    4
    4
    -&gt;&lt;-
    5
    &gt;&gt;&gt;&gt;&gt;
    3
    &lt;--
    2
    &lt;&gt;

    输出#1

    3
    5
    3
    0

说明/提示

In the first test case, all rooms are returnable except room 22. The snake in the room 22 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.

在第一个测试用例中,除房间 22 外,其余所有房间均可返回。房间 22 中的蛇被困住,无法离开。该测试用例对应题目陈述中的图片。

在第二个测试用例中,所有房间均可通过沿顺时针方向的传送带序列行进而返回。

输入解题思路,AI测评打分。不知道怎么写?

首页