#P16124. [USTCPC 2026] Line of Pac-Man

    ID: 18117 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>动态规划 DP贪心2026高校校赛

[USTCPC 2026] Line of Pac-Man

Background

“Waaah—! Why is Pac-Man coming out of my bento?!”

Kruskal-chan stared in horror at the sandwich in her hand. The densely packed sesame seeds suddenly turned into countless tiny Pac-Men, crazily moving left and right! Even stranger, bean-shaped specks of light appeared in the air and were swallowed one by one.

“Could this be the truth of the universe?” Trembling, Kruskal-chan took out her notebook and decided to calculate the minimum number of beans that would be eaten.

Problem Description

On the integer points of the segment 1xn1 \le x \le n, there are some beans and Pac-Men. There are two types of Pac-Men: one moves left at unit speed, and the other moves right at unit speed. When a Pac-Man passes a bean, the bean will be eaten. When two Pac-Men meet, you need to choose one Pac-Man to eat the other; the remaining Pac-Man keeps its moving direction unchanged.

Find: the minimum total number of beans that will be eaten.

Note: the positions of Pac-Men can change continuously, not discretely.

Input Format

This problem has multiple test cases.

The first line contains an integer TT (1T1051 \le T \le 10^5), the number of test cases.

For each test case, the first line contains an integer, the right endpoint of the segment nn (1n1051 \le n \le 10^5).

The next line contains a string of length nn consisting only of .o<>, representing an empty space, a bean, a left-moving Pac-Man, and a right-moving Pac-Man, respectively.

It is guaranteed that n105\sum n \le 10^5.

Output Format

Output TT lines. Each line contains one integer, the minimum total number of beans that will be eaten.

2
6
o>.<oo
2
<>
1
0

Hint

In the first sample, when two Pac-Men meet, choose to keep the left-moving Pac-Man. In this way, only the leftmost bean will be eaten in the end, so the answer is 11.

Translated by ChatGPT 5