Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2018 /finals /contest.html
wjomlex's picture
2018 Problems
ab396f0 verified
raw
history blame
3.7 kB
<p>
The 2018 Hacker Cup finals are underway! The contest is being held in a room with 2 rows of <strong>N</strong> desks each, with finalists sitting at some of them.
</p>
<p>
One of the finalists, Alex, is sitting at the leftmost desk in the front row. Another finalist, Borys, is sitting at the rightmost desk in the front row.
Unfortunately, both of them find themselves distracted by the contest room's environment &mdash; Alex is a bit too hot on his side of the room, while Borys is a bit too cold.
If only they could switch places! Unfortunately, this would be against the rules, but if they work together with some other contestants, perhaps they can manage it without the
contest organizers noticing...
</p>
<p>
The initial state of each row of desks can be represented by a string of <strong>N</strong> characters, with the <em>i</em>th character corresponding to the <em>i</em>th desk from
the left in that row. Each character is one of the following:
</p>
<ul>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <code>A</code> - Alex's desk (guaranteed to appear exactly once, as the leftmost desk in the front row) </li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <code>B</code> - Borys's desk (guaranteed to appear exactly once, as the rightmost desk in the front row) </li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <code>*</code> - A cooperative finalist's desk </li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <code>#</code> - An uncooperative finalist's desk </li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <code>.</code> - An unoccupied desk </li>
</ul>
<p>
At any point, a single finalist may move from their current desk to an adjacent, currently-unoccupied desk.
Two desks are considered adjacent if either they're in the same column, or they're directly side-by-side in the same row.
However, the finalists won't be foolish enough to move sideways between two desks in the front row, as that would surely attract the contest organizers' attention.
</p>
<p>
Alex, Borys, and any cooperative finalists may all move between desks in this fashion.
On the other hand, uncooperative finalists are too busy actually competing, and will never move from their original desks.
</p>
<p>
Assuming that Alex, Borys, and the cooperative finalists all work together, is it possible for Alex and Borys to switch seats (in other words, for Alex to occupy the front row's rightmost desk while Borys simultaneously occupies its leftmost desk) without the contest organizers noticing?
</p>
<h3>Input</h3>
<p>
Input begins with an integer <strong>T</strong>, the number of parallel universes in which the 2018 Hacker Cup is occurring.
For each universe, there are two lines of <strong>N</strong> characters each, as described above. The first line is the front row of desks, and the second line is the back row of desks.
</p>
<h3>Output</h3>
<p>
For the <em>i</em>th universe, output a line containing "Case #<em>i</em>: " followed by the string "Possible" if Alex and Borys can successfully switch seats,
or "Impossible" otherwise.
</p>
<h3>Constraints</h3>
<p>
1 &le; <strong>T</strong> &le; 200 <br />
2 &le; <strong>N</strong> &le; 2,000 <br />
</p>
<h3>Explanation of Sample</h3>
<p>
In the first case, the contest room looks as follows (with grey lines indicating adjacent desks which finalists may potentially move between).
The blue circle denotes a cooperative finalist, and the gray square denotes an uncooperative finalist. A and B denote Alex and Borys respectively.
</p>
<p>
One possible sequence of moves resulting in Alex and Borys switching places is as follows (with some moves omitted):
</p>
<p>
In the second case, Alex and Borys are unable to get past one another and switch seats.
</p>