#P16871. [GKS 2022 #A] Palindrome Free Strings
[GKS 2022 #A] Palindrome Free Strings
Problem Description
You are given a string consisting of characters , , and . You can replace each with either or . Your task is to find if it is possible to assign each to either or such that the resulting string has no substrings that are palindromes of length or more.
Input Format
The first line of the input gives the number of test cases, . test cases follow.
Each test case consists of two lines.
The first line of each test case contains an integer , denoting the length of the string .
The second line of each test case contains a string of length .
Output Format
For each test case, output one line containing Case : , where is the test case number (starting from ) and is POSSIBLE if there is a possible resulting string that has no palindromic substrings of length or more, or IMPOSSIBLE otherwise.
2
9
100???001
5
100??
Case #1: IMPOSSIBLE
Case #2: POSSIBLE
Hint
In Sample Case #, 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 and replace the last question mark with , we get . If the remaining is replaced by , we get , then the first characters form a palindrome of length . Otherwise, we get , the first characters are a palindrome of length .
If we replace first question mark with we get . If the remaining is replaced by , we get , then the last characters form a palindrome of length . Otherwise, we get , the last characters are a palindrome of length .
Hence, there is no way to get a valid string.
In Sample Case #, one of the valid strings after replacing all the is .
Limits
.
only consists of characters , and .
Test Set
.
Test Set
.