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

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

Palindrome Free Strings

메모리 제한1024 MB

요약
각 물음표를 0 또는 1로 바꿔서 길이 5 이상인 회문 부분 문자열이 하나도 없는 문자열을 만들 수 있는지 판별한다.
난이도

보통10점 중 7점

유형
동적 계획법, 문자열, 비트 연산
정답자
아직 제출이 없습니다

문제

You are given a string SS consisting of characters 0, 1, and ?. You can replace each ? with either 0 or 1. Your task is to find if it is possible to assign each ? to either 0 or 1 such that the resulting string has no substrings that are palindromes of length 55 or more.

입력

The first line of the input gives the number of test cases, TT. TT test cases follow.

Each test case consists of two lines.

The first line of each test case contains an integer NN, denoting the length of the string SS.

The second line of each test case contains a string SS of length NN.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is POSSIBLE if there is a possible resulting string that has no palindromic substrings of length 55 or more, or IMPOSSIBLE otherwise.

제한

  • 1≤T≤1001≤T≤100.
  • SS only consists of characters 0, 1 and ?.

힌트

In Sample Case #1, to prevent the whole string from being a palindrome, the first and last question mark must be different characters.

If we replace first question mark with 0 and replace the last question mark with 1, we get 1000?1001. If the remaining ? is replaced by 1, we get 100011001, then the first 55 characters form a palindrome of length 55. Otherwise, we get 100001001, the first 66 characters are a palindrome of length 66.

If we replace first question mark with 1 we get 1001?0001. If the remaining ? is replaced by 1, we get 100110001, then the last 55 characters form a palindrome of length 55. Otherwise, we get 100100001, the last 66 characters are a palindrome of length 66.

Hence, there is no way to get a valid string.

In Sample Case #2, one of the valid strings after replacing all the ? is 10011.

예제1

  1. 예제 1

    입력
    2
    9
    100???001
    5
    100??
    
    예상 출력
    Case #1: IMPOSSIBLE
    Case #2: POSSIBLE