Welcome to the Second 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.
Contest ends at 2026-11-30T23:59:59+01:00
| Category | Task | Total | Subtask 1 | Subtask 2 | Subtask 3 | Subtask 4 | Subtask 5 | Subtask 6 |
|---|---|---|---|---|---|---|---|---|
| Junior only | tablegroups | ‒/100 | ‒/15 | ‒/16 | ‒/19 | ‒/20 | ‒/30 | |
| Junior only | microwaving | ‒/100 | ‒/15 | ‒/17 | ‒/19 | ‒/20 | ‒/29 | |
| Both | standemehr | ‒/100 | ‒/9 | ‒/14 | ‒/16 | ‒/23 | ‒/17 | ‒/21 |
| Both | alpineechoes | ‒/100 | ‒/8 | ‒/11 | ‒/22 | ‒/16 | ‒/18 | ‒/25 |
| Both | fajitas | ‒/100 | ‒/18 | ‒/13 | ‒/25 | ‒/12 | ‒/32 | |
| Both | magicforest | ‒/100 | ‒/7 | ‒/8 | ‒/15 | ‒/40 | ‒/30 | |
| Regular only | explorer | ‒/100 | ‒/10 | ‒/14 | ‒/15 | ‒/20 | ‒/24 | ‒/17 |
| Regular only | rohrpost | ‒/100 | ‒/6 | ‒/13 | ‒/26 | ‒/16 | ‒/18 | ‒/21 |
| Both | graderpractice | ‒/100 | ‒/25 | ‒/25 | ‒/25 | ‒/25 |
You may use any programming language to solve the tasks of the Second Round. To solve a practical task, you have to design a program, download an input file, run the program on the data in that file, write the results in another file and upload it along with the source code to the website, which will grade your submission and display the number of points that you’ve earned as well as an explanation if you did not get all the possible points. In order to read the data in the input file, make sure that your program either reads directly in that file or redirect the standard input to it (in a terminal running on Linux, Windows or macOS, you can do that by using the command ‘yourprogram < inputfile’, replacing ‘yourprogram’ and ‘inputfile’ by the paths to the actual program and input file). More elaborate explanations about how to solve the tasks of the Second Round await you on our wiki and our training page. Note that in case you get stuck on the tasks, you can move to next task and try again later: no need to solve them in order.
You should also hear about our workshops! In October and November, we offer workshops about algorithmics. It’s a great opportunity to learn all you need for the Second Round and to meet other like-minded participants. Whether you’re a beginner or an experienced programmer, it’s worth it to come. More info and registration here.
Don’t hesitate to contact us at info@soi.ch if you have any question about programming or the tasks.
To participate, you need to either have qualified in the first round or scored 600 points in the pre-round. It may take up to five minutes after adding an additional email address in your profile or submitting something in the pre-round for your qualification status to be updated.
The Second Round has two categories: Junior and Regular. You can participate in the Junior category if you are eligible to participate in this year’s edition of SOI as well as the two next ones. If you are eligible as a junior, you can choose to participate in the Junior or in the Regular category or in both.
You qualify for the finals and the Sarnen Camp if you are placed under the
Additionally, we may distribute wildcards.
We wish you good luck, hope you will enjoy solving our tasks and look forward to meeting you at our workshops.
Mouse Stofl loves eating fancy food. Fancy food, however, is too expensive for Stofl, so he came up with an idea: He will work at a fancy German restaurant as a waiter! That way he will have access to free fancy food from the kitchen.
Being a waiter is not an easy job. One of his tasks is collecting orders from customers. In Germany, it is customary that, for a group of mice, instead of every mouse placing an order individually, the group as a whole places one order. It is also a well-known fact that two different groups of German mice always have at least one empty chair between them, so all adjacent mice belong to the same group. In other words, a group is a maximal set of mice sitting on consecutive chairs. If no mouse is sitting at the table, there are groups.
To collect the orders, Stofl takes one piece of paper per order from the kitchen to write it down. Since Germany is renowned for its high efficiency, Stofl would like to only take exactly the amount of paper he needs so as not to appear inefficient. But since he is still new to German culture, he has difficulties determining which mouse belongs to which group, and he therefore asked you to help him find out how many pieces of paper he needs.
The restaurant Stofl is working at only has a very small table. Help Stofl determine the number of groups sitting at the table.
The first line contains the number of test cases . For each test case you get two lines:
For the -th test case, output a single line containing “Case #t: x”, where is the number of groups sitting at the table.
There are test cases. In each test case we have:
Input:
2 3 101 3 111
Output:
Case #0: 2 Case #1: 1
To submit for this subtask, please log in.
Stofl wasn’t happy with the food at his old restaurant, so he changed to a different restaurant with a bigger table.
Same as Subtask 1.
Same as Subtask 1.
There are test cases. In each test case we have:
Input:
2 5 10011 5 11111
Output:
Case #0: 2 Case #1: 1
To submit for this subtask, please log in.
The restaurant Stofl is working at wants to become even more fancy! They once heard that circular tables are super fancy, so they replaced the old table with a circular one.
Same as Subtask 1. Additionally, chairs and are now also considered adjacent.
Same as Subtask 1.
There are test cases. In each test case we have:
Input:
2 5 10011 5 11111
Output:
Case #0: 1 Case #1: 1
Comment:
To submit for this subtask, please log in.
The restaurant has become very popular, and some mice may be leaving or arriving at the restaurant one after another. Every time a mouse arrives or leaves, Stofl wants you to find how many groups there are now. The table is circular.
The first line contains the number of test cases . For each test case:
For the -th test case, output lines:
There are test cases. In each test case we have:
Input:
2 5 01011 2 1 0 5 01111 3 4 1 0
Output:
Case #0: 2 1 1 Case #1: 1 1 1 2
Comment:
To submit for this subtask, please log in.
The restaurant has become so famous that a lot of mice are joining and leaving. A huge circular table has been bought accordingly.
Same as Subtask 4.
Same as Subtask 4.
There are test cases. In each test case we have:
Input:
2 5 01011 2 1 0 5 01111 3 4 1 0
Output:
Case #0: 2 1 1 Case #1: 1 1 1 2
To submit for this subtask, please log in.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
Mouse Stofl is a student at the Mouse-Binna-Institute (MBI) for Analog Cheese Sciences in Potsdam. Mouse Stofl is really fond of the MBI, partly because of the great hands-on courses, partly because there is an abundance of microwaves to warm up his lunch in. Unfortunately, one day, Cat Tigro decided to make the students’ lives as hard as possible by disabling all but one microwave. Now there is a long line in front of the only remaining microwave!
The mice in that line have each prepared a meal, and now they are all queuing in front of the single microwave, which can warm only one meal at a time. The meal prepared by the -th mouse is considered warm once its heat level is at least . Every meal starts at room temperature, which is heat level . While it is inside the microwave, its heat level rises by per second; once it has been taken out, it drops by per second. A meal never gets colder than room temperature: one that has cooled all the way back down to heat level simply stays there until it is put into the microwave again.
A meal that is taken out early therefore keeps cooling while the later meals are still being warmed. The group wants to start eating at the same time, i.e. only once the very last meal has finished warming, and at that moment every meal must still be warm.
The mice are happy to let Stofl decide for them: you may choose the order in which they use the microwave. A meal may be warmed for any real number of seconds: a warming time does not have to be a whole number of seconds. The same mouse may also use the microwave more than once: a meal may be taken out and put back in later, cooling down in between. How many seconds are needed until the whole group can start eating together?
Mouse Stofl and his friends just finished the class “Cheese Optimizations” early, and have rushed to the microwave before any other classes have finished. Thus, the friend group, consisting of at most seven mice, is the only group standing in line. Having planned ahead, they stick to the plan they agreed on: they queue up in the order in which the meals are listed in the input, and each of them warms their meal exactly once, for exactly as long as they said they would. As soon as the last meal is out of the microwave the group starts eating, and only then do they find out whether the plan leaves everyone’s lunch warm enough to eat. As it is Monday, everyone has brought the same analog cheese fondue, so every meal warms up at the same rate and cools down at the same rate. Since every mouse is different, how warm they like their fondue still differs.
The first line contains the number of test cases . Each test case consists of five lines:
For the -th test case, output a single line “Case #t:” followed by “yes” if every meal is still warm enough for its mouse at the moment the group starts eating, i.e. if its heat level is at least , and “no” if at least one meal is not.
There are test cases. In each test case:
Input:
2 3 900 200 100 100 100 100 10 10 10 9.5 0.5 8 3 900 200 100 100 100 100 10 10 10 9.6 2.5 1.5
Output:
Case #0: no Case #1: yes
Comment:
To submit for this subtask, please log in.
The next day, Mouse Stofl’s class did not finish early. When he arrived at the microwave, there were already a lot of mice queuing. Unfortunately, he does not know them, and since he is shy, he does not want to ask them to reorder. Thus, Mouse Stofl is content with knowing how long it takes until everyone can start eating.
The order in which the mice use the microwave is exactly the order in which they are listed in the input, and each mouse warms their meal exactly once, in one uninterrupted turn. Compute the time this fixed queue needs.
The first line contains the number of test cases . Each test case consists of four lines:
The order in which the meals are listed is the order in which they use the microwave. You may choose the warming times freely.
For the -th test case, output a single line “Case #t: X”, where is the number of seconds the group needs when the meals are warmed in the listed order (each meal is warmed just long enough to still be warm at the very end). may be a real number; print it with enough digits (about 6 decimal places are always enough). An answer is accepted if its relative error is at most (or its absolute error is at most when the answer is below ).
There are test cases. In each test case:
Input:
1 3 100 900 200 100 100 100 10 10 10
Output:
Case #0: 13.32
Comment:
To submit for this subtask, please log in.
Wednesday is warm brie Wednesday! Therefore, everyone brought brie for lunch. Brie has the property that regardless of how you prepare it, it will always warm up and cool down at the same rate. Since every mouse is different, how warm they like their brie differs. Meanwhile, Mouse Stofl’s friends have done some advertising for their new optimization technique, and thus all mice in the queue agreed to let Mouse Stofl reorder the queue to improve its efficiency.
Same as Subtask 2, except that the order in which the meals are listed is arbitrary: you may choose the order in which the mice use the microwave, and a mouse may also take more than one turn, taking their meal out and putting it back in later.
Same as Subtask 2, except that is the minimum number of seconds needed over all possibilities, instead of the time needed for the arrangement in which they are listed.
There are test cases. In each test case:
Input:
1 3 900 200 100 100 100 100 10 10 10
Output:
Case #0: 12.41
Comment:
To submit for this subtask, please log in.
Thursday is triple-Gouda Thursday! Everyone brought a Gouda dish. Gouda dishes have the property that they all cool down at the same rate, but depending on what the Gouda cheese is paired with, it warms up at a different rate. Since every mouse is different, how warm they like their Gouda differs.
Same as Subtask 3.
Same as Subtask 3.
There are test cases. In each test case:
Input:
1 3 900 200 100 100 1000 200 10 10 10
Output:
Case #0: 9.7755
Comment:
To submit for this subtask, please log in.
Friday is fusion Friday! Everyone has brought along the leftovers of the week: some of Monday’s fondue, a piece of Wednesday’s brie, what was left of Thursday’s Gouda, and whatever else was still in the fridge. With every lunch a different mixture, there is no pattern left in how a meal warms up or cools down: every meal may have its own , and .
Same as Subtask 3.
Same as Subtask 3.
There are test cases. In each test case:
Input:
1 3 900 200 100 100 1000 200 2 5 10
Output:
Case #0: 9.71655
Comment:
To submit for this subtask, please log in.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
Mouseland is a wonderful country organised in a hierarchy: the country consists of cantons, each canton of districts, each district of smaller districts, and so on. At the bottom of the hierarchy are the mice. There are administrative units (such as the country, a canton, or a district), and mice.
You have launched a tax-free cheese initiative and want to get it accepted. Each mouse plans to vote either Yes or No.
An administrative unit approves the initiative if a strict majority of its sub-units accept it. This is called the Ständemehr. This means, for your initiative to pass in Mouseland, a strict majority of cantons must approve it. For a canton to approve it, a strict majority of its districts must approve it, and so on down the hierarchy.
Unfortunately, your initiative is unlikely to pass, so you want to influence the vote. You can persuade any mouse to change their vote by offering it a certain amount of cheese.
What is the minimum total cost (in cheese) needed to make the initiative pass?
In this subtask, there is one canton and up to voters. All voters belong directly to this canton. Each voter has a persuasion cost of 1.
For the -th test case, output a line “Case #t: X”, where is the minimum total cost needed to make the initiative pass. Test cases are numbered from to .
Input:
3 6 1 0 0 1 0 0 2 0 0 8 0 0 0 1 1 1 1 1
Output:
Case #0: 2 Case #1: 2 Case #2: 0
Comment:
To submit for this subtask, please log in.
We now have 26 cantons and up to voters. All voters vote directly in their respective cantons.
You want to compute the result of a provisional survey on the initiative to determine whether you need to stock up on cheese.
Note: Each canton has at least one mouse.
For the -th test case, output a line “Case #t: X”, where is if the initiative passes and otherwise. Test cases are numbered from to .
Input:
1 30 0 0 0 1 1 2 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 0 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
Output:
Case #0: 0
Comment:
To submit for this subtask, please log in.
We now have three administrative levels: the country, cantons, and districts, and up to mice.
Each mouse changes its mind when given a certain amount of cheese. The persuasion cost depends on the mouse.
Note: Each district has at least one mouse under it.
For the -th test case, output a line “Case #t: X”, where is the minimum total cost needed to make the initiative pass. Test cases are numbered from to .
Input:
1 6 2 5 1 0 0 1 1 0 1 0 2 3 4 1 1 0 0 1 1 1 1 3 1 2 1
Output:
Case #0: 1
Comment:
To submit for this subtask, please log in.
We now have numerous hierarchical levels. To describe these levels, you are given a list , where is the parent administrative unit of administrative unit . The top-level administrative unit is the country, which has as its parent.
For example, the list of parents -1 0 0 2 1 1 2 2 represents the same hierarchy as in Subtask 3. We have one country () with two cantons () and five districts (). Districts belong to canton , while districts belong to canton .
Please note that the list of parents 7 7 1 0 0 1 1 -1 is also a valid representation of the same hierarchy, since the administrative units may be listed in any order.
A pivotal mouse is a mouse whose change of vote alone would change the outcome of the initiative. The initiative currently fails and needs one pivotal mouse to vote Yes in order to pass. You must find all possible pivotal mice; it is guaranteed that there is at least one.
Print all possible pivotal mice, that is, all mice whose vote change would make the initiative pass.
Notes:
For the -th test case, output a line “Case #t:” followed on the same line by the indexes of all possible pivotal mice in increasing order, i.e. the mice whose vote change would make the initiative pass. Test cases are numbered from to .
Note: the hierarchy can be very deep (up to levels). If your solution uses recursion, you need to increase the stack size or the recursion limit:
Input:
1 9 5 -1 0 0 0 0 1 1 1 2 2 3 3 4 4 1 1 1 1 0 1 0 1 1
Output:
Case #0: 4 6
Comment:
We have five administrative entities: the country and four cantons. There are nine mice.
Cantons 1 and 4 accept the initiative, while cantons 2 and 3 reject it by one vote each. Three cantons must accept the initiative for it to pass at the national level.
Therefore, we display the mice in cantons 2 and 3 that voted “No”, because changing their votes would change the acceptation of their canton, and therefore make the initiative pass at national level.
To submit for this subtask, please log in.
You now want to influence an actual vote.
Any mouse may change its mind if given 1 piece of cheese.
Same as Subtask 4.
For the -th test case, output a line “Case #t: X”, where is the minimum total cost needed to make the initiative pass. Test cases are numbered from to .
Input:
1 6 8 -1 0 0 1 2 2 1 1 3 4 3 5 6 7 1 1 0 0 1 1
Output:
Case #0: 1
Comment:
To submit for this subtask, please log in.
There are now more mice, and they have learned to be greedy.
Each mouse changes its mind when given a certain amount of cheese. The persuasion cost depends on the mouse.
Same as Subtask 4, except that each test case has an additional fifth line containing integers : the persuasion cost of mouse .
For the -th test case, output a line “Case #t: X”, where is the minimum total cost needed to make the initiative pass. Test cases are numbered from to .
Note: as in subtask 4, the hierarchy can be very deep, see the note there on how to increase the stack size.
Input:
1 6 8 -1 0 0 1 2 2 1 1 3 4 3 5 6 7 1 1 0 0 1 1 1 1 3 2 2 1
Output:
Case #0: 2
Comment:
To submit for this subtask, please log in.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
After a long hike through the Swiss Alps, Mouse Stofl has finally fallen asleep. Unfortunately, the annual Mouse Bell Festival is about to begin in the nearby valleys.
The festival has bells, numbered from to , spread across valleys, numbered from to . Bell has base loudness and is located in valley .
Sound echoes between the mountains, so bells in the same valley amplify each other. Valley has an echo factor . The loudness of a ringing bell is its base loudness multiplied by the echo factor of its valley and by the number of bells ringing in its valley. The total loudness is the sum of the loudnesses of all ringing bells.
For example, suppose that bells with base loudnesses , and ring in a valley with echo factor . Since three bells are ringing, each of them is multiplied by , so together they have loudness . If the bell with base loudness is muffled, only two bells ring in this valley. Each of them is multiplied by , and the valley is only loud.
Initially, all bells are ringing. Mouse Binna does not want the festival to wake Stofl. She has exactly wool covers. Each cover completely muffles one bell: a muffled bell makes no sound and does not count as ringing.
Help Binna to find the minimum possible total loudness after she muffles exactly bells.
All subtasks use the same input and output format.
The first line contains the number of test cases . test cases follow, each in the following format:
For every , output a line Case #t: L, where is the minimum possible total loudness in test case after muffling exactly bells.
In this subtask, we have .
These limits guarantee that the loudness of every possible choice of muffled bells fits in a signed 64-bit integer.
Input:
2 5 1 2 2 1 4 7 2 3 0 0 0 0 0 4 1 1 1 8 1 5 2 0 0 0 0
Output:
Case #0: 36 Case #1: 24
Comment:
To submit for this subtask, please log in.
In this subtask, we have . Since every valley contains at least one bell, every valley contains exactly one bell.
These limits guarantee that the loudness of every possible choice of muffled bells fits in a signed 64-bit integer.
Input:
2 5 5 2 2 3 8 1 2 1 4 7 2 3 0 4 2 1 3 4 4 1 1 1 1 1 8 1 5 2 3 0 2 1
Output:
Case #0: 11 Case #1: 8
Comment:
To submit for this subtask, please log in.
This year, all bells were cast by the same bell maker, and all valleys have exactly the same shape. So all bells have the same base loudness, and all valleys have the same echo factor. However, different valleys may still contain different numbers of bells.
These limits guarantee that the loudness of every possible choice of muffled bells fits in a signed 64-bit integer.
Input:
2 7 3 2 3 3 3 2 2 2 2 2 2 2 0 1 1 2 2 2 2 6 2 2 1 1 1 1 1 1 1 1 0 1 1 1 1 1
Output:
Case #0: 54 Case #1: 10
Comment:
To submit for this subtask, please log in.
In this subtask, we have .
These limits guarantee that the loudness of every possible choice of muffled bells fits in a signed 64-bit integer.
Input:
2 5 2 2 2 3 1 4 7 2 3 0 0 0 1 1 4 3 1 1 1 1 8 1 5 2 0 1 2 0
Output:
Case #0: 26 Case #1: 8
Comment:
To submit for this subtask, please log in.
In this subtask, we have .
These limits guarantee that the loudness of every possible choice of muffled bells fits in a signed 64-bit integer.
To submit for this subtask, please log in.
There are no additional restrictions.
These limits guarantee that the loudness of every possible choice of muffled bells fits in a signed 64-bit integer.
To submit for this subtask, please log in.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
The mice are having a fajita evening. mice have gathered, and the pantry contains ingredients. Initially, the mice have units of ingredient in stock.
The mice cook after different recipes. Each mouse can eat fajitas of any recipe. Their objective is to eat as many fajitas as possible!
The evening lasts minutes. Each minute, every mouse does exactly one of the following:
The shop never runs out of anything, and the stock is shared by all mice.
What is the maximum total number of fajitas the mice can eat?
In this subtask, you are additionally given a target number , and instead of just claiming that eating fajitas is possible, you have to prove it: Output a complete schedule with which the mice eat at least fajitas.
The first line contains the number of test cases . test cases follow, each in the following format:
For the -th test case, output a line “Case #t:”, followed by lines: The -th of which describes minute and contains space-separated actions, the -th of which describes the action of mouse . Each action can be one of the following:
Input:
1 2 1 3 1 3 1 1
Output:
Case #0: B0 B0 E0 E0 E0 .
Comment:
To submit for this subtask, please log in.
From now on, output only the maximum total number of fajitas eaten. All mice use the same recipe ().
The first line contains the number of test cases . test cases follow, each in the following format:
For the -th test case, output a single line “Case #t: X”, where is the maximum total number of fajitas eaten.
Input:
2 3 2 1 1 1 1 0 1 2 1 3 1 1 1
Output:
Case #0: 2 Case #1: 3
Comment:
To submit for this subtask, please log in.
Same as subtask 2, but the dinner can last much longer, many more mice show up, and the pantry holds many more ingredients.
To submit for this subtask, please log in.
Mouse Stofl and his friend group are getting a bit bored of the same old recipe (“but it was what my grandparents did at home!”), and decided to get experimental. They got a cookbook (Easy Cooking, with at most ingredients!) and now have a second recipe! But they still want to eat as many fajitas as possible in total.
Input:
1 4 2 3 2 3 5 1 2 2 0
Output:
Case #0: 5
Comment:
To submit for this subtask, please log in.
Actually, they found out that they did not like the new recipe that much. But fortunately, Mouse Noémie, the well-known chef, is also part of the group and proposes a complex recipe with more ingredients.
To submit for this subtask, please log in.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
A group of people wants to cross a magic forest. The forest is dangerous, but there is a magic stone that protects everyone who touches it while crossing. At most people can touch the stone at the same time, so at most people can cross together. A group crossing together must walk as slowly as the slowest person in the group.
There is only one magic stone. Once a group has crossed, the stone is on the other side. To let more people cross, one or more people have to bring the stone back. Going back also takes the time of the slowest of them.
For each person you know the time it takes them to cross the forest alone. The input guarantees .
Find the minimum total time until all people have crossed the forest.
At most two people can touch the stone at the same time, i.e. .
The first line contains the number of test cases . test cases follow, each in the following format:
The first line of the test case contains , the number of people. The second line contains integers , the crossing times of the people.
For the -th test case, output a line Case #t: X, where is the minimum amount of time needed for all people to cross the forest.
Input:
1 4 1 2 5 10
Output:
Case #0: 17
Comment:
To submit for this subtask, please log in.
At most people can touch the stone at the same time, where is given in the input. There are at most people.
The first line contains the number of test cases . test cases follow, each in the following format:
The first line of the test case contains and , the number of people and the maximum number of people that can touch the stone at the same time. The second line contains integers , the crossing times of the people.
For the -th test case, output a line Case #t: X, where is the minimum amount of time needed for all people to cross the forest.
Input:
1 4 3 1 2 5 10
Output:
Case #0: 13
Comment:
To submit for this subtask, please log in.
At most people can touch the stone at the same time. There are at most people.
The first line contains the number of test cases . test cases follow, each in the following format:
The first line of the test case contains and , the number of people and the maximum number of people that can touch the stone at the same time. The second line contains integers , the crossing times of the people.
For the -th test case, output a line Case #t: X, where is the minimum amount of time needed for all people to cross the forest.
Input:
1 4 3 1 2 5 10
Output:
Case #0: 13
Comment:
To submit for this subtask, please log in.
At most people can touch the stone at the same time. There are at most people.
Your task is to output any valid schedule that gets all people across. The better your total time, the more points you get.
For each test case, we compute the relative error between your schedule time and the optimal time . Each test case is assigned a quality score based on its error:
Examples for quality :
Subtask Score:
Your total score for the subtask is computed from the average quality across all test cases:
If any schedule is invalid, the subtask gives points.
The first line contains the number of test cases . test cases follow, each in the following format:
The first line of the test case contains and , the number of people and the maximum number of people that can touch the stone at the same time. The second line contains integers , the crossing times of the people.
For the -th test case, output a line Case #t: X U, where is the total time of your schedule and is the number of trips. Then output lines describing the trips in order. Each line has the form
V --> p1 p2 ...
for a trip from the left side to the right side, or
V <-- p1 p2 ...
for a trip from the right side back to the left side. is the number of people in the trip and are their indices (-indexed).
Input:
1 4 2 1 2 5 10
Output:
Case #0: 17 5 2 --> 0 1 1 <-- 0 2 --> 2 3 1 <-- 1 2 --> 0 1
Comment:
To submit for this subtask, please log in.
The forest contains different paths. The magic stone can be carried along any of them, but each path is different: some paths are more dangerous than others, so on path the stone can protect at most people at once. Moreover, the paths have different lengths. A group crossing path needs time units. Every path can be traversed in both directions. It is guaranteed that at least one path can protect or more people.
There is still only one stone, so only one path can be used at a time.
Your task is to output any valid schedule that gets all people across. The better your total time, the more points you get.
The scoring is the same as in Subtask 4, except that the quality score is:
The first line contains the number of test cases . test cases follow, each in the following format:
The first line of the test case contains and , the number of people and the number of paths. The second line contains integers , the crossing times of the people. The third line contains integers , the maximum number of people the stone can protect on each path. The fourth line contains integers , the length factors of the paths.
For the -th test case, output a line Case #t: X U, where is the total time of your schedule and is the number of trips. Then output lines describing the trips in order. Each line has the form
V P --> p1 p2 ...
for a trip from the left side to the right side using path , or
V P <-- p1 p2 ...
for a trip from the right side back to the left side using path . is the number of people in the trip, is the path index (-indexed), and are the people crossing.
Input:
1 3 2 1 2 3 2 2 1 2
Output:
Case #0: 9 3 2 0 --> 0 1 1 0 <-- 0 2 1 --> 0 2
Comment:
To submit for this subtask, please log in.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
Mouse Binna is a legendary explorer. Long ago she traveled through a region with sites, numbered to . All we have from that time is an old book, which contains some of the rules that every explorer must follow, together with a record of her trip.
In the book, we can see that the sites are connected by one-way routes. For each site the book records a circular order of its neighbors, i.e. the sites the explorer can reach with a direct route. While exploring the neighbors, an explorer must follow this circular order, but may begin at any neighbor they like. So if the book records for a site, they can go through its neighbors as , as or as , but not as .
Binna started at site . At every site with at least one neighbor she picked one of them to begin with, and then went through all of that site’s neighbors in the circular order recorded in the book. Each new site she came to she explored right away; the ones she had already visited she skipped. Formally, when is the number of neighbors of site and the index of the neighbor Binna began with:
explore(A):
mark A as visited
for i = 0, 1, ..., d[A] - 1:
B = the neighbor of A at index ((t[A] + i) mod d[A])
if B is not visited yet:
explore(B)
The whole trip is the single call explore(S).
When Binna first arrived at a site other than , she came there from some site. The book records that site as , and for the start site it records . Together these numbers describe the Explorer’s Tree.
Here the book also tells you which neighbor Binna began with at every site. Work out the Explorer’s Tree.
The first line contains the number of test cases . Each test case looks like this:
For the -th test case, output a line “Case #k:”, followed on the same line by integers : the Explorer’s Tree. Test cases are numbered from to in all subtasks.
Input:
2 4 4 0 3 2 1 3 1 2 0 0 1 0 0 0 6 9 3 1 4 1 0 2 4 5 3 0 1 5 0 2 2 3 0 0 0 2 0 1
Output:
Case #0: -1 0 1 0 Case #1: 3 3 5 -1 2 3
Comment:
To submit for this subtask, please log in.
From here on the book does not say which neighbors Binna began with. Instead it gives the Explorer’s Tree. Decide whether her trip could have produced exactly that Explorer’s Tree, that is, whether there is a choice of starting neighbors that leads to it.
In this subtask, for every and , between which there is a route, one of the two sites is an ancestor of the other in the Explorer’s Tree. The ancestors of a site are , then , then , and so on up to . The start site has no ancestors.
The same as in Subtask 1, except for the last line of a test case. Instead of the starting neighbors it contains integers which describe the Explorer’s Tree. You can rely on all of this:
These input guarantees also apply to Subtasks 3–6. The restriction that every route connects an ancestor and a descendant applies only to Subtask 2.
For the -th test case, output a line “Case #k: YES” if the starting neighbors can be chosen so that Binna’s trip produces exactly this Explorer’s Tree, and “Case #k: NO” otherwise.
Input:
2 4 4 0 3 2 1 3 1 2 0 0 -1 0 1 0 5 6 0 4 3 1 4 2 1 3 1 4 0 0 -1 0 0 1 2
Output:
Case #0: YES Case #1: NO
Comment:
To submit for this subtask, please log in.
Input and output as in Subtask 2. In this subtask, exactly two routes are not part of the Explorer’s Tree.
Input:
2 6 7 0 1 1 2 2 3 1 4 1 5 1 5 1 0 -1 0 1 1 2 3 6 7 0 1 1 2 2 3 1 4 1 5 1 5 1 4 -1 0 1 1 2 3
Output:
Case #0: YES Case #1: NO
Comment:
To submit for this subtask, please log in.
Input and output as in Subtask 2. In this subtask, the Explorer’s Tree is a star: for every site .
Input:
2 4 6 0 3 1 2 3 1 3 1 1 1 2 -1 0 0 0 4 4 0 3 1 2 3 1 3 0 0 -1 0 0 0
Output:
Case #0: NO Case #1: YES
Comment:
To submit for this subtask, please log in.
Input and output as in Subtask 2. In this subtask, every site has at most neighbors.
Input:
2 7 10 0 2 1 2 3 3 6 4 1 5 1 6 1 5 1 0 1 4 -1 0 0 1 1 2 3 7 10 0 2 1 2 3 3 4 6 1 5 1 6 1 5 1 0 1 4 -1 0 0 1 1 2 3
Output:
Case #0: YES Case #1: NO
To submit for this subtask, please log in.
Input and output as in Subtask 2. In this subtask, there are no further constraints.
Input:
2 25 35 0 12 1 2 3 4 5 6 7 8 9 10 11 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 12 1 1 1 2 1 3 0 1 5 1 6 1 7 1 8 1 9 1 10 1 11 -1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 25 36 0 12 1 2 3 4 5 6 7 8 9 10 11 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 12 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 -1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12
Output:
Case #0: YES Case #1: NO
To submit for this subtask, please log in.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
Mouse Stofl has been elected mayor of Potsdam. His entire campaign ran on a single slogan:
Postdam – Rohrpost Delivers All Mice
and with it he promised two things: to rename the city to Postdam, and to build a Rohrpost to finally give it a functioning public transport system made for mice.
Renaming the city was the easy part. This being Germany, there is an established and documented process for it (§ 9(1) BbgKVerf). Stofl filed the forms on day one and paid 1.15 euros in processing fees. After just 1’456 of his 1’461 days in office, the name change was officially confirmed. Building the Rohrpost is harder, so Stofl needs your help.
A Rohrpost is a network of underground tubes through which capsules are propelled by compressed air from so-called machine stations. This technology for the future of urban mobility has been demonstrated to work in a proof of concept in which almost 8 million shipments a year were delivered over a 400 km network. This experiment from 1865 became known as Berlin’s Rohrpost and was so successful that it ran for over a hundred years. The Postdam capsules will be bigger and better, and they are designed to deliver mice.
Postdam consists of intersections, numbered to , connected by roads. The -th road connects the intersections and , and a mouse needs minutes to walk along it; we call the walking time of the road. Between any two intersections there is exactly one route.
Stofl can lay tubes along some of the roads; a road with a tube along it is called a tubed road. Capsules inside the tubes are so fast that a ride in one takes minutes. The compressed air only works if the whole system is one piece, so the tube network must be connected: It must be possible to get from every tubed road to every other tubed road using tubed roads only. A mouse may enter and leave the tube network at any intersection along it.
The travel time between two intersections is the total walking time along the route between them, where every tubed road on that route takes minutes. The in Stofl’s slogan also stands for a delivery guarantee: His election poster promises that the travel time between every pair of intersections is at most minutes. He did not commit to an exact , but he claimed it would be “as small as the d in Postdam”, and, as he keeps his promises, he needs to be as small as possible. For a given tube network, is the largest travel time between any two intersections.
An intersection at which exactly one tubed road ends is a terminal of the tube network, and we say that the network branches at an intersection where three or more tubed roads meet. A tube network with exactly two terminals is a single tube line.
Instead of listing every tubed road, you describe a tube network by its terminals: distinct intersections . The network then consists of all roads that lie on the route between some pair of them, that is, the smallest connected network containing all of them. Every nonempty tube network has a unique set of terminals, so each you print must be a terminal of the resulting network, and not an intersection inside it. You may list the terminals in any order.
Stofl’s campaign promised the mice at least two terminal stations, so . He promised his voters a Rohrpost, so he has to build one – even where the best is already reached without laying a single tube.
In every subtask, test cases are numbered from to .
Stofl is thinking about where to put the first tube line. If he places it along the route between the intersections and , what is once that line is in service?
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 #t:” followed by a single integer, the value of .
Input:
1 6 0 4 0 2 3 1 2 3 2 3 2 3 4 4 3 5 4
Output:
Case #0: 7
Comment:
To submit for this subtask, please log in.
Stofl has been staring at his first tube line all night and is now convinced that the best line is the one that runs along a longest route: That way, the two intersections that are furthest apart are helped the most.
Show him that this is wrong. You are given the road network without walking times, and you choose the walking times yourself. Call a route longest if no other route has a larger total walking time. Assign a walking time to every road such that every longest route, tubed on its own, gives a strictly larger than the smallest that any tube line achieves. For some road networks no such assignment exists; in that case, say so.
The first line contains the number of test cases . The test cases follow in the following format:
For the -th test case: If such walking times exist, output a line “Case #t: Possible” followed by a line with integers, where the -th of them is the walking time you assign to the -th road. Otherwise output a single line “Case #t: Impossible”.
Any assignment with the required property is accepted.
Input:
2 2 0 1 10 0 1 0 2 0 3 1 4 1 5 2 6 2 7 3 8 3 9
Output:
Case #0: Impossible Case #1: Possible 2 3 3 4 3 2 1 2 1
Comment:
To submit for this subtask, please log in.
Stofl now has to decide for real. He still builds a single tube line, that is, a tube network with two terminals. Which line makes as small as possible?
As in subtask 1, except that the second line of every test case (the one with and ) is missing.
For the -th test case, output a line “Case #t: D M” where is the best (that is, smallest) delivery guarantee that a single tube line achieves and is the number of terminals of your tube line. Then output a line with the two intersections, separated by a space.
If multiple tube lines achieve , you may output any of them. The you print must be the one your own network achieves.
Input:
1 6 0 2 3 1 2 3 2 3 2 3 4 4 3 5 4
Output:
Case #0: 6 2 4 5
Comment:
To submit for this subtask, please log in.
The city council approves the Rohrpost, but the budget stretches to exactly one machine station. All the compressed air comes from there, so the tube network may branch at no more than one intersection – the machine station itself. The tube network has at most terminals.
As in subtask 3, except that the first line of every test case contains and .
For the -th test case, output a line “Case #t: D M” where is the best (that is, smallest) delivery guarantee that such a tube network achieves and is the number of terminals of your tube network. Then output a line with those intersections, separated by spaces. Your answer must satisfy , and the intersections must be pairwise distinct. In addition, your tube network must branch at no more than one intersection.
If multiple tube networks achieve , you may output any of them. The you print must be the one your own network achieves.
Input:
2 6 4 0 2 3 1 2 3 2 3 2 3 4 4 3 5 4 5 2 0 1 1 0 2 1 0 3 1 0 4 1
Output:
Case #0: 3 3 0 4 5 Case #1: 2 2 0 1
Comment:
To submit for this subtask, please log in.
After the first capsule crosses Postdam in under a minute, the city council approves a supplementary budget and Stofl buys more machine stations. The tube network may now branch at any number of intersections, but tubes are not free: it still has at most terminals, and is now small.
As in subtask 4, except that the tube network may branch at any number of intersections.
Input:
1 6 4 0 2 3 1 2 3 2 3 2 3 4 4 3 5 4
Output:
Case #0: 0 4 0 1 4 5
Comment:
To submit for this subtask, please log in.
The Rohrpost was a big success. Stofl is re-elected, and even the city signs have arrived, finally making the renaming complete. The city council has also approved an expansion of the network: The number of terminals can now be up to , and the limits for have been extended too. Everything else is as in subtask 5.
As in subtask 5.
Since we can’t ensure that optimized brute-force solutions or heuristics won’t be able to pass, we will manually check all submissions and may retroactively give an accepted submission 0 points.
We expect a solution that runs in for a constant , where is the largest walking time. See Introduction to Algorithm Design for an explanation of the -notation.
To submit for this subtask, please log in.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
The grader practice for the second round consists of 4 tasks, each of which is worth 25 points. You can gain a maximum of 100 points counting towards your second-round score.
Grader PracticeThis helps you get familiar with our grading system which we will use in all our events after the second round, including workshops, camp, finals, and team selection.
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 the grader practice, 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 (700) | tablegr… (100) tablegroups | microwa… (100) microwaving | standemehr (100) | alpinee… (100) alpineechoes | fajitas (100) | magicfo… (100) magicforest | graderp… (100) graderpractice |
|---|---|---|---|---|---|---|---|---|---|
| loading ... |
| Rank | Username | Total (700) | standemehr (100) | alpinee… (100) alpineechoes | fajitas (100) | magicfo… (100) magicforest | explorer (100) | rohrpost (100) | graderp… (100) graderpractice |
|---|---|---|---|---|---|---|---|---|---|
| loading ... |