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

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

A Color Game

면접 대비

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

요약
색이 칠해진 막대가 일렬로 주어질 때, 같은 색이 m개 이상 연속한 묶음을 없애는 과정을 반복해서 모든 막대를 제거할 수 있는지 판정한다.
난이도

보통10점 중 7점

유형
동적 계획법, 구간, 배열, 재귀
정답자
아직 제출이 없습니다

문제

Playing games is fun. For programmers, however, playing games with programs is even more fun. Consider a simple single-user tabletop game as follows. Given a row of sticks, each of which is in one of the seven colors, red (R), green (G), blue (B), cyan (C), magenta (M), yellow (Y), and key (K), the goal of the game is to eliminate all the sticks by repeating the following rules.

  • Consecutive sticks with the same color can be eliminated if the size of them is not less than m.
  • The remaining sticks will move closer together.

For the case where the row is BBBRRRRRRGGGB and m is 3, all the sticks can be successfully eliminated as the following steps:

  1. BBBRRRRRRGGGB
  2. BBBGGGB (By eliminating all red sticks)
  3. BBBB (By eliminating all green sticks)
  4. (By eliminating all blue sticks)

For the same row of sticks with m = 4, however, it is no way to eliminate all the sticks.

Given a row of n sticks and the value of m, your task is to determine if it is possible to eliminate all the sticks.

입력

Each test case is given as a string that is the row of sticks and an integer m.

출력

Output Yes if it is possible to eliminate all the sticks. Otherwise, output No.

제한

  • 0 < n, m ≤ 500

예제2

  1. 예제 1

    입력
    BBBRRRRRRGGGB 3
    
    예상 출력
    Yes
    
  2. 예제 2

    입력
    BBBRRRRRRGGGB 4
    
    예상 출력
    No