Chef Hates Palindromes
All submissions for this problem are available.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef's birthday is coming soon! His friend Fehc is going to send him a string of length N as a gift. Knowing that Chef doesn't like palindromes, Fehc wants the longest palindromic substring to be as short as possible. The string should only contain the first A latin letters(e.g. let A=2, then this string only contains 'a' and 'b'). Please help Fehc and find such a string. If multiple solution exists, you can print any.
- The first line of input is an integer T, denoting the number of test cases.
- T tests follow. For each test, there is a line containing two space-separated integers N and A.
For each test, print a number L and a string s, separated by one space. L is equal to the length of longest palindromic substring of s, and s is the string that Fehc will give to Chef. You must minimize L, but in the case of multiple s's, any valid s is OK.
- (sum of N in all test cases)≤105
Subtask #1 (21 points):
Subtask #2 (79 points):
- original constraints.
Input: 4 5 2 12 26 8 26 7 2 Output: 3 aaabb 1 hapybirthday 1 codechef 3 aaababb
Example case 1. There are multiple solutions. For example, "abaaa" is also correct. Note that "abbaa" is not a correct solution, since "abba" is a palindromic substring of length 4, which is not optimal.
|Tags||bruteforce, medium, nov17, r_64|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, kotlin, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.5, RUBY, rust, SCALA, SCM chicken, SCM guile, SCM qobi, ST, swift, TCL, TEXT, WSPC|
Fetching successful submissions