File size: 2,670 Bytes
7acee6b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
<p>
Many people are avid fans of the daily crossword in the paper, but not you. I mean, the format is pretty terrible, right?
You only get to use English words, and any hack can look those up in a dictionary. Also, it takes forever to make just one puzzle.
What a waste of time.
</p>
<p>
You've written a letter to the editor describing a new word game. It's really easy to make new puzzles because the only thing you
give the solver is a permutation <strong>P<sub>1..N</sub></strong> of the first <strong>N</strong> positive integers.
It's then up to the solver to find any string that's <em>salient</em> for the given permutation.
</p>
<p>
A string is <em>salient</em> for the permutation <strong>P<sub>1..N</sub></strong> if it consists of <strong>N</strong> uppercase letters ("A"..."Z"),
such that when its <strong>N</strong> non-empty suffixes are sorted in lexicographical order, the suffix starting at the <em>i</em>th character is the
<strong>P<sub>i</sub></strong>th suffix in the sorted list. It's possible that a given permutation has no salient strings.
</p>
<p>
You need some example puzzles to include in your letter. You already have some permutations generated, so all you need is to supply an answer
for each permutation (if possible).
</p>
<h3>Input</h3>
<p>
Input begins with an integer <strong>T</strong>, the number of different permutations you've generated.
For each permutation, there is first a line containing the integer <strong>N</strong>.
Then <strong>N</strong> lines follow, the <em>i</em>th of which contains the integer <strong>P<sub>i</sub></strong>.
It is guaranteed that each integer from 1 to <strong>N</strong> shows up exactly once in <strong>P</strong>.
</p>
<h3>Output</h3>
<p>
For the <em>i</em>th permutation, print a line containing "Case #<strong>i</strong>: "
followed by any salient string for that permutation (note that any valid string consisting of <strong>N</strong> uppercase letters will be accepted), or "-1" if there are no such strings.
</p>
<h3>Constraints</h3>
<p>
1 ≤ <strong>T</strong> ≤ 2,000 <br />
1 ≤ <strong>N</strong> ≤ 1,000 <br />
1 ≤ <strong>P<sub>i</sub></strong> ≤ <strong>N</strong> <br />
</p>
<h3>Explanation of Sample</h3>
<p>
In the first case, if we sort the suffixes of FACEBOOK we get:
<ol>
<li> ACEBOOK </li>
<li> BOOK </li>
<li> CEBOOK </li>
<li> EBOOK </li>
<li> FACEBOOK </li>
<li> K </li>
<li> OK </li>
<li> OOK </li>
</ol>
If we read the indices of the suffixes back in order of decreasing length, we get 5 1 3 4 2 8 7 6, which is the given permutation. Therefore "FACEBOOK" is salient for this permutation, and is one possible accepted answer.
</p>
|