아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Färgrobot

시간 제한1초메모리 제한1024 MB

요약
색칠된 칸의 나열과 명령 횟수 N이 주어질 때, 로봇을 가장 오른쪽으로 멀리 이동시키는 N개의 색 명령을 출력한다.
난이도

보통10점 중 6점

유형
동적 계획법, 그리디
정답자
아직 제출이 없습니다

문제

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 NN, writes out the sequence of NN commands that makes the robot go as far to the right as possible.

Figure 1: An illustration of the third sample case.

입력

The first line containes an integer NN, 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 NN commands may cause the robot to reach outside the row of squares.

출력

The program should output a string of NN 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.

예제4

  1. 예제 1

    입력
    1
    RRBBBGG
    
    예상 출력
    G
    
  2. 예제 2

    입력
    2
    GBBRGRGBRG
    
    예상 출력
    RB
    
  3. 예제 3

    입력
    3
    RGBGRRBGBBRG
    
    예상 출력
    BBR
    
  4. 예제 4

    입력
    4
    RBRBRBBRBRBRGRGGRGGGRBBRBRRBBRBRBRGBGBGBBGBGBGBBBGBGR
    
    예상 출력
    GBGR