Guard Evaders

면접 대비

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

요약
L, F, R 중 하나를 향하는 경비병들이 있을 때, 각 통과가 해당 틈의 두 경비병 방향을 바꾸는 규칙 아래 p명 모두 무사히 지나갈 수 있는지 판정한다.
난이도

보통10점 중 6점

유형
백트래킹, 게임 이론, 시뮬레이션
정답자
아직 제출이 없습니다

문제

Here is a new game to play. You and a team of your friends sequentially run through a row of guards (a bit like in the playground game "Rover, Red Rover.") The guards may be facing forward, left, or right. When facing forward, they can't see you coming until it's too late, because they have very limited peripheral vision. (Perhaps they wear blinders.) They can similarly not see you if they are facing sideways away from you as you come through. However, as soon as you pass between a pair of guards, they do hear you and turn to face where you came through, so that if you tried to pass through the same pair of guards again they would be positioned to stop you. Two guards stop a player trying to pass between them if at least one of them is facing the gap that the player attempts to run through.

More formally: Given a row of gg guards labeled 11 through gg from left to right, each player chooses to run through the gap between guards ii and i+1i+1 (for some 1≤i≤g−11 \leq i \leq g-1). A player cannot run to the left of the first guard or to the right of the last. If either guard ii is facing right or guard i+1i+1 is facing left (or both), the player is caught. Otherwise, guard ii turns to face right and guard i+1i+1 turns to face left. No other guards change orientation.

Given how the guards are initially facing and the number of players pp on your team, can all pp players run through the guards without getting caught?

입력

The first line of input contains two positive integers: the number of guards gg (2≤g≤10)(2 \leq g \leq 10) and the number of players on your team pp (1≤p≤50)(1\leq p \leq 50). The second line contains a string of uppercase letters representing the directions each of the guards is initially facing. Each character in the string is either L (left), F (forward), or R (right). The first illustration shows four guards configured according to input string RFRL.

출력

If with optimal play all players can make it past the guards without getting caught, print 1. Otherwise print 0.

예제3

  1. 예제 1

    입력
    4 1
    RFRL
    
    예상 출력
    1
    
  2. 예제 2

    입력
    4 2
    RFRL
    
    예상 출력
    0
    
  3. 예제 3

    입력
    4 4
    FFFF
    
    예상 출력
    1