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 T-th floor.
We start from the S-th floor and can use 2 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) 2 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 up portal from the i-th floor, no subsequent portal will take us to the i-th floor or any floor below it, and
    • if we use the down portal, no subsequent portal will take us to the i-th floor or any floor above it. Therefore, a floor might have fewer than 2 portals.

For example, if floor 1 has a portal to floor 2 (up portal), then floor 2 cannot have a down portal anywhere.

You need to find the best way to get from floor S to floor T.

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.

  1. The first line contains 3 integers F, S, and T: the number of floors, the starting floor, and the floor where the exit is.
    You are initially on floor S.
  2. As long as you are not on floor T:
    • You print your move: LADDER UP, LADDER DOWN, PORTAL UP, PORTAL DOWN,
    • The judge prints the floor number x you land on, in the form OK x, and
    • If you requested a PORTAL move on a floor that doesn't have the corresponding portal, the judge will print SAME.
  3. Once you reach floor T, the game ends and the judge computes your score.

Your score for this game is:
100\% - \frac{\text{number of ladder moves}}{\text{total moves}}

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 {7 - 3 \over 7} = 57\%.

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 automatically
    print("LADDER UP")
    
  • In C/C++ (cstdio): use printf as usual
    printf("LADDER UP\n");
    
  • In C++ (iostream): use endl
    cout << "LADDER UP" << endl;
    

Comments

There are no comments at the moment.