Palindrome Check 2
Time limit1sMemory limit1024 MB
Given a string with some unknown positions, find the fewest adaptive queries asking whether position i holds letter c that are needed to decide if the string is a palindrome.
- Level
Medium5 of 10
- Topics
- String, Math, Game theory
- Solved
- No attempts yet
문제
Ian has a string of length , where each character is one of the lowercase English letters (a, b, , z). If reading the characters of from back to front gives exactly , then is a palindrome. For example, abccba is a palindrome, but abccbba is not. Eunseong knows some of the characters of and wants to decide whether is a palindrome. Knowing only some characters may not be enough, so Eunseong can ask Ian the following kind of query.
- Eunseong asks Ian for a pair , where is an integer with and is a lowercase letter.
- Ian answers 1 if the -th character of from the left is , and 0 otherwise.
Eunseong does not want to bother Ian, so Eunseong wants to decide whether is a palindrome with as few queries as possible. Ian answers each query right away, so the next query can depend on earlier answers. Find the smallest such that Eunseong can decide whether is a palindrome with at most queries, no matter what is.
입력
The first line contains the integer .
The second line contains a string of length . For each , if the -th character of is a lowercase letter, Eunseong knows that the -th character of equals the -th character of . If the -th character of is ?, Eunseong does not know the -th character of .
출력
Print on the first line the minimum number of queries that guarantees Eunseong can decide whether is a palindrome.
제한
- Each character of is a lowercase English letter or
?.