codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1326D1.md (2075B)


      1 Source: https://codeforces.com/problemset/problem/1326/D1
      2 
      3 D1. Prefix-Suffix Palindrome (Easy version)
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 This is the easy version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.
     22 
     23 You are given a string $s$, consisting of lowercase English letters. Find the longest string, $t$, which satisfies the following conditions:
     24 
     25 * The length of $t$ does not exceed the length of $s$.
     26 * $t$ is a palindrome.
     27 * There exists two strings $a$ and $b$ (possibly empty), such that $t = a + b$ ( "$+$" represents concatenation), and $a$ is prefix of $s$ while $b$ is suffix of $s$.
     28 
     29 Input
     30 
     31 The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 1000$), the number of test cases. The next $t$ lines each describe a test case.
     32 
     33 Each test case is a non-empty string $s$, consisting of lowercase English letters.
     34 
     35 It is guaranteed that the sum of lengths of strings over all test cases does not exceed $5000$.
     36 
     37 Output
     38 
     39 For each test case, print the longest string which satisfies the conditions described above. If there exists multiple possible solutions, print any of them.
     40 
     41 Example
     42 
     43 Input
     44 
     45 ```
     46 5
     47 a
     48 abcdfdcecba
     49 abbaxyzyx
     50 codeforces
     51 acbba
     52 ```
     53 
     54 Output
     55 
     56 ```
     57 a
     58 abcdfdcba
     59 xyzyx
     60 c
     61 abba
     62 ```
     63 
     64 Note
     65 
     66 In the first test, the string $s = $"a" satisfies all conditions.
     67 
     68 In the second test, the string "abcdfdcba" satisfies all conditions, because:
     69 
     70 * Its length is $9$, which does not exceed the length of the string $s$, which equals $11$.
     71 * It is a palindrome.
     72 * "abcdfdcba" $=$ "abcdfdc" $+$ "ba", and "abcdfdc" is a prefix of $s$ while "ba" is a suffix of $s$.
     73 
     74 It can be proven that there does not exist a longer string which satisfies the conditions.
     75 
     76 In the fourth test, the string "c" is correct, because "c" $=$ "c" $+$ "" and $a$ or $b$ can be empty. The other possible solution for this test is "s".