RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0519

Photoshoot

Bronze II 브론즈 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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 \leq N \leq 2\cdot 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.

Problem credits: Aryansh Shrivastava

제약

SCORING

  • Test cases 2-6 satisfy \(N\le 1000\).
  • Test cases 7-11 satisfy no additional constraints.

Problem credits: Aryansh Shrivastava

입력 형식

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.

출력 형식

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

예제 1
입력
14
GGGHGHHGHHHGHG
출력
1
설명

In this example, it suffices to reverse the prefix consisting of the first six
cows.

   GGGHGHHGHHHGHG (Before)
-> HGHGGGHGHHHGHG (After)

Before the reversal, four Guernseys were at even positions. After the reversal,
six Guernseys are at even positions. It is impossible for there to be more than
six Guernseys at even positions.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2021-2022 > US Open > Bronze

태그

평가 및 의견

Photoshoot

개요
출제자 난이도 Bronze II 브론즈 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Photoshoot

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8