AB String
InterviewTime limit2sMemory limit512 MB
Find the length-N A/B string whose number of (A before B) pairs equals K, choosing the lexicographically smallest such string.
- Level
Medium4 of 10
- Topics
- Greedy, Combinatorics, String
- Solved
- No attempts yet
Problem
You are given two integers and . Find a string that satisfies both conditions below.
- has length and uses only the letters 'A' and 'B'.
- Exactly pairs satisfy , character of is 'A', and character of is 'B'. Positions are counted from 0.
If more than one string satisfies both conditions, find the lexicographically smallest one. In lexicographic order 'A' comes before 'B'.
Input
The first line contains and , separated by a space. (, )
Output
Print the lexicographically smallest string that satisfies the conditions. If no such exists, print -1.