Palindrome Check
Time limit1sMemory limit1024 MB
Decide whether a hidden sequence of length N is a palindrome using only count_pair and find_character queries under a limit on query sizes.
- Level
Medium6 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
KOI is running a new event to promote its algorithm contest. To take part, you must determine whether a secret sequence , known only to KOI, is a palindrome.
A sequence is a palindrome if it stays the same when reversed. A sequence of length is a palindrome if holds for every . For example, and are palindromes, but and are not.
You initially know the length of the secret sequence . Each element of is an integer from 1 to 5,000. To help the participants, KOI provides two machines.
- The
count_pairmachine takes three distinct integers , , and . It returns the number of equal pairs among , , and . For example, if , it returns 3. - The
find_charactermachine takes an integer and a list of integers . It returns 1 if some in satisfies , and 0 otherwise.
Every number you input to either machine must be an integer from 0 to . The sum of the sizes of the lists you input to find_character must be at most .
You must determine whether is a palindrome while using the machines a small number of times.
Constraints
- (for every )
- Let be the sum of over all test cases in one input. Then .
- The grader is not adaptive. is fixed when the grader starts and does not change with the queries.