Logo
(追記) (追記ここまで)

23717번 - Painter 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
서브태스크 참고 (추가 시간 없음) 1024 MB1781345975.641%

문제

You have recently started to study how to paint, and in one of the first classes you learned about the three primary colors: Red, Yellow, and Blue. If you combine these colors, you can produce many more colors. For now, the combinations that you have studied are the following:

  • Red + Yellow = Orange
  • Red + Blue = Purple
  • Yellow + Blue = Green
  • Red + Yellow + Blue = Gray

You still do not understand shades of colors, therefore the proportion and order of each color in the combination does not matter. For example, combining Red and Yellow produces the same result as combining Yellow and Red, as well as the same result as combining Red, Yellow, and Red again.

To practice your skills, you want to paint a 1-dimensional painting $P$ of length $N$. Your painting consists of $N$ squares. From left to right, $P_i$ represents the color of the $i-th square. Initially all squares are Uncolored, that is, $P_i$ = Uncolored for every 1ドル≤i≤N$.

In a single stroke, you can choose one of the three primary colors and apply it to a sequence of consecutive squares. In other words, you can choose a color $c$ and two integers $l$ and $r,ドル such that 1ドル≤l≤r≤N,ドル and apply color $c$ to all squares $P_j$ such that $l≤j≤r$. If the square being painted is currently Uncolored, then its color will become $c$. Otherwise, the color will be a combination of all the colors applied on this square so far and the new color $c,ドル as described in the list above.

In order to save time, you want to use as few strokes as possible. Given the description of the painting that you want to paint, figure out what is the minimum number of strokes required to paint it.

입력

The first line of the input gives the number of test cases, $T$. $T$ test cases follow.

Each test case starts with a line containing an integer $N,ドル representing the length of the painting. Then on the next line, there will be a string $P$ of length $N,ドル representing the painting. The $i$-th character represents the color of square $P_i,ドル according to the following list:

  • U = Uncolored
  • R = Red
  • Y = Yellow
  • B = Blue
  • O = Orange
  • P = Purple
  • G = Green
  • A = Gray

출력

For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is the minimum number of strokes required to paint the painting.

제한

  • 1ドル≤T≤100$.
  • 1ドル≤N≤10^5$.

Test Set 1 (9점)

시간 제한: 20 초

  • $P_i$ will be one of {Y, B, G}.

Test Set 2 (11점)

시간 제한: 40 초

  • $P_i$ will be one of {U, R, Y, B, O, P, G, A}.

예제 입력 1

2
9
YYYBBBYYY
6
YYGGBB

예제 출력 1

Case #1: 3
Case #2: 2

In Sample Case #1, the solution is to make 3ドル$ strokes: the first one using color Yellow from square 1ドル$ through 3ドル,ドル the second one using color Blue from square 4ドル$ through 6ドル,ドル and the third one using color Yellow from square 7ドル$ through 9ドル$. Notice that this particular painting required only primary colors.

In Sample Case #2, the solution is to make 2ドル$ strokes: the first one using color Yellow from square 1ドル$ through 4ドル,ドル and the second one using color Blue from square 3ドル$ through 6ドル$. Notice that squares 3ドル$ and 4ドル$ will be painted with both colors Yellow and Blue, which will result on it being Green.

예제 입력 2

1
5
ROAOR

예제 출력 2

Case #1: 3

In Sample Case #3, the solution is to make 3ドル$ strokes: the first one using color Red from square 1ドル$ through 5ドル,ドル the second one using color Yellow from square 2ドル$ through 4ドル,ドル and the third one using color Blue on square 3ドル$. Notice that square 3ドル$ is painted with all three primary colors, which will result in it being Gray.

힌트

출처

Contest > Google > Kick Start > Google Kick Start 2021 > Round H B번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /