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

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

Tetris Generation

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

요약
일곱 종류의 테트로미노 문자로 이루어진 문자열이 주어질 때, 7개 묶음 생성기에서 임의 위치에서 시작해 만들어질 수 있는지, 즉 같은 문자가 일곱 번 연속 나오지 않는지 판정한다.
난이도

보통10점 중 5점

유형
문자열, 슬라이딩 윈도우, 그리디, 구현
정답자
아직 제출이 없습니다

문제

The classic game Tetris involves arranging falling tetrominoes on a board. There are seven different tetrominoes, each named after a letter that resembles their shape: J, L, S, Z, I, O, and T. 

In the original Tetris, the player would receive one tetromino at a time, and each tetromino would be chosen from among the seven possibilities independently and uniformly at random. This meant that any sequence of tetrominoes could appear in a game, such as numerous I tetrominoes in a row. Modern versions of Tetris remove these streaks by generating tetrominoes in groups of seven: The first seven tetrominoes in a game will be one of each of the seven different tetrominoes in a random order. The next seven tetrominoes will also be one of each of the seven different tetrominoes in a random order (possibly but not necessarily different from the ordering of the first seven). Same goes for the next seven, and so on and so forth. With this generator, it is still possible to get two of the same tetromino in a row (for example, the seventh and eighth tetrominoes in the game can be the same as each other), but it is not possible to get three of the same type in a row.

Given a sequence of tetrominoes, determine whether it is possible for a modern Tetris generator to produce that sequence at some point in a game.

입력

The first line of input contains an integer tt (1≤t≤1051 \le t \le 10^5), which is the number of test cases.

Each of the next tt lines contains a single string ss (1≤∣s∣≤1,000,s∈J,L,S,Z,I,O,T\*1 \le |s| \le 1{,}000, s \in \\{\texttt{J}, \texttt{L}, \texttt{S}, \texttt{Z}, \texttt{I}, \texttt{O}, \texttt{T}\\}^\*). This string represents a sequence of tetrominoes, and is a single test case.

The sum of the lengths of all input test cases will not exceed 10510^5.

출력

For each test case, output a single line with a single integer, which is 1 if the sequence can be generated by a modern Tetris generator, and 0 otherwise.

예제1

  1. 예제 1

    입력
    2
    JJTO
    JJTT
    
    예상 출력
    1
    0