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

Feeding the Cows

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

의견: 0

설명

Farmer John has \(N\) (\(1 \le {N} \le {10^5}\)) cows, the breed of each being
either a Guernsey or a Holstein. They have lined up horizontally with the cows occupying positions
labeled from
\(1\dots N\).

Since all the cows are hungry, FJ decides to plant grassy patches on some
of the positions \(1\dots N\). Guernseys and Holsteins prefer different types of
grass, so if Farmer John decides to plant grass at some location, he must choose
to planting either Guernsey-preferred grass or Holstein-preferred grass --- he
cannot plant both at the same location. Each patch of grass planted can feed an
unlimited number of cows of the appropriate breed.

Each cow is willing to move a maximum of \(K\) (\(0 \le {K} \le N-1\)) positions to
reach a patch. Find the minimum number of patches needed to feed all the cows.
Also, print a configuration of patches that uses the minimum amount of patches
needed to feed the cows. Any configuration that satisfies the above conditions
will be considered correct.

Problem credits: Mythreya Dharani

제약

SCORING

  • Inputs 2 through 4 have \(N \le 10\).
  • Inputs 5 through 8 have \(N \le 40\).
  • Inputs 9 through 12 have \(N \le 10^5\).

Problem credits: Mythreya Dharani

입력 형식

Each input contains \(T\) test cases, each describing an arrangement of cows. The
first line of input contains \(T\) (\(1 \le T \le 10\)). Each of the \(T\) test cases
follow.

Each test case starts with a line containing \(N\) and \(K\). The next line will
contain a string of length \(N\), where each character denotes the breed of the
\(i\)th cow (G meaning Guernsey and H meaning Holstein).

출력 형식

For each of the \(T\) test cases, please write two lines of output. For the first
line, print the minimum number of patches needed to feed the cows. For the
second line, print a string of length \(N\) that describes a configuration that
feeds all the cows with the minimum number of patches. The \(i\)th character,
describing the \(i\)th position, should be a '.' if there is no patch, a 'G' if
there is a patch that feeds Guernseys, and a 'H' if it feeds Holsteins. Any
valid configuration will be accepted.

예제 1
입력
6
5 0
GHHGG
5 1
GHHGG
5 2
GHHGG
5 3
GHHGG
5 4
GHHGG
2 1
GH
출력
5
GHHGG
3
.GH.G
2
..GH.
2
...GH
2
...HG
2
HG
설명

Note that for some test cases, there are multiple acceptable configurations that
manage to feed all cows while using the minimum number of patches. For example,
in the fourth test case, another acceptable answer would be:

.GH..

This corresponds to placing a patch feeding Guernseys on the 2nd position and a
patch feeding Holsteins on the third position. This uses the optimal number of
patches and ensures that all cows are within 3 positions of a patch they prefer.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2022-2023 > December > Bronze

태그

평가 및 의견

Feeding the Cows

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

Log in to rate problems.

개별 의견

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

풀이 제출

Feeding the Cows

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