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

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

Good Game

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

요약
A와 B 블록으로 이루어진 문자열에서 같은 문자가 인접한 2개 또는 3개를 차례로 제거해 모두 없앨 수 있으면 각 제거 위치를, 불가능하면 -1을 출력합니다.
난이도

보통10점 중 6점

유형
그리디, 스택, 문자열
정답자
아직 제출이 없습니다

문제

Finn is playing a game of Twos and Threes. Twos and Threes is a one-player game played on a one-dimensional board. In the starting position, there are NN blocks arranged in a row, with each block labelled either AA or BB. Blocks are numbered from 11 to NN from left to right. Finn is allowed to make moves of the following form:

  • Select 22 or 33 consecutive blocks that share the same label. Remove them from the board. Connect any remaining blocks together. Re-index the blocks from left to right, starting with index 11.

Finn wins the game if all blocks are removed from the board. Your task is to help Finn determine a winning sequence of moves, or determine if the game cannot be won.

입력

The first line of input will contain the integer NN.

The second line of input will contain the string SS, which is the starting position of the game.

There are NN characters in SS, and each of these characters in SS is either A or B.

출력

If there is a winning sequence of moves, output KK, the number of moves in the winning sequence. On each of the next KK lines, print an index ii, followed by one space, followed by a number jj, denoting a move that will remove the blocks currently at indices ii to i+j−1i + j - 1, inclusive.

If there is no winning sequence of moves, output -1.

If there are multiple winning sequences, then any winning sequence will be accepted. There is no need to minimize or maximize KK.

힌트

The sample output denotes this winning sequence:

\displaystyle \begin{align\*} & ABAAB\underline{BB}AA \\\ & AB\underline{AA}BAA \\\ & A\underline{BB}AA \\\ & \underline{AAA} \end{align\*}

예제1

  1. 예제 1

    입력
    9
    ABAABBBAA
    
    예상 출력
    4
    6 2
    3 2
    2 2
    1 3