루미 알고리즘

#1405골드Färgrobot

PO 2016 온라인 예선코딩출제 Pär Söderhjelm영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

A robot can move along a row of colored squares. Every square can be either red, green or blue. A command to the robot is a color. The robot responds by moving to the right until it stands on the color specified by the command. Write a program that, for a given sequence of squares and a number N, writes out the sequence of N commands that makes the robot go as far to the right as possible.

(그림은 원문 저장소에서 볼 수 있습니다)

Figure 1: An illustration of the third sample case.

Input

The first line contains an integer N, the number of commands to give to the robot. The second line contains a string of letters, R , G, or B, which specifies the color of each square in the row, from left to right. The string contains less than 200 characters, and is always sufficiently long that no sequence of N commands may cause the robot to reach outside the row of squares.

Output

The program should output a string of N characters, each being R, G, or B, which constitutes the sequence of commands you should give to the robot to make it move as far as possible along the row of squares. If there are several sequences that accomplish this, you may output anyone of them.

Limits

  1. In one test case worth 20 points, N=4 and the sequence is 'RGBGGBGRBRBRGRGRB' (i.e. the case shown on this year's PO poster)
  2. In other test cases worth 30 points, 1 ≤ N ≤ 4.
  3. In test cases worth 20 points, 5 ≤ N ≤ 10.
  4. In test cases worth 30 points, 20 ≤ N ≤ 25.

예제

예제 1

입력
1
RRBBBGG
출력
G

예제 2

입력
2
GBBRGRGBRG
출력
RB

예제 3

입력
3
RGBGRRBGBBRG
출력
BBR

예제 4

입력
4
RBRBRBBRBRBRGRGGRGGGRBBRBRRBBRBRBRGBGBGBBGBGBGBBBGBGR
출력
GBGR

출처 표기

출처: Programmeringsolympiaden 2016년 온라인 예선 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.