Logo
(追記) (追記ここまで)

24841번 - Palindrome Free Strings 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
서브태스크 참고 (추가 시간 없음) 1024 MB161574739.167%

문제

You are given a string $S$ 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 5ドル$ or more.

입력

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

Each test case consists of two lines.

The first line of each test case contains an integer $N,ドル denoting the length of the string $S$.

The second line of each test case contains a string $S$ of length $N$.

출력

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

제한

  • 1ドル≤T≤100$.
  • $S$ only consists of characters 0, 1 and ?.

Test Set 1 (13점)

시간 제한: 20 초

  • 1ドル≤N≤15$.

Test Set 2 (18점)

시간 제한: 90 초

  • 1ドル≤N≤5×10^4$.

예제 입력 1

2
9
100???001
5
100??

예제 출력 1

Case #1: IMPOSSIBLE
Case #2: POSSIBLE

힌트

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 5ドル$ characters form a palindrome of length 5ドル$. Otherwise, we get 100001001, the first 6ドル$ characters are a palindrome of length 6ドル$.

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 5ドル$ characters form a palindrome of length 5ドル$. Otherwise, we get 100100001, the last 6ドル$ characters are a palindrome of length 6ドル$.

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.

출처

Contest > Google > Kick Start > Google Kick Start 2022 > Round A C번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /