Codeforces Raif Round 1 (Div. 1 + Div. 2)
B
Belted Rooms
Codeforces
1200
原题
← AC →
翻译中…

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) \bmod n$. In the other words, rooms $0$ and $1$, $1$ and $2$, $\ldots$, $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) \bmod n$.
  • If it is anticlockwise, snakes can only go from room $(i+1) \bmod n$ to $i$.
  • If it is off, snakes can travel in either direction.
翻译中…

image

翻译中…

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?

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \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 $n$ ($2 \le n \le 300\,000$): 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 $300\,000$.

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

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.

翻译中…

样例

Input #1
4
4
-><-
5
>>>>>
3
<--
2
<>
Output #1
3
5
3
0
InputCopy OutputCopy
题目信息
题号
1428B
时间限制
1 s
内存限制
256 MB
标签
图论
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。