Welcome to the first round of the Swiss Olympiad in Informatics! You will find below an overview of what you’ve done so far as well as a few things that you should know before getting started.
This contest is over.
Category | Task | Total | Subtask 1 | Subtask 2 | Subtask 3 | Subtask 4 | Subtask 5 |
---|---|---|---|---|---|---|---|
Junior only | harvest | ‒/100 | ‒/17 | ‒/18 | ‒/19 | ‒/21 | ‒/25 |
Junior only | exhibition | ‒/100 | ‒/7 | ‒/23 | ‒/31 | ‒/39 | |
Junior only | cruisetrip | ‒/100 | ‒/20 | ‒/25 | ‒/25 | ‒/30 | |
Both | calendar | ‒/100 | ‒/16 | ‒/12 | ‒/21 | ‒/18 | ‒/33 |
Both | labyrinth | ‒/100 | ‒/12 | ‒/11 | ‒/19 | ‒/26 | ‒/32 |
Both | pyramids | ‒/100 | ‒/14 | ‒/16 | ‒/30 | ‒/40 | |
Regular only | irrigation | ‒/100 | ‒/4 | ‒/13 | ‒/21 | ‒/24 | ‒/38 |
Regular only | caravan | ‒/100 | ‒/10 | ‒/10 | ‒/20 | ‒/35 | ‒/25 |
Regular only | 1h | ‒/100 | ‒/25 | ‒/25 | ‒/25 | ‒/25 |
In the town of Bloomsville, Mouse Binna runs a community garden where townsfolk can rent a plot to grow their own fruits and vegetables. Each year, Binna hosts a Harvest Day, where everyone brings the fruits and vegetables they’ve grown to share with the community.
This year, Mouse Binna wanted to ensure that every resident of Bloomsville received an equal share of the harvest, so she provided each person with a basket to fill. But right before the townsfolk came to collect their shares, Binna noticed that some baskets had lots of fruits and vegetables, while others had just a few.
Determined to spread the joy of the harvest equally, Mouse Binna decides to redistribute items from their baskets to balance out their hauls.
Mouse Binna’s challenge is to figure out the minimum number of items she has to move from one basket to another to ensure everyone went home with an equal amount of harvest.
In this subtask, Mouse Binna is not concerned about the number of items she has to swap and only asks you to find out whether it’s possible to swap the items in the baskets so that everyone has the same amount of items in their baskets or not.
The first line contains the number of test cases . The test cases follow in the following format:
For the -th test case, output a line “Case #i: YES” if it’s possible to swap the items in the baskets so that everyone has the same amount of items in their baskets, or “Case #i: NO” otherwise.
There are test cases. In each test case we have:
Input:
3 5 1 5 2 6 1 2 4 9 4 3 9 7 1
Output:
Case #0: YES Case #1: NO Case #2: YES
Comment:
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
In this and all following subtasks, Mouse Binna is interested in the minimum number of items she has to move from one basket to another to ensure everyone went home with an equal amount of harvest. Additionally, in this subtask, Binna heard that all farmers in Bloomsville had an exceptionally bad harvest this year and are only able to bring exactly one item. To make sure to spread some joy, she invited her friend from a neighboring town, in the hope that she has had a better harvest this year.
Same as subtask 1.
For the -th test case, output a line “Case #i: x” where is the minimum number of items Binna has to move.
In this and all following subtasks, it is guaranteed that Binna can distribute the items to the baskets equally (in particular that means for all the following cases the answer in Subtask 1 would be yes).
There are test cases. In each test case we have:
Input:
3 5 6 1 1 1 1 2 15 1 1 4
Output:
Case #0: 4 Case #1: 7 Case #2: 0
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Luckily, the times of the bad harvest are over and the fields have been flourishing again this year. Oddly enough, Mouse Binna notices that everyone arrives with a very similar amount of items. Maybe the rain this year was very evenly distributed over Bloomsville and thus everyone harvested almost the same amount of crops? When doing the math Binna notes that the minimum and the maximum number of items brought by the inhabitants of Bloomsville only differs by .
Same as subtask 2.
There are test cases. In each test case we have:
Input:
3 4 1 3 2 2 4 2 4 3 3 9 1 1 3 1 3 3 2 2 2
Output:
Case #0: 1 Case #1: 1 Case #2: 3
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
For the next festival, Mouse Binna notices a wide variety of brought crops both in type and in number. She deduces that there are no special conditions that hold this year and she has to find the minimum amount of items she has to move without any additional assumptions to ensure she does not do any extra work this year.
Same as subtask 3.
There are test cases. In each test case we have:
Input:
4 4 3 1 3 1 2 2 2 5 14 8 4 3 6 3 20 3 1
Output:
Case #0: 2 Case #1: 0 Case #2: 8 Case #3: 12
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
This year was a very good year for the farmers of Bloomsville and everyone brings enormous amount of fruits and vegetables (up to one billion each). Mouse Binna deduces that there are no special conditions that hold this year and she has to find the minimum amount of items she has to move without any additional assumptions to ensure she does not do any extra work this year.
Same as subtask 4.
There are test cases. In each test case we have:
Attention: The numbers in this subtask will get very large. If you use integers (e.g. in C++) then you should switch to a larger datatype (e.g. long long) instead to avoid overflows.
Input:
2 4 3 1 3 1 2 0 10000000000
Output:
Case #0: 2 Case #1: 5000000000
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
Mouse Stofl wants to make an exhibition of the most expensive paintings that exist, based on his reasoning that the most valuable paintings are also the most beautiful. However, that might be a bit boring, so he additionally has the constraint that, for any painter included in the exhibition, there are at least two paintings of this painter. That way, visitors will be better able to see the individual style of each painter.
Obviously, with all the most expensive paintings in one place, he needs an insurance. For calculating the insurance costs, he needs to know the total value of all the paintings in the exhibition. Since he isn’t yet sure how big the exhibition is going to be, he just wants to calculate it for every possible number of paintings, from 2 up to all the paintings.
This might be a nice idea, but who is actually going to borrow Stofl his most expensive paintings for the exhibition? For now, he just has access to the paintings that he has made himself.
The first line contains the number of test cases . test cases follow of the following format:
In this subtask, we always have .
For the -th test case print a line “Case #t:” followed by numbers, where the -th number () is the total value of all paintings of the most expensive exhibition with paintings, and where no painter has exactly one painting in the exhibition. It is guaranteed that such an exhibition exists for each .
Input:
3 1 2 2 4 3 1 3 3 8 5 7 1 4 4 3 3 3 3
Output:
Case #0: 7 Case #1: 15 20 Case #2: 6 9 12
Comment:
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Just one painter is clearly not enough. Stofl additionally asked Mouse Binna whether he could borrow her paintings, and luckily she agreed.
Same as in subtask 1.
In this subtask, we always have .
Input:
2 2 5 3 6 5 6 2 1 2 2 7 3 5 5 6 4 1 7 6 2
Output:
Case #0: 12 17 15 20 Case #1: 13 16 24 29 31 32
Comment:
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Mouse Stofl made a lot of phone calls to various galleries, and finally found the Bibliotheca Alexandrina, who was willing to lend some paintings from its collection to Stofl.
Same as in subtask 1.
Input:
2 3 9 3 8 2 4 2 7 3 4 9 1 3 5 4 15 3 2 1 4 4 5 5 3 4 3 9 5 4 5 6 8 2 3 1
Output:
Case #0: 14 17 26 29 36 39 41 42 Case #1: 14 18 28 32 38 42 46 49 52 55 58 60 61 62
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
The previous exhibition was a huge success. Afterwards, many art owners contacted Mouse Stofl and offered to lend their paintings for an even bigger exhibition.
Same as in subtask 1.
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
The Nile is a famous river in Egypt and one of the longest in the world. Mouse Stofl, who recently heard about the river, is planning to rent a cruise ship and travel on the Nile to appreciate the magnificent landscape. He wants to be the coolest mouse in his friend group by surprising them with all the photos he’s going to take during the trip. He wants to visit three different cities in Egypt to replenish his supplies and asks for your help to plan the route he’s going to take. On the map he gave you, the Nile is divided into a grid of rows and columns with islands positioned on some grid cells. Every minutes, the boat can move to an adjacent grid cell provided no island is occupying the cell. A cell is adjacent to another one if both cells share a common side, diagonals are not permitted.
Because he has high standards, Mouse Stofl wants the cruise to be as long as possible without travelling through the same grid cell twice and without travelling upstream because of his limited supplies. This means for each movement you can travel one cell left, one cell right or one cell down. Fortunately for you Stofl has already made sure there exists a trip which satisfies his constraints but he did not know how to make sure the trip was the longest one possible.
Mouse Stofl has the authorization to start his trip anywhere on the upper row of the grid if there is water there and must travel downstream to any of the cells on the bottom row of the grid.
All subtasks have the same input and output format.
The first line contains the number of test cases . The test cases follow in the following format:
A valid trip from the top row to the bottom one is guaranteed to exist.
For the -th test case, output a line “Case #t:”, followed by the number , the maximum possible length of a trip.
The first destination Stofl wants to reach is Sohag. The width of the Nile until Sohag is very narrow. On the map you have to prepare the trip, the Nile is separated into only two columns.
Input:
2 3 2 .. .# .# 5 2 #. #. .. .. .#
Output:
Case #0: 4 Case #1: 6
Comment:
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
After his first stop, the Nile is becoming wider and Mouse Stofl now has more freedom when travelling. The Nile is now represented with at most columns on the map.
Input:
2 3 5 ...#. .#.#. ...#. 5 6 ...#.. ..##.. ...#.. .#.... .#.#..
Output:
Case #0: 7 Case #1: 13
Comment:
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Mouse Stofl left Asyut and is now heading to Cairo on the largest part of the Nile. The map you have doesn’t have a width restriction. However his boat has a technical problem which causes the boat’s steering mechanism to malfunction. Because of that Mouse Stofl is unable to steer enough to make his boat travel in all directions. He can now either go down or to the right. That means for each grid cell the boat can either go to the cell directly to its right or the one directly downwards. Even with the problems he is facing Stofl does not want to cancel his trip so he wants you to create him a trip which never goes left.
Same as in the previous subtasks. Additionally, in this subtask it is guaranteed that there exists a valid trip from the top row to the bottom row which only requires Stofl to move down and to the right. You need to output the longest possible length of such a trip.
Input:
2 5 6 ...#.. ..##.. ...#.. .#..#. .#.#.. 7 8 .##.#.#. #..#..#. .#...... ...##.## ##.##..# ...#.#.# .#...#.#
Output:
Case #0: 7 Case #1: 8
Comment:
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Mouse Stofl managed to fix the problem with his boat’s steering and now only needs to finish his trip. He can again go in all three directions, left, right or down.
Same as Subtask .
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
Mouse Binna had to leave Mouseland for Egypt in order to plan the upcoming IMOI (the International Mouse Olympiad in Informatics). Unfortunately, Egypt is very warm and Binna finds it very hard to get work done. She now has one month to finalize the planning of IMOI which also lasts one month. As it is well known, every month of the mice-calendar contains exactly days. She still has event to plan before the competition starts. The -th event starts on day and ends on day . Luckily, Mouse Binna is very good at multitasking and can handle as many events as needed on the same day.
Additionally, Mouse Stofl reminded her that the SOI camp is scheduled to happen the same month as IMOI and should last exactly days. However, she can choose when in the month the camp will happen to ease the planning.
To keep her organisation schedule easy to follow, she decides to plan an entire day of events during a single day of preparation and does not work on any other day during this day. That is on the -th day of preparation she will do the necessary work to plan the -th day of IMOI, where .
As the weather is much warmer than Mouseland’s chill countrylands, her productivity decreases as time goes on. On the first day, she has a productivity score of and every day loses one productivity point up to her last preparation day where she has productivity score of .
As Mouse Binna is very dedicated she wants IMOI and the SOI camp to run as smoothly as possible, hence she wants to work on the days that have more events first. In fact, she estimates her work’s worth as the sum of each’s tasks accomplished times the productivity on that day. That is if she had tasks on a day with productivity , her score for that day is .
Because of all the work she has to do, she does not have time to choose when she will plan which tasks, so she charged you to choose the order that will maximise her productivity. And who knows, if you do it well, she might even invite you to the camp!
In this subtask , which means that Binna doesn’t have to do the camp planning, because Stofl already did it for her.
However, all IMOI events starts on the first day of the competition, i.e. for all .
The first line contains the number of test cases . The test cases follow in the following format:
For the -th test case, output a line "Case #i: " followed by single integer number — the maximum total productivity score Binna can get for all events.
There are test cases. In each test case we have:
Input:
3 4 3 0 0 3 0 1 0 0 3 3 0 0 1 0 2 0 2 3 2 0 0 2 0 2
Output:
Case #0: 14 Case #1: 9 Case #2: 6
Comment:
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Stofl still did the camp planning for Binna (), but now the IMOI events can start on any day, i.e. for all .
Same as subtask 1.
Same as subtask 1, except that for we have .
Input:
3 4 3 0 3 3 0 1 0 0 3 3 0 0 1 1 2 0 2 3 2 0 0 2 1 2
Output:
Case #0: 9 Case #1: 8 Case #2: 6
Comment:
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
In this subtask Mouse Binna is still getting help from Mouse Stofl with the Camp planning but a month in Mouseland can be very long and there are a lot of events to be planned for IMOI.
Same as subtask 2.
Same as subtask 2, but and .
Input:
3 4 3 0 3 3 0 1 0 0 3 3 0 0 1 1 2 0 2 3 2 0 0 2 1 2
Output:
Case #0: 9 Case #1: 8 Case #2: 6
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
In this and the next subtasks Mouse Binna has to do the camp planning as well. Note that in this subtask the length of a month is shorter and there are less events to plan than in Subtask 3.
Same as subtask 2.
Same as subtask 2, but .
Input:
3 4 3 2 3 3 0 1 0 0 3 3 3 0 1 1 2 0 2 3 2 1 0 2 1 2
Output:
Case #0: 14 Case #1: 11 Case #2: 8
Comment:
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
In this subtask the months in Mouseland can be very long again and there are a lot of events to plan for IMOI.
Same as subtask 4.
Same as subtask 4, but and .
Input:
4 8 2 1 3 6 4 6 2 0 2 1 0 1 5 9 3 2 2 4 4 4 4 3 3 3 3 3 4 3 4 0 4 3 4
Output:
Case #0: 47 Case #1: 1 Case #2: 0 Case #3: 56
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
The famous explorer Mouse Binna is undergoing an expedition in the ancient tomb of the Great Mouse Pharaoh Stofl. While wandering through the labyrinth of the Pharaoh, she unexpectedly steps on an unsuspicious stone activating one of the many grave traps. Fortunately, as a famous explorer would, she came prepared with a plan for deactivating such a trap. For this she needs to rearrange torches in the labyrinth in a specific way:
The labyrinth consists of chambers. There are corridors, each connecting two chambers. It is possible to walk from any chamber to any other chamber using one or more of the corridors. Furthermore, there are no cycles in the labyrinth.
Each of the chambers has either a torch or no torch in it. Mouse Binna has a map of the labyrinth showing in which chambers a torch should be and in which not, to deactivate the trap. Unfortunately, the current distributions of the torches might not be according to her map, so she needs to move some torches.
She can take a torch from one chamber and move it to another chamber which is directly connected via a corridor and where there is no torch already. (Two torches in one chamber destabilized the labyrinth endangering Binna’s life further). As carrying a torch through a corridor might also destabilize the labyrinth, she wants to minimize the amount of time a torch moves through a corridor. (As an experienced and modern explorer she does not care how long she walks, or if she needs to walk without a torch, as she has her trusty headlamp).
Can you help her find the minimal amount of times a torch moves through a corridor?
The first line contains the number of test cases . This is followed by test cases in the following format: The first line of the test case contains , the number of chambers in the labyrinth.
lines follow, each line has two characters , either “0” or “1”, separated by a space. The first character represents the number of torches that should be present in the chamber at the end. The second character represents the number of torches in the chamber at the beginning. The total number of torches that should be in the end is the same as the number of torches in the beginning.
Then more lines follow, describing the structure of the labyrinth. Each line with two integers , separated by a space, representing a corridor between the chamber and .
For the -th test case, output single line “Case #i:”, followed by a single integer, the minimal amount of time a torch moves through a corridor.
For every input, it is guaranteed that there is a sequence of torch moves that places a torch in each chamber according to the map.
You might hit recursion limit, memory limit, stack limit or similar, if you are using recursive functions in python. See this wiki article on possible solutions for these problems.
The Mukhtar Tomb is of a very special shape. There is a central chamber with the mummy of the Pharaoh, with index . Every other chamber is connected to the central chamber.
There are test cases. In every test case:
Input:
2 4 0 0 0 1 1 1 1 0 1 0 3 0 2 0 1 0 0
Output:
Case #0: 2 Case #1: 0
Comment:
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
In the dark tomb there exists only one torch in the whole labyrinth.
There are test cases. In every test case:
Input:
2 4 1 0 0 0 0 0 0 1 1 2 1 0 2 3 5 0 0 0 1 0 0 1 0 0 0 1 0 3 0 2 0 4 0
Output:
Case #0: 3 Case #1: 2
Comment:
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
All the chambers are ordered in a line. Can you make use of this to reorder the torches?
There are test cases. In every test case:
Input:
2 4 1 0 0 0 0 0 0 1 2 1 1 0 3 2 5 0 1 0 1 1 1 1 0 1 0 4 3 1 0 3 2 2 1
Output:
Case #0: 3 Case #1: 6
Comment:
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Tomb of Mouse Tutankhamun does not contain many chambers, as they died at a young age.
As Tutankhamun did not get a pyramid like other pharaohs, the layout of his tomb is modeled after a pyramid. This means that there are chambers ordered on a line, representing the left side of the ‘pyramid’. Starting from the first chamber of this ‘left line’, there is another line, with chambers. Starting from the second chamber of this ‘left line’, there is another line, with chambers. Continue like this until the last chamber of this ‘left line’ (here there is no further line, as it would contain chambers). In total there will be chambers in such a tomb.
Here are two pictures, visualizing the labyrinth of such tombs:
0 / \ 1 2 / \ \ 3 4 5 0 / \ 1 2 / \ \ 3 4 5 / \ \ \ 6 7 8 9 / \ \ \ \ 10 11 12 13 14
There are test cases. In every test case:
Input:
2 15 0 0 1 1 1 0 0 0 1 1 1 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 0 1 0 2 1 3 1 4 2 5 3 6 3 7 4 8 5 9 6 10 6 11 7 12 8 13 9 14 6 0 0 0 0 0 1 0 1 1 0 1 0 0 1 0 2 1 3 1 4 2 5
Output:
Case #0: 17 Case #1: 3
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Now that you have mastered all the previous tombs it is time for the challenge. The Tomb of Great Pharaoh Stofl is the largest tomb known to mousekind. In this tomb, there are no additional restrictions on the structure of the labyrinth. Recall that in any labyrinth it is possible to walk from any chamber to any other chamber using one or more of the corridors. Furthermore, there are no cycles in any labyrinth. Can you help Binna escape the Great Pharaoh Stofl’s trap?
There are test cases. In every test case:
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
Mouse Stofl is in charge of organizing the excursions for IMOI 2024 in Egypt. Of course, a trip to see the famous Pyramids cannot be missing from the program. When Stofl arrives in the desert, he is very disappointed to not actually see pyramids but what seems to be an arbitrary pile of stones with stones.
After taking a closer look, Stofl realizes that these stones can actually form a pyramid and is determined to reconstruct it. The pieces are of different sizes (denoted by ) and Stofl notices that there is exactly one stone of every size (in particular that means that there are exactly stones).
Next to the pile of stones there are stable patches where Stofl can place the stones. When Stofl tries to place a stone anywhere else in the desert it starts to sink into the sand. The spot below the pile of stone is also stable (so there is a total of stable patches).
In his class “Pyramid building 1x1” Stofl learned that pyramids need to be built with the largest stone at the bottom and then adding the other stones in decreasing size (that is, the stone with size goes on the bottom, the stone with size on top of it, then the stone with size and so on). The stones are all very heavy and Stofl can only carry one at a time. For every pile of stones, he can pick up the top stone and place it on any other pile or any empty stable patch.
Stofl asks you for help on how to build the pyramid in the place where the pile of stones is currently located.
In this subtask you do not have to plan how to move the stones but only execute Stofl’s instructions. Stofl has already started building the pyramid before you arrived, so in this subtask the stones are arbitrarily distributed as piles on the stable patches.
The first number contains the number of test cases . The test cases follow in the following format:
The first line of each test case contains three numbers which represent the number of stones, the number of stable patches (including the ones the stones are currently lying on) and the number of instructions Stofl gives you.
The next lines will describe the piles of stone. Each of these lines starts with a number with , the number of stones on this pile, followed by numbers where indicating the size of the -th stone on this pile from the bottom to the top (that is, is the size of the bottom most stone and is the size of the stone on top of the pile).
The next lines will each contain two numbers, and with , that represent that we moved the top element from stack to stack . It is guaranteed that this is a legal move (this is, that stack is not empty).
It is guaranteed that every stone size from to appears exactly once.
For the -th test case, on the first line print “Case #t:”. This should be followed by lines, where the -th line first contains a number indicating the number of stones on the -th pile after you executed all of Stofl instruction, followed by numbers separated by spaces, describing the size of the stones on the -th pile starting with the lowest stone.
There are test cases. In each testcase we have:
Input:
2 3 2 3 1 2 2 0 1 0 1 1 0 1 0 5 3 5 3 0 3 1 0 2 4 2 0 1 0 2 1 0 2 1 2 1
Output:
Case #0: 2 2 1 1 0 Case #1: 2 0 1 2 3 2 1 4
Comment:
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
The Pyramid of Ahmose is a small pyramid located near Abydos. Mouse Stofl decided this is the perfect location to train you how to build a pyramid.
From now on, all the stones will be on pile initially and you have to decide how to move the stones to end up with a pyramid at the end.
The first number contains the number of test cases . The test cases follow in the following format:
The first line of each test case contains two numbers which represent the number of stones and the number of stable patches (including the one the stones are currently lying on). The next line describes the order of stones on the first pile. There are numbers, separated by spaces, where indicating the size of the -th stone on the first pile from the bottom to the top (that is, is the size of the bottom most stone and is the size of the stone on top of the pile).
It is guaranteed that every stone size from to appears exactly once, in particular, the stones on pile form a permutation of the numbers from to .
For the -th test case, on the first line print “Case #t: M” where is the number of moves you make to build the pyramid on pile . This should be followed by lines, each containing two numbers and such that indicating you move the top stone from pile to pile .
The moves you output must result in a pyramid on pile for your program to get points on this subtask.
There are test cases. In each testcase we have:
Input:
2 3 3 1 0 2 5 3 4 1 3 2 0
Output:
Case #0: 6 0 1 0 2 0 2 1 0 2 0 2 0 Case #1: 9 0 1 0 1 0 2 0 1 2 0 1 2 1 0 2 0 1 0
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
As you have proven in the last subtask that you do indeed know how to build a pyramid, Stofl leads to the site of the Pyramid of Menkaure, this is a large pyramid close to the city of Giza.
As Stofl wants the reconstructed pyramid to be ready for the start of IMOI 2024, he asks you to try to keep the number of moves you make as low as possible. In particular, to get full points on this subtask you should not use more than moves.
Same as Subtask 2
Same as Subtask 2
There are test cases. In each testcase we have:
If you need or less moves you get 30 points. If you use more than moves, the number of points you get will be
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
As the final project, Stofl leads you to the pyramid complex of Dashur. As this is a huge pyramid complex, you have more stable patches available than before. That should make it easier right? But Stofl is getting more impatient as IMOI 2024 is approaching soon, so to get full points on this subtask, you should not use more than moves.
Same as Subtask 2
Same as Subtask 2
There are test cases. In each testcase we have:
If you need or less moves you get 40 points. If you use more than moves, the number of points you get will be
Input:
2 5 5 3 2 1 0 4 6 5 4 2 5 3 0 1
Output:
Case #0: 10 0 1 0 2 0 2 0 3 0 3 1 0 3 0 3 0 2 0 2 0 Case #1: 12 0 1 0 2 0 3 0 4 0 1 0 3 4 0 3 0 3 0 1 0 1 0 2 0
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
Irrigation canals are a key innovation that allowed the Egyptian agriculture to flourish since the ancient times. In this problem, we will represent the set of irrigation canals in Egypt as an undirected graph, with nodes of the graph corresponding to the junctions and edges of the graph corresponding to the actual canals.
To avoid difficulties with controlling the water flow, there must be no cycles in this graph. In other words, this graph is a forest. Note that it is not necessarily a tree, or in other words it is not necessarily connected. Some junctions might even have no canals connected to them, in other words the graph may have isolated vertices.
Some nodes in this graph correspond to the water sources (typically a junction with a river, or a spring). You need to redesign the existing canal system to maximize the number of junctions that are connected to at least one water source through the canals. In other words, you need to maximize the total size of the connected components containing at least one water source node.
The canal construction is hard work, so you need to do the redesign one improvement at a time. In one improvement, you can choose one junction as the pivot junction, destroy one of the canals connected to the pivot junction, and build a new canal connecting the pivot junction to any other junction. Since we destroy one canal and build one canal, the total number of canals stays the same. You may not introduce cycles when building the new canals, in other words the graph must still be a forest after each improvement. In particular, you may not have more than one canal between the same pair of junctions, or connect a junction to itself. You may not choose a junction with no connected canals as the pivot junction, since there would be no canal to destroy.
You can do multiple improvements, but to avoid concentrating too much construction work in one place, each junction may be touched by improvements at most once. Note that each improvement touches three junctions: the pivot junction, the one it is being disconnected from, and the one it is being connected to.
Your goal is to find such a sequence of improvements that touches each junction at most once, and after all improvements are made the number of junctions that are connected to at least one water source is as high as possible. Note that the number of improvements that you do does not matter, only the end result.
All subtasks have the same input and output format.
The first line contains the number of test cases . test cases follow of the following format:
For the -th test case, output a line containing “Case #t:”, followed by two integers and : the number of junctions that you have managed to connect to at least one water source through the canals (directly or indirectly), and the number of improvements that you have made to do so. In the -th of the following lines, print three integers , , and : the number of the pivot junction, the number of the junction that the canal being destroyed connects the pivot junction to, and the number of the junction that the canal being built connects the pivot junction to.
In case there are multiple solutions that lead to the maximum amount of junctions connected to at least one water source, you may output any such solution.
In this subtask there are at most three junctions and exactly one water source.
Input:
1 3 1 1 0 2 1
Output:
Case #0: 2 1 0 2 1
Comment:
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
In this subtask there are at most seven junctions and exactly one water source.
Input:
2 3 1 1 0 2 1 6 3 1 1 2 3 4 4 5 0
Output:
Case #0: 2 1 0 2 1 Case #1: 4 2 2 1 5 4 3 0
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
In this subtask there are at most junctions and exactly one water source.
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
In this subtask there are at most junctions and the water sources are not connected to each other, directly or indirectly.
Input:
3 3 1 1 0 2 1 6 3 1 1 2 3 4 4 5 0 6 3 2 0 1 2 3 4 5 0 5
Output:
Case #0: 2 1 0 2 1 Case #1: 4 2 2 1 5 4 3 0 Case #2: 5 1 2 3 1
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
In this subtask there are at most junctions.
Input:
4 3 1 1 0 2 1 6 3 1 1 2 3 4 4 5 0 6 3 2 0 1 2 3 4 5 0 5 8 4 2 0 1 2 3 4 5 6 7 0 1
Output:
Case #0: 2 1 0 2 1 Case #1: 4 2 2 1 5 4 3 0 Case #2: 5 1 2 3 1 Case #3: 5 2 0 1 2 4 5 3
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
Caravans played an important role in long-distance desert travel and trade in ancient Egypt. Not on camels though! The camel, originating from North America, has not been domesticated until the 3rd millennium BC. Instead, ancient trade has been served on donkey caravans.
Mouse Binna, the vizier of pharaoh Binothris (ca. 2850 BC to 2760 BC), has been tasked to establish new trade routes for her pharao’s empire.
Trade is centered around an oasis that houses some donkeys and the task is to give instructions to those donkeys. There is a route from trade post A to trade post B with an oasis O in the middle. The distance between A and O is , the distance between O and B is .
Wares have to be transported between trade post A ( kilometers left of oasis O) and trade post B ( kilometers right of oasis O), and in subtasks 3-5 also back from B to A.
A a O b B |<==========>|<============>| | | | Trade Oasis Trade post A (donkeys) post B
The transportation needs to happen within one day and that is what the donkeys are for. The donkeys () are initially stationed at the oasis. The -th donkey can travel at most kilometers in one day. You are given the in the input.
You can control the donkeys individually by letting them move left (towards A) or right (towards B) by any possibly non-integer amount, and you may switch directions arbitrarily. Note that after donkey travelled his kilometers, it will not be able to move until the end of the day.
In this subtask , therefore the oasis and the second trade post are at the same position.
Is it possible to bring wares from A to O with the available donkeys?
A a O |<==========>| | | Trade Oasis & post A Trade post B
The first line contains the number of test cases . test cases follow in the following format:
For the -th test case, output a line “Case #i: YES” if it’s possible to send the donkeys from to or “Case #i: NO” if not.
There are test cases. In each test case we have:
Input:
3 1 3 0 5 1 3 0 6 3 4 0 4 5 4
Output:
Case #0: NO Case #1: YES Case #2: YES
Comment:
A O W-----------+----------- v<= <= <= <=| donkey 1 |=>v | d_1=5 |--W--------|----------- | v<= <= <=| donkey 2 | =>v | d_2=4 |-----W-----|----------- | v<= <=| donkey 2 | => =>v d_0=4 +-----------W-----------
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
This time trading post B might be at a different location than the oasis. Can we to transport the wares from A to B?
A a O b B |<==========>|<============>| | | | Trade Oasis Trade post A (donkeys) post B
Same as subtask 1.
Same as subtask 1, except that for we have .
Input:
4 5 5 9 6 5 4 4 9 5 5 9 6 5 4 3 9 2 3 3 9 1 2 7 3 5 13
Output:
Case #0: YES Case #1: NO Case #2: YES Case #3: YES
Comment:
Case #0:
5 4 3 2 1 0 ... 9 +--------------| d0=6 +--> | +-----------| d1=5 +--> | +--------| d3=4 +--> | +-----| d2=4 +---->| |--...-> d4=9
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
In this and the next subtasks Mouse Binna has to bring the wares from A to B and back.
Additionally, and are not always given, instead you have to find the maximal values for which it is possible to plan a successul trade route.
In this subtask in particular we have so we are dealing with the following situation:
O b B |==============>| first go A->B, |<==============| then B->A. | | Oasis & Trade Trade post A post B
For the -th test case, output a line “Case #i: b”, where is the largest possible distance such that it there exists a trade route from A to B and back.
Your answer is accepted if the absolute error is below . In other words, if your output is and the correct solution is , your output is correct if and only if .
There are test cases. In each test case we have:
Input:
3 1 5 2 3 3 16 7 6 6 5 1 4 3 1 1 1 1 1 1 1 1 4
Output:
Case #0: 2.5 Case #1: 2.25 Case #2: 6.2812347
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Same as subtask 3, but in this subtask we have so we are dealing with the following situation:
A a O |==============>| first go A->B, |<==============| then B->A. | | Trade Oasis & post A Trade post B
Same as subtask 3.
For the -th test case, output a line “Case #i: a”, where is the largest possible distance such that it there exists a trade route from A to B and back.
Your answer is accepted if the absolute error is below .
Same as subtask 3.
Input:
7 3 9 11 5 5 8 6 3 1 1 4 8 6 3 2 7 3 1 5 2 2 2 2 3 4 3 3 4 4 3 3 3 5 4 3 3 3 3
Output:
Case #0: 7 Case #1: 5.02222222 Case #2: 5.05882353 Case #3: 3.14141414 Case #4: 2.77777778 Case #5: 3 Case #6: 3.09803922
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
This time we are dealing with the general case:
A a O b B |============|=============>| first go A->B, |<===========|==============| then B->A. | | | Trade Oasis Trade post A (donkeys) post B
Distance is fixed and given in the input. Help Binna to find the maximum distance such that trade is possible.
For the -th test case, output a line “Case #i: a” where is the largest possible distance such that it there exists a trade route from A to B and back. If it is not possible to make a trade route, print -1 instead.
Your answer is accepted if the absolute error is below .
Input:
4 3 3 9 11 5 5 1 5 3 3 5 5 4 1 8 6 3 2 5 5 5 3 3 5 5
Output:
Case #0: 5.8 Case #1: 4.21568627 Case #2: 4.88888889 Case #3: -1
The contest is over, you can no longer submit. But you can still solve the task (‘upsolve’ it), and check your solution here.
If the time expires, or you don’t get full points, you can try again by downloading a fresh input.
You can directly run C++ solutions in your browser. For other languages, you need to download the input and manually run your solution. Please note that running in the browser is slower than running natively.
Do not navigate away while your solution is running.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
The homework part of round1 (1H) consists of 4 tasks, each of which is worth 25 points. You can gain a maximum of 100 points counting towards your score of the regular round.
1H GraderThis helps you get familiar with our grading system which we will use in all our events after round1, including workshops, camp, round2 and the finals.
You can submit in C++ (recommended), Java or Python.
C++: | If you don’t have a setup already, we recommend installing VSCode. |
---|---|
Java: | Read Java on the SOI Grader. |
Python: | Read Python on the SOI Grader. |
For 1H you can discuss solutions with friends or publicly on Discord, as long as you don’t share source code. We are also happy to help you! If you need help with the grading system or have questions regarding the theory or tasks, don’t hesitate to ask here or in Discord.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
Rank | Username | Total (600) | harvest (100) | exhibition (100) | cruisetrip (100) | calendar (100) | labyrinth (100) | pyramids (100) |
---|---|---|---|---|---|---|---|---|
loading ... |
Rank | Username | Total (600) | calendar (100) | labyrinth (100) | pyramids (100) | irrigation (100) | caravan (100) | 1h (100) |
---|---|---|---|---|---|---|---|---|
loading ... |