Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2017 /round3 /salientstrings.html
wjomlex's picture
2017 Problems
7acee6b verified
raw
history blame
2.67 kB
<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 &le; <strong>T</strong> &le; 2,000 <br />
1 &le; <strong>N</strong> &le; 1,000 <br />
1 &le; <strong>P<sub>i</sub></strong> &le; <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>