European Girls' Olympiad in Informatics: 2023 Day 2 Problem 4
In the old town of Lund, there is a street with
The game itself consists of two phases. In the first phase, Emma picks an order in which to visit the
houses, such that her house is the last one to visit. She then leads Anna to the houses one by one
in this order, without telling Anna the order in advance. For each house that is not Emma's house,
Anna is allowed to write a single integer between
In the second phase of the game, Bertil walks along the street from house
Can you devise a strategy where Anna and Bertil are guaranteed to win the game? Your strategy
will be scored based on the value of
Implementation
This is a multi-run problem, meaning that your program will be executed multiple times. The first time it is run, it will implement Anna's strategy. After that it will implement Bertil's.
The first line of the input will contain two integers,
The following input depends on the phase:
Phase 1
Your program should start by outputting the number
Phase 2
Your program should read a line with
Then, it should print a line with two integers,
Implementation Details
Note that when running your program in Phase 2, the program is restarted. This means that you cannot save the information in some variables between the runs.
After each line you print, make sure to flush standard output, or else your program might get
judged as Time Limit Exceeded. In Python, the print()
flushes automatically. In C++, cout << endl;
also flushes in addition to printing a newline; if using printf, use fflush(stdout)
.
The grader for this problem may be adaptive, meaning it may change its behavior depending on the output of your program to prevent heuristic solutions from passing. It might do a trial run of phase 1, look at your output, and then run phase 1 for real using information it extracted from the previous run.
Your program must be deterministic, that is behave the same if run twice on the same input. If
you want to use randomness in your program, make sure to use a fixed random seed. This can be
done by passing a hard-coded constant to srand
(in C++) or random.seed
(in Python), or, if using
C++11's random number generators, by specifying the seed when constructing the random
number generator. In particular, you can not use srand(time(NULL))
in C++. If the grader
detects that your program is not deterministic, it will be given a Wrong Answer verdict.
If the sum of the runtimes of the (up to 3) separate runs of your program exceeds the time limit, your submission will be judged as Time Limit Exceeded.
Scoring
Your solution will be tested on a number of test cases. If your solution fails on any of these test cases (e.g. by giving wrong answers (Wrong Answer), crashing (Run-Time Error), exceeding the time limit (Time Limit Exceeded), etc.), you will receive 0 points and the appropriate verdict.
If your program successfully finds the index of Emma's house in all test cases, you will get the
verdict Accepted, and a score calculated as follows. Let
Score | |
---|---|
The scoring function is depicted in the figure below.
On DMOJ, you will receive an additional
The sample test case is ignored for scoring, and your solution does not have to work for it.
Testing Tool
To facilitate the testing of your solution, we provide a simple tool that you can download. It can be downloaded at testing_tool.py. The tool is optional to use, and you are allowed to change it. Note that the official grader program is different from the testing tool.
Example usage (with
For Python programs, say solution.py
(normally run as pypy3 solution.py
):
python3 testing_tool.py pypy3 solution.py <<<"4 2"
For C++ programs, first compile it
(e.g. with g++ -g -O2 -std=gnu++17 -static solution.cpp -o solution.out
)
and then run:
python3 testing_tool.py ./solution.out <<<"4 2"
The testing tool will visit the houses in random order.
To use a specific order, modify the testing tool where it says MODIFY HERE
.
Example Interaction
The sample test case is ignored for scoring, and your solution does not have to work for it.
Suppose we have
In the first run of your code:
Finally, the grader sets
In the Phase 2 of your code, your solution is passed the list 1 2 3 2
.
It responds with 1 3
.
Since one of the guesses is the correct index of the house
Sample Interaction 1
1 4
>>> 3
2
>>> 3
0
>>> 1
3
>>> 2
Sample Interaction 2
2 4
1 2 3 2
>>> 1 3
In the sample interactions above, >>>
denotes your output. Do not print this out.
Comments
My solution used to work but now it doesn't.
There was a small bug in our version of the grader that allowed certain incorrect solutions to pass. This bug has since been fixed, and all submissions were rejudged accordingly.