[Solution] Building Palindromes Kick Start Solution
Anna has a row of blocks, each with exactly one letter from A
to Z
written on it. The blocks are numbered from left to right.
Today, she is learning about palindromes. A palindrome is a string that is the same written forwards and backwards. For example, ANNA
, RACECAR
, AAA
and X
are all palindromes, while AB
, FROG
and YOYO
are not.
Bob wants to test how well Anna understands palindromes, and will ask her questions. The i-th question is: can Anna form a palindrome using all of the blocks numbered from to , inclusive? She may rearrange the blocks if necessary. After each question, Anna puts the blocks back in their original positions.
Please help Anna by finding out how many of Bob's questions she can answer "yes" to.
Input
The first line of the input gives the number of test cases, . test cases follow. Each test case starts with a line containing the two integers and , the number of blocks and the number of questions,
respectively. Then, another line follows, containing a string of uppercase characters (A
to Z
). Then, lines follow. The i-th line contains the two integers and , describing the i-th question.
Output
For each test case, output one line containing Case #:
, where is the test case number (starting from ) and is the number of questions Anna can answer "yes" to.
Limits
Time limit: 30 seconds.
Memory limit: 1 GB.
.
.
Test Set 1
.
.
Test Set 2
.
.
No comments:
Post a Comment