#63750. [ USACO 2022 Open Bronze]Photoshoot

[ USACO 2022 Open Bronze]Photoshoot

暂无测试数据。

英文题面

Farmer John, desperate to win the award for best cow photographer at the county fair, is trying to take the perfect photograph of his $N$ cows $(2≤N≤2⋅10^5, N$ even).

Farmer John owns cows of two potential breeds: Guernseys and Holsteins. To make his photo as aesthetic as possible, he wants to line up his cows so that as many Guernseys are in even-numbered positions in the line as possible (the first position in the line is an odd position, the next is an even position, and so on). Due to his lack of strong communication with his cows, the only way he can achieve his goal is by asking even length "prefixes" of his cows to reverse themselves (a prefix consists of the range of cows from the first cow up to the $j$th cow for some position $j$).

Please count the minimum number of reversals required for Farmer John to achieve his goal.

译文

迫切希望在郡县集市上赢得最佳奶牛摄影师的 Farmer John 正在尝试为他的 $N$头奶牛拍摄一张完美的照片($2≤N≤2⋅10^5$,$N$为偶数)。

Farmer John 拥有两种品种的奶牛:更赛牛(Guernsey)和荷斯坦牛(Holstein)。为了使他的照片尽可能地艺术,他想把他的奶牛排成一排,使得尽可能多的更赛牛处于队列中的偶数位置(队列中的第一个位置是奇数位置,下一个是偶数位置,以此类推)。由于他与他的奶牛缺乏有效的沟通,他可以达到目的的唯一方法是让他的奶牛的偶数长的「前缀」进行反转(一个前缀指的是对于某个位置 $j$,从第一头奶牛到第 $j$ 头奶牛范围内的所有奶牛)。

请计算 Farmer John 达到目的所需要的最小反转次数。

输入格式

The first line of input contains the value of $N$.

The second line contains a string of length $N$, specifying the initial ordering of the cows from left to right. Each 'H' represents a Holstein, while each 'G' represents a Guernsey.

输入的第一行包含 $N$ 的值。

第二行包含一个长为 $N$ 的字符串,给出初始时所有奶牛从左到右的排列方式。每个 'H' 代表一头荷斯坦牛,每个 'G' 代表一头更赛牛。

输出格式

Output the minimum number of reversals needed on a single line.

输出一行,包含达到目的所需要的最小反转次数。

数据范围

  • Test cases 2-6 satisfy $N≤1000$.

  • Test cases 7-11 satisfy no additional constraints.

  • 测试点 2-6 满足 $N≤1000$。

  • 测试点 7-11 没有额外限制。

14
GGGHGHHGHHHGHG
1