StrIIRec
SRM 545 · 2011-11-22 · by subscriber
Problem Statement
Given are
- The number of inversions in R is at least minInv.
- The string R is not lexicographically smaller than minStr.
Notes
- A String A is lexicographically smaller than a String B if A is a prefix of B or A contains a smaller character at the first position where the Strings differ.
Constraints
- n will be between 1 and 20, inclusive.
- minInv will be between 0 and n*(n-1)/2, inclusive.
- minStr will contain between 1 and n characters, inclusive.
- Each character in minStr will be one of the first n lowercase Latin letters.
- All characters in minStr will be unique.
1 0 "a" Returns: "a"
2 0 "a" Returns: "ab"
2 0 "b" Returns: "ba"
2 1 "a" Returns: "ba"
2 1 "b" Returns: "ba"
2 1 "ab" Returns: "ba"
You must find the lexicographically smallest String that has at least 1 inversion and is not lexicographically smaller than "ab".
11 55 "debgikjfc" Returns: "kjihgfedcba"
"kjihgfedcba" is the only String that has at least 55 inversions.
Submissions are judged against all 206 archived test cases, of which 7 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class StrIIRec with a public method string recovstr(int n, int minInv, string minStr) · 206 test cases · 2 s / 256 MB per case