ENIGMA-0x02 (2024) - S4 / A0 (Now you think with portals) **
View as PDF
Submit solution
Points:
100 (partial)
Time limit:
1.0s
Memory limit:
64M
Authors:
Problem type
Allowed languages
Blockly, C, C++, Java, Pascal, Python
Now You Think with Portals
We are in a skyscraper and want to reach the -th floor.
We start from the -th floor and can use
methods to change floors:
- via ladders: each ladder moves us from the current floor to either the next floor up or the next floor down.
- via portals: each floor provides (up to)
portals.
Each portal can take us to a higher floor or a lower floor.
But which floors? We don't know! The portals are pre-defined, but unknown to us in advance.
The only thing we know is that:- if we use the
upportal from the-th floor, no subsequent portal will take us to the
-th floor or any floor below it, and
- if we use the
downportal, no subsequent portal will take us to the-th floor or any floor above it. Therefore, a floor might have fewer than
portals.
- if we use the
For example, if floor has a portal to floor
(
up portal), then floor cannot have a
down portal anywhere.
You need to find the best way to get from floor to floor
.
The ideal solution avoids using ladders altogether!
Input (STDIN) - Output (STDOUT)
This problem is interactive, meaning you give instructions to the judge, and it responds with information for you to proceed.
- The first line contains
integers
,
, and
: the number of floors, the starting floor, and the floor where the exit is.
You are initially on floor.
- As long as you are not on floor
:
- You print your move:
LADDER UP,LADDER DOWN,PORTAL UP,PORTAL DOWN, - The judge prints the floor number
you land on, in the form
OK x, and - If you requested a
PORTALmove on a floor that doesn't have the corresponding portal, the judge will printSAME.
- You print your move:
- Once you reach floor
, the game ends and the judge computes your score.
Your score for this game is:
Example
Input (STDIN)
10 3 7
One possible sequence of moves could be:
Program Output (STDOUT) |
Judge Output (STDIN) |
|---|---|
PORTAL DOWN | |
ΟΚ 1 |
|
LADDER UP | |
ΟΚ 2 |
|
LADDER UP | |
ΟΚ 3 |
|
PORTAL UP | |
ΟΚ 4 |
|
PORTAL UP | |
ΟΚ 8 |
|
LADDER DOWN | |
7 |
This solution would score .

Note:
To ensure the interactive grader works properly, you must flush the lines you print.
This is done as follows:
- In Python:
print()does this automaticallyprint("LADDER UP") - In C/C++ (
cstdio): useprintfas usualprintf("LADDER UP\n"); - In C++ (
iostream): useendlcout << "LADDER UP" << endl;
Comments