CF1428B.Belted Rooms

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

In the snake exhibition, there are nn rooms (numbered 00 to n1n - 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)modn(i+1) \bmod n . In the other words, rooms 00 and 11 , 11 and 22 , \ldots , n2n-2 and n1n-1 , n1n-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)modn(i+1) \bmod n .
  • If it is anticlockwise, snakes can only go from room (i+1)modn(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?

输入格式

Each test contains multiple test cases. The first line contains a single integer tt ( 1t10001 \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 ( 2n3000002 \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 300000300\,000 .

输出格式

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 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.

首页