Kth Lex Min Min Min Subpalindromes
Time limit3sMemory limit1024 MB
Find the k-th lexicographically smallest length-n array over 1 to m that has the fewest palindromic subarrays, or print -1 if there are fewer than k such arrays.
- Level
Medium6 of 10
- Topics
- Greedy, Combinatorics, Math
- Solved
- No attempts yet
Problem
Consider all arrays of length whose elements are integers from to . Let be the minimum number of contiguous subarrays that are palindromic that such an array can have. An array is palindromic if it is equal to its own reverse.
From all arrays of length with integers from to , keep only those that have the minimum number of palindromic contiguous subarrays, and sort them lexicographically. Find the -th array in this order.
Input
The only line contains three integers , , and (, , ).
Output
If there are fewer than valid arrays, print -1. Otherwise, print the -th lexicographically smallest of them.
Hint
Did we put the minimum number of min in the title? Min.