Woburn Challenge 2018-19 Round 4 - Junior Division
Problem 4: Your Name, Please
Billy is just about to begin playing the classic role-playing game EarthBound! His first order of business will be to enter a name for his character.
EarthBound's name entry system displays the uppercase letters "A
" through "Z
" in a row, with a cursor indicating the one currently selected (initially "A
"). It also displays the name which the player has entered so far (initially an empty string).
At any point in time, Billy may press a button to perform one of the following actions:
- "
<
": Move the cursor to the previous letter, wrapping around to the end if necessary (e.g. "Y
" → "X
", "A
" → "Z
") - "
>
": Move the cursor to the next letter, wrapping around to the start if necessary (e.g. "I
" → "J
", "Z
" → "A
") - "
A
": Append the currently-selected letter to the end of the current name (without moving the cursor) - "
+
": Submit the current name, thus completing the name entry process
Given any name, there are multiple possible sequences of button presses which would end up submitting it. However, as the king of video games, Billy will showcase his skills right off the bat by entering his name of choice using the minimum possible number of button presses.
What remains is choosing an appropriate name…
Billy has decided that his name will consist of exactly N (1 ≤ N ≤ 100) letters. To make things particularly interesting, he's also decided to choose a name such that the minimum number of button presses required to enter it is exactly K (1 ≤ K ≤ 10,000).
Help Billy come up with any name satisfying both of the above criteria, or determine that no such name exists!
Input Format
The first and only line of input consists of two space-separated integers, N and K.
Output Format
Output a single string, either a valid name consisting of N uppercase letters, or "Impossible
" if no such name exists.
Sample Input 1
2 6
Sample Output 1
CB
Sample Input 2
1 20
Sample Output 2
Impossible
Sample Explanation
In the first case, "CB
" meets both criteria: it consists of 2 letters, and requires a minimum of exactly 6 button presses to enter (">
", ">
", "A
", "<
", "A
", "+"
). Note that other outputs would also be accepted.
In the second case, there exists no single-letter name whose minimum number of required button presses is exactly 20.
All Submissions
Best Solutions
Point Value: 7 (partial)
Time Limit: 2.00s
Memory Limit: 16M
Added: Mar 22, 2019
Author: SourSpinach
Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
Comments (Search)