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 | marathon | ‒/100 | ‒/20 | ‒/20 | ‒/20 | ‒/20 | ‒/20 |
Junior only | stickers | ‒/100 | ‒/10 | ‒/20 | ‒/20 | ‒/20 | ‒/30 |
Both | bargain | ‒/100 | ‒/10 | ‒/25 | ‒/25 | ‒/15 | ‒/25 |
Both | reversi | ‒/100 | ‒/10 | ‒/20 | ‒/20 | ‒/50 | |
Both | sbb | ‒/100 | ‒/25 | ‒/25 | ‒/25 | ‒/25 | |
Regular only | arcmatch | ‒/100 | ‒/10 | ‒/10 | ‒/10 | ‒/30 | ‒/40 |
Regular only | earthwormsurgery | ‒/100 | ‒/20 | ‒/20 | ‒/60 | ||
Regular only | soiway | ‒/100 | ‒/25 | ‒/25 | ‒/25 | ‒/25 |
In anticipation of the Olympic games in 2020, Mouse Binna decided she wants to organise a marathon for herself and her friends. The conditions for this idea seemed perfect – in her village there is a very long road. However, upon further investigation, she discovered that the road is not in a very good shape and there are a lot of holes. Since Mouse Binna doesn’t want someone to trip and hurt themselves while running, there cannot be any holes on the track. Your task is to help her organise the longest marathon possible.
Mouse Binna wants to use only a short part of the road. Your first program should help her figure out the maximum possible length of the race.
The first line contains the number of test cases . test cases follow in the following format:
You should output T lines, one for each test case. For the -th test case output “Case #i: l”, where is equal to the maximum length of the marathon Mouse Binna can organise.
Input:
2 3 1 0 0 3 0 1 0
Output:
Case #0: 2 Case #1: 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.
Your task here is the same as in subtask 1, but with a longer road.
The input format is the same as in subtask 1.
The output format is the same as in subtask 1.
The examples are the 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.
Your task here is the same as in subtask 1, but with an even longer road.
The input format is the same as in subtask 1.
The output format is the same as in subtask 1.
The examples are the 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.
While Mouse Binna was thinking of the possible marathons she could organise, a friend of hers who is working in construction proposed to fix some of the holes on the road. However she only has enough material to fix holes. Help Mouse Binna find out what is the longest marathon she can organise now by fixing at most holes.
The first line contains the number of test cases . test cases follow in the following format:
The output format is the same as in subtask 1
Input:
2 10 3 0 0 0 1 1 1 0 0 0 0 12 3 0 1 0 0 1 1 0 1 0 0 1 0
Output:
Case #0: 10 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.
Same as in subtask 4, but with a longer road and more material to fix holes.
The input format is the same as in subtask 4.
The output format is the same as in subtask 1.
Same as in subtask 4.
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 loves collecting stickers. After buying many of them, he realises that each sticker belongs to a specific family. His wish is now to have as few different families of stickers as possible. Unfortunately, the stickers he buys are given at random, but he can trade some of his stickers with his friends. Depending on how nice his friends are, he has to pay them additional money to convince them of trading their stickers.
Your goal is to help Stofl to minimize the number of different families he owns, without paying too much.
Stofl bought exactly three () stickers and as his friends are really nice, they are willing to trade their stickers if he pays them one Swiss franc for every sticker trade. Help him to minimize the amount of money he has to spend so that all of his stickers belong to only one family.
The first line contains the number of test cases . test cases follow, in the following format:
The first line of the test case contains , the number of stickers Stofl owns (in this subtask, we have ) and , the maximum number of different families Stofl wants to own after all his trades (in this subtask, we have ).
The second line contains numbers , where represents the family of the -th sticker. The cost of trading one sticker of one family for a sticker of another family is Swiss franc.
For the -th test case, output a line “Case #i: M”, where is the minimal amount of money Stofl has to spend.
There are test cases. In all test cases , and .
Input:
2 3 1 1 2 1 3 1 1 2 3
Output:
Case #0: 1 Case #1: 2
Comment:
In case #0, Stofl already owns two stickers of the same family, he then trades the sticker belonging to family for one of his friends’ stickers which belongs to family . He needs to pay one franc as he makes one trade.
In case #1, Stofl has to trade at least two stickers with his friends to have three stickers of the same family.
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 fell in love with this game so he decided to buy even more stickers. He now owns more than three stickers.
Same as in subtask 1, but is not necessarily anymore. Note that there are now many more families in the game than before ().
There are test cases. In all test cases , and .
Input:
3 3 1 1 3 2 5 1 1 3 3 2 1 4 1 1 1 9 10
Output:
Case #0: 2 Case #1: 3 Case #2: 2
Comment:
In case #0, Stofl has to trade two stickers.
In case #1, one possible solution is to trade away the stickers belonging to the families 1 and 2. He can do this with three trades.
In case #2, Stofl keeps the stickers belonging to family . He trades the rest away in exchange for stickers of family .
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 spent a lot of money to buy the stickers and realizes he can’t keep spending as much as before to trade stickers. He decides that owning more than one family of stickers isn’t that bad after all. The maximum number of different families is not restricted to anymore.
Same as in subtask 1 but is not necessarily anymore.
There are test cases. In all test cases , and .
Input:
3 3 3 1 8 70 5 2 1 2 2 5 3 7 2 9 2 13 1 13 9 13
Output:
Case #0: 0 Case #1: 2 Case #2: 2
Comment:
In case #0, Stofl can own up to three different sticker families. So he does not have to trade at all.
In case #1, Stofl can own up to two sticker families. He could trade away the families and to achieve this.
In case #2, Stofl decides to trade away stickers belonging to family and .
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 is now done with buying new stickers. Since the last update of the game, families now have values. In particular, family is worth Swiss francs. Stofl now trades according to the following rules:
Can you help Stofl to find the minimum amount he has to pay in order to make all his stickers belong to one of at most two families?
Same as in subtask 1. is always equal to .
There are test cases. In all test cases, , and .
Input:
3 3 2 10 2 1 5 2 10 5 7 8 4 5 2 1 3 2 2 4
Output:
Case #0: 1 Case #1: 6 Case #2: 2
Comment:
In case #0, Stofl decides to trade the sticker of family for another sticker of family . This way, he owns stickers of at most different families.
In case #1, Stofl trades the stickers belonging to families and for two stickers of family . Additionaly he trades a sticker of family for one of family .
In case #2, Stofl trades for stickers belonging to families and .
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 wants to expand his collection of stickers and no longer restricts himself to only two families anymore. Help him solve the general case.
Same as in subtask 1.
There are test cases. In all test cases , and .
Input:
3 4 3 1 3 8 4 8 3 1 4 2 3 3 8 1 6 6 4 9 7 8 7 1 2
Output:
Case #0: 1 Case #1: 6 Case #2: 1
Comment:
In case #0, Stofl trades the sticker belonging to family for one of family .
In case #1, Stofl can trade sticker of family for one of family . He then trades his two stickers belonging to family for stickers of family . Finally, he trades his stickers of family for stickers belonging to family . The total cost is .
In case #2, Stofl trades the sticker belonging to family for one of family .
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).
This year, Mouse Binna participates for the first time in the Swiss Mouse Olympiad in Informatics. This involves a lot of travel by train, and unlike its human counterpart, the SMOI does not refund train tickets. As taking the train in Switzerland is quite expensive, Mouse Binna has a brilliant idea: in each city in which she passes during her trips, she goes to a market where she can buy cheese from a merchant or sell some that she has already acquired. The prices, of course, vary from city to city. Binna’s goal is to buy cheese for not too much money and resell it later for a profit, in order to pay for her tickets. Can you help her figure out where to buy and where to sell cheese so that she can maximize her profits?
The first event to which a participant must go to succeed in the olympiad is the workshop in autumn. Mouse Binna decides to go in order to learn the programming and algorithmic skills needed for the first round (you can do so too: more information on this page).
Since there are workshops organized in several regions of Switzerland, Mouse Binna does not need to travel far, she can even use a direct train. That means there are exactly two cities where she can buy or sell cheese: her home city and the one in which the workshop is organized. She does not have any money to buy cheese herself, but she talked with her parents about the project and they agreed to pay for at most one loaf of cheese. That means that Binna can buy and sell at most once in total. Of course, she’s not obliged to buy anything; in that case, she just makes no profit, which is better than losing money.
There’s another restriction: in order to get home early on the last day, Mouse Binna wants to do all of this on her way to the workshop. That means she can’t sell cheese from the second city in the first one.
The first line contains the number of test cases . test cases follow, in the following format:
You should output lines, one for each test case. For the -th test case, output a line “Case #i: P”, where is the maximal profit made by Binna. Note that test cases are numbered from to and not from to .
There are test cases. In every test case, the following restriction holds:
Input:
2 4 2 7 6 8 5 3 2
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.
Thanks to the training in the workshop, Mouse Binna has done really well in the first round and has qualified for the SMOI Winter Camp! She decides to buy and sell cheese on her way, exactly like last time.
There’s just one big difference: there is no direct train to the camp. Mouse Binna must change trains in several places, which means she’ll visit cities in total. That makes the travel longer, but has a big advantage: there are now many more opportunities to make a profit. Note, again, that you can’t go back to an earlier city to sell cheese you’ve bought in a later one.
The first line contains the number of test cases . test cases follow in the following format:
Same as in subtask 1.
There are test cases. In every test case, the following restrictions hold:
Input:
3 4 6 5 8 4 11 8 4 1 3 7 5 4 1 3 2 4 3 2 7 6 2 1 6 3
Output:
Case #0: 2 Case #1: 0 Case #2: 3
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 the camp, Mouse Binna has kept on training well and obtained a good result in the second round, and, later, a gold medal in the national finals. That’s why she’s now qualified for the International Mouse Olympiad in Informatics, which takes place in Singapore this year. She decides to still travel via trains (in reality, some busses would be needed as well), as she wants to continue buying and selling cheese on the way. She has realized that she can make quite a lot of money that way.
Because of the good results of the first experiments, Mouse Binna’s parents trust her more and allow her to buy a maximum of loafs of cheese. Of course, she can buy less than loafs, and she can buy or sell several ones in the same city. Help her figure out where to buy and sell the cheese exactly in order to make the biggest possible profit.
The first line contains the number of test cases . test cases follow in the following format:
Same as in subtasks 1 and 2.
There are test cases. In every test case, the following restrictions hold:
Input:
2 5 2 7 4 12 4 9 8 5 3 7 6 4 3 3 2 7 6 2 1 6 3
Output:
Case #0: 2 Case #1: 9
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 Binna has done well in the IMOI and is starting university now. She’d like to give back what she can to the SMOI and becomes a leader there. That means she still has to travel to some national events to train students, and for that reason, she wants to continue making money with her cheese business.
There is one key difference now: Mouse Binna is an adult and does not need her parents’ help anymore. She can just borrow money from the bank, which agrees to lend her any amount without interests because of her previous successes. Mouse Binna is therefore not limited in the total amount of cheese loafs she can purchase. Of course, she cannot take an infinite quantity of cheese with her. She can, at any time, carry only units of cheese at most. Help her again to find where and how much cheese she should buy and sell.
The first line contains the number of test cases . test cases follow in the following format:
Same as in subtasks 1 to 3.
There are test cases. In every test case, the following restrictions hold:
Input:
1 7 4 4 3 7 5 8 2 3 2 9 5 8 7 10 6
Output:
Case #0: 20
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.
Binna has worked hard to prepare the Swiss participants for the next International Mouse Olympiad in Informatics and has well earned her place as one of the two leaders accompanying the national team there. Help her optimize her profits on the way there.
This subtask is the same problem as subtask 4, but can be much larger.
Same as in subtask 4.
Same as in subtasks 1 to 4.
There are test cases. In every test case, the following restrictions hold:
See subtask 4.
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 and Mouse Stofl are playing a strategy board game called Reversi . Usually it is played with discs on an 8×8 board and two players. They quickly got bored playing it and came up with their own version which is played on an (endless) row:
Each disc occupying a square has a dark and a light side.
If we now place a dark disc to the left end of the line then every light disc between that and the next dark disc is flipped.
A similar thing happens if we add a light disc to the left end. Note that if we add a disc with the same colour as the one at the end of the line then no disc gets flipped. The same procedure applies to the right end.
Here, you can play around with the mechanics to get familiar with them:
Our mice came up with some interesting questions for you to solve.
Given an arrangement of continuous discs and the operation of appending either a light or dark disk on either the left or the right end output the state after the operation.
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 discs. A second line follows with a bitstring containing characters consisting only of 0’s and 1’s, where a 0 represents a dark and a 1 a light disc. It is guaranteed that contains at least one 0 and one 1. The third line contains a character and a bit describing the operations:
For the -th test case, output a single line “Case #i: R”, where is the bitstring representing the state after the operation. should only contain 0’s and 1’s.
Input:
3 4 1000 R 1 7 0101010 L 0 15 000011111100100 L 1
Output:
Case #0: 11111 Case #1: 00101010 Case #2: 1111111111100100
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.
You are given an arrangement of continous discs. What is the minimum number of operations you need such that all discs will be of the same colour?
The first line contains the number of test cases . test cases follow in the following format:
The first line of the test case contains , the number of discs. A second line follows with a sequence of length , consisting only of 0’s and 1’s, where a 0 represents a dark and a 1 a light disc. It is guaranteed that contains at least one 0 and one 1.
For the -th test case, output a single line “Case #i: M”, where is the minimum number of operations.
Input:
3 4 1000 7 0101010 15 000011111100100
Output:
Case #0: 1 Case #1: 6 Case #2: 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.
Again, an arrangement of continous discs is given. We define now the cost of an operation as the number of discs that get flipped + 1 (meaning we include the newly appended disc). Your task is now to calculate the minimum cost you need such that all discs will be the same colour.
Same as in Subtask 2.
For the -th test case, output a single line “Case #i: M”, where is the minimum cost.
Input:
3 4 1000 7 0101010 15 000011111100100
Output:
Case #0: 2 Case #1: 24 Case #2: 21
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.
You should do the same as in substask 3. But Mouse Stofl and Mouse Binna don’t trust your solution, meaning you need to justify why your solution is correct.
Describe an algorithm that can solve subtask 3 and analyze it. This is a theoretical task so you should reason why your solution is correct and what asymptotic running time and memory usage your solution has.
You should optimize for running time first and memory usage second.
Check out the wiki for more information on how to solve/write theoretical tasks: Theoretical Intro
Hand in a document (preferably PDF) that describes
We give you the option to hand in your solution earlier and you will receive a feedback within roughly a week. This includes how many points you would get and comments on where to improve the solution. Afterwards, you may adjust your solution and send it in again for more points. Submissions after 26.11.2019 will not receive any feedback before the end of the round.
If everything is correct, we will give you points based on the table below.
Running time | Memory usage | Max score |
---|---|---|
any | any | 5 |
10 | ||
20 | ||
25 | ||
30 | ||
40 | ||
50 |
If you are not familiar with the notation, you can read about it here.
Note: You can assume that the input is given as a read-only array, which means you can’t change the values. This array doesn’t count to your memory, so only additional memory counts to your memory analysis.
Here you can see a rough outline of the marking scheme and how the points are awarded for an explanation:
Submissions after 26.11.2019 will not receive any feedback before the end of the round.
The contest is over, you can no longer submit.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
Stofl’s mountain railways (SBB) operates a rail network with stations and routes, which each run in both directions. It is possible from any station to reach every other station by several intermediate routes (i.e., the network is connected). Each track has a length of kilometers and the price of an ordinary billet on a stretch of length is , so the price per kilometer is one. As is common in the mountains, a direct connection between two stations need not be the shortest, i.e. there may be an alternative route with multiple intermediate routes, which is shorter overall.
The SBB have recently introduced a savings offer, the so-called StoflTicket. A StoflTicket is offered to for pairs of train stations and allows a ride between the two stations (in any direction) for a special price.
You now realize that the cheapest price for a ride between two stations can be reached possibly only through a combination of ordinary tickets and StoflTickets. So you want to start a startup which calculates the cheapest price for a trip between two stations. The only goal is to get the best possible price, even if for that a route must be traveled several times.
In order for your server to provide an instant response, you want the cheapest price for each pair of stations precalculated.
You are given a description of the rail network of the SBB as well as StoflTickets. Your job is to find the lowest price for a journey between each pair of stations.
The first line contains the number of test cases . This is followed by test cases in the following format:
The first line contains three integers: , , . The next lines indicate a route. The -th of these lines consists of three integers: , , , which specify the two terminus stations , , and the length of the route. The next lines describe a StoflTicket. The -th of these lines consists of three integers: , , , which specify the two terminus stations , , and the special price of this StoflTicket.
For the -th test case, issue a line “Case #i: N”, followed by lines. The -th line contains integers , separated by spaces, which indicates the cheapest price for a ride between the stations and . For you should output .
There are test cases.
In each test case:
Input:
3 5 4 0 0 1 1 1 2 1 2 3 1 3 4 1 5 4 1 0 1 1 1 2 1 2 3 1 3 4 1 0 4 1 3 3 1 0 1 1 0 2 1 0 1 1 0 2 1
Output:
Case #0: 5 0 1 2 3 4 1 0 1 2 3 2 1 0 1 2 3 2 1 0 1 4 3 2 1 0 Case #1: 5 0 1 2 2 1 1 0 1 2 2 2 1 0 1 2 2 2 1 0 1 1 2 2 1 0 Case #2: 3 0 1 1 1 0 2 1 2 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.
The task as well as input/output are the same as for Subtask 1.
There are test cases.
In each test case:
Input:
3 5 4 0 0 1 5 1 2 10 2 3 10 3 4 5 5 4 1 0 1 5 1 2 10 2 3 10 3 4 5 0 4 1 3 4 2 0 1 5 0 2 4 0 1 2 0 1 3 0 2 1 0 2 6
Output:
Case #0: 5 0 5 15 25 30 5 0 10 20 25 15 10 0 10 15 25 20 10 0 5 30 25 15 5 0 Case #1: 5 0 5 15 6 1 5 0 10 11 6 15 10 0 10 15 6 11 10 0 5 1 6 15 5 0 Case #2: 3 0 2 1 2 0 3 1 3 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.
The SBB want to bankrupt your start-up so they introduced the same feature into their own app. You have now queried all their pairwise prices and want to find out whether there is a rail network and StoflTickets offers, such that the prices correspond. If there are several solutions, you should first minimize the number of StoflTickets and then minimize the total length of the regular connections. If there are still several solutions with these additional criteria, you can output any of them.
The first line contains the number of test cases . This is followed by test cases in the following format:
The first line contains the number of stations , followed by lines. The -th of these lines contains` N` integers separated by spaces, which indicates the price quoted for a journey between the stations and . For , . In addition, .
For the -th test case, if an input exists for subtask 1, which returns the -th test case as output, output a line “Case #i: OK”, followed by an input for subtask 1, which returns the -th test case as output, in the same format as in Subtask 1. Otherwise, output a line “Case #i: Inconsistent”.
Input:
3 5 0 1 2 3 4 1 0 1 2 3 2 1 0 1 2 3 2 1 0 1 4 3 2 1 0 5 0 1 2 2 1 1 0 1 2 2 2 1 0 1 2 2 2 1 0 1 1 2 2 1 0 2 0 10 10 0
Output:
Case #0: OK 5 4 0 0 1 1 1 2 1 2 3 1 3 4 1 Case #1: OK 5 5 0 0 1 1 0 4 1 1 2 1 2 3 1 3 4 1 Case #2: Inconsistent
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 task as well as input are the same as for Subtask 3.
For the -th test case, if an input exists for Subtask 2 which returns the -th test case as output, output a line “Case #i: OK”, followed by an input for Subtask 2, which returns the -th test case as output, in the same format as in Subtask 2. Otherwise, output a line “Case #i: Inconsistent”.
Input:
3 5 0 5 15 25 30 5 0 10 20 25 15 10 0 10 15 25 20 10 0 5 30 25 15 5 0 5 0 5 15 6 1 5 0 10 11 6 15 10 0 10 15 6 11 10 0 5 1 6 15 5 0 3 0 1 2 1 0 10 2 10 0
Output:
Case #0: OK 5 4 0 0 1 5 1 2 10 2 3 10 3 4 5 Case #1: OK 5 5 0 0 1 5 0 4 1 1 2 10 2 3 10 3 4 5 Case #2: Inconsistent
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 visiting his friends in Mousepore. Unlike in Switzerland, where each mouse lives in a single mouse hole, in Mousepore each mouse owns two holes. All holes in Mousepore are arranged in a single street on a straight line. As the mice have to commute quite frequently from one of their holes to the other one and this often leads to clashes, they ask Mouse Stofl for help to plan how to build non-intersecting connections. A connection is a path that connects two holes of a mouse directly (without using the street) and non-intersection means that a path can be drawn without crossing the street or another path (see visualization). Paths can either be built on the right or the left side of the street.
Since the street goes along the shoreline, the paths can only be built on the left side of the street.
Is it possible to do that without having two paths overlap?
The first line contains the number of test cases . test cases follow, each with , the number of mice, on the first line. On the second line numbers follow . The -th hole is owned by mouse , and each mouse owns exactly two holes.
For the -th test case print a line “Case #i:” followed by “Possible” if it is possible to build the connection paths without having them intersect. If it is impossible to do so, then you should print “Impossible” instead.
Input:
5 1 0 0 2 0 1 0 1 4 0 0 1 1 2 3 3 2 5 1 0 2 3 3 2 4 4 0 1 5 1 0 2 3 3 4 2 4 0 1
Output:
Case #0: Possible Case #1: Impossible Case #2: Possible Case #3: Possible Case #4: Impossible
Case #1 (impossible): *---* | *-|-* | | | | 0 1 0 1 Case #2 (possible): *-----* *-* *-* | *-* | | | | | | | | | 0 0 1 1 2 3 3 2
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 before, but this time .
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 the area is surrounded by land, so the connections can be built on both sides. Is it possible now? If yes, print which path goes on which side.
For the -th test case print a line “Case #i:” followed by characters L or R. If the -th character is “L”, this means that the two houses of mouse are connected by a path on the left, if the character is “R” they are connected on the right. If there are multiple possibilities, print any of them.
Input:
5 4 1 2 3 0 0 2 3 1 3 1 2 0 1 0 2 3 1 2 0 1 2 0 2 1 1 0 0 8 0 1 2 3 4 5 4 6 7 6 7 5 2 3 0 1
Output:
Case #0: LLRL Case #1: RLR Case #2: Impossible Case #3: RR Case #4: RLRLRLRL
Comment:
Case #1: *-----* | | 1 2 0 1 0 2 | | | | | *---* | *-------* Case #2 (impossible): *-----* | | 1 2 0 1 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.
Same as before, but this time .
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 the city is very large: .
Only print Possible or Impossible (otherwise the output is too large to be uploaded).
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 (or or ). See Introduction to Algorithm Design on what those symbols mean.
Unless you exploit how the tests are generated or were squeezing your solution through the time limit, you should be fine.
Note: We need around 20sec to generate the input (depending on your browser and machine) and another 20sec to verify your submission. Please be patient.
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 wants to become a surgeon one day. In her garden, she found the perfect test subjects on which she can practice and perfect her surgery skills: earthworms. Earthworms consists of light and dark brown segments. Depending on her mood, Mouse Binna likes some patterns more than others, so she tries to change the earthworms’ patterns to the ones she thinks fit them best.
Mouse Binna’s surgery patient is Earthworm Jane. Mouse Binna figured out that applying a drop of citric acid to a segment of Earthworm Jane causes that segment to grow rapidly and change its color. A light segment will turn into two dark segments and a dark segment will turn into two light segments. As this causes Earthworm Jane to grow longer and longer, Mouse Binna may want to remove some segments. Based on experiments on some other earthworms, Mouse Binna determined that she can only remove consecutive dark segments or consecutive light segments. Any other surgery would end very badly for Earthworm Jane… Mouse Binna can switch between adding drops of citric acid and surgery operations at any time.
Currently, Earthworm Jane consists of segments with a specific pattern . Mouse Binna prefers the pattern . Can you help her figure out whether she can change the pattern to the one she desires?
The first line contains the number of test cases . test cases follow, each test case consists of three lines. The first line contains two integers and – the current length of Earthworm Jane and her desired length. The second line contains characters , describing the initial pattern of Earthworm Jane. The character 1 is used to describe a light segment and 0 denotes a dark segment. The third line contains characters , describing the pattern Mouse Binna likes the most.
For the -th test case print a line “Case #i:” followed by “YES” or “NO”, indicating whether Mouse Binna can turn Earthworm Jane’s pattern into the one Mouse Binna likes the most.
Input:
3 1 2 0 11 7 1 0001000 1 1 2 0 00
Output:
Case #0: YES Case #1: YES Case #2: NO
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.
Earthworm Jane survived the surgery and she’s very happy with her new pattern. She has now invited her brother, Earthworm Jim, to Mouse Binna.
Mouse Binna has already figured out the optimal pattern for Earthworm Jim. Unfortunately Earthworm Jim behaves a bit differently: Applying a drop of citric acid to one of his light segments causes it to turn into dark segments and applying a drop of citric acid to one of his dark segments causes it to turn into light segments. Moreover, Earthworm Jim is a bit more sensitive to surgery, so Mouse Binna can only remove exactly consecutive light segments or consecutive dark segments from him.
Help her determine if she can give Earthworm Jim his optimal pattern.
The first line contains the number of test cases . Each test case consists of three lines. The first line contains four integers , , , – the current length of Earthworm Jim, the desired length of Earthworm Jim and two parameters describing how Earthworm Jim reacts to citric acid and his constraints on surgery. The second line contains characters , describing the initial pattern of Earthworm Jim. The character 1 is used to describe a light segment and 0 denotes a dark segment. The third line contains characters describing the optimal pattern for Earthworm Jim.
For the -th test case print a line “Case #i:” followed by “YES” or “NO”, indicating whether Mouse Binna can give Earthworm Jim his optimal pattern.
Input:
3 1 2 2 3 0 11 9 1 3 4 111101111 0 3 5 1 123 000 11111
Output:
Case #0: YES Case #1: YES Case #2: NO
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.
Earthworm Jim liked his new pattern (although he’s a bit dizzy from all the citric acid he’s received), so he’s told some of his friends about Mouse Binna’s surgery skills. They were quite impressed, so now Mouse Binna has a lot of work to do.
This is a theoretical subtask. Describe an algorithm that can solve subtask 2 and analyze its running time and memory usage.
You should optimize for running time first and memory usage second.
Hand in a document (preferably PDF) that describes
The contest is over, you can no longer submit.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
In Soicity, the capital of Mouseland, a new subway system is supposed to be built, the SOIway. The mayor of Soicity has tasked her best engineer, Mouse Binna, to build the new system. Help Mouse Binna to optimally plan the SOIway lines.
The SOIway network consists of different stations. Over time, new stations are added, which need to be included in the network. For every station you are given their coordinates and their type. The distance between two stations with the coordinates and is equal to (i.e. the rounded up euclidean distance with a correction factor). A train traveling between two stations needs exactly the amount of distance many time steps. A stay in a station needs exactly one time step. Furthermore, you are given a list of passengers with their respective starting position, starting time and their destination type. The station where the passengers start is fixed, but the destination could be any station of the correct type. Time is defined as the number of time steps since the start of the simulation.
Your task is to determine which lines should operate on which stations and how many trains should be used on a given line. You should also specify when passengers board a train and when they get off. The passengers can change the train any number of times. You can reposition trains from a given line at most every timesteps. A train can maximally hold passengers. All lines, trains, stations, station types and passengers will be numbered separately and increasingly from .
In the beginning there are no stations, no passengers and you don’t have any trains or lines available. Those are added during the simulation, i.e. from time to time you will receive new lines and new trains, which can be used.
The goal is to operate the SOIway as long as possible, without overloading the network. The network is overloaded if there is a station with strictly more than passengers. This restriction is only enforced at the end of a turn. It’s no problem if there are too many people at a station during a turn.
The first line contains some constants given as integers: . , , , , are the number of stations, passengers, lines and trains, which occur in the input. lines follow with events. A description of an event allways starts with an integer and a character , where is the point in time and the type of the event. The events are sorted by time. We now describe all event types:
You should output a protocol of all actions you take. A description of an action always starts with an integer and a character , where is the point in time and the type of the action. The actions are sorted by time. Actions with the same point in time will be executed in the order of the protocol. We now describe all action types:
: Defining a line. Two integers follow, the index of the line and , the number of stations. There follow integers , the indices of the stations on the line, in the order in which they should be visited. Trains on the line start their journey at and drive along the defined route. As soon as they reach station they continue to drive to and start their journey once again (“Loop”-operation). If you prefer “Ping-Pong”-operation you can achieve this by defining the route as , , …, , , , …, . The same action can be used to modify an existing line. A line can only be defined if no train is assigned to that line. So to modify a line, all assigned trains have to be removed first. A line can contain at most stations.
: Placing a train. Three integers follow, the index of the train, the index of the line and the index of the station within the line, where the train should start. A train can only be (re)placed if it is empty and was not placed in the last time steps. The train starts its journey from the given starting point and begins after a time step (in which a passenger could board) to drive right away. To temporarily remove a train, use . For a temporarily removed train, there are no restrictions on when it can be placed again.
: Boarding a passenger. Two integer follow, the index of the passenger and the index of the train which the passenger boards. A passenger can only board if there have been strictly less than passengers in the train before and if the train is located at the same station as the passenger. The train is located at the station exactly at the point in time where it arrives, i.e. at the time when it leaves, no more passenger can board.
: Passenger getting off. Two integers follow, the index of the passenger and the index of the station where the passenger is getting off. If the station has the correct type, the passenger vanishes.
: Debug output. The rest of the line will be displayed on the visualization at the corresponding time.
For each subtask we have:
Input:
472 400 12 29 20 450 1 1 0 s 0 0 0 0 0 s 1 -18 -26 1 0 s 2 40 -55 2 0 s 3 -15 60 3 0 s 4 -97 -18 4 0 s 5 40 -15 5 0 s 6 -70 93 6 0 s 7 77 113 7 0 s 8 86 -119 8 0 s 9 142 2 9 ...<snip>... 0 l 0 0 z 0 1 p 0 4 0 4 p 1 8 17 4 p 2 14 8 6 p 3 7 9 6 p 4 2 11 8 p 5 12 16 10 p 6 9 14 12 p 7 13 2 14 p 8 13 1 15 p 9 1 9 21 p 10 5 0 21 p 11 6 1 21 p 12 7 15 22 p 13 7 0 23 p 14 18 5 24 p 15 17 15 25 p 16 10 6 ...<snip>...
Output:
27 r 0 20 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 27 z 0 0 0 27 e 17 0 ...<snip>... 1459 a 17 15 ...<snip>...
You can find a Visualization here. You can also download it here together with a simple example in C++.
For the visualization, you just have to open the file soiwayviz.html in your browser. Afterwards, you can choose the input file, which you have downloaded, and the output file, which your program has generated, and let it display. With space you can start/stop the simulation, with the arrow-keys you can go back and forth (left and right) individual frames or adjust the speed (up and down with shift in integer steps).
Pro Tip: To avoid manually selecting the files, you could place a file debug_input.js in the same folder. This Javascript file has to define the two variables debug_input and debug_output (use Backticks ‘\`’ for strings on multiple lines). If you don’t choose any file in the Browser and click , then this file will be read. This way you can write a small script which executes your program and automatically generates the file debug_input.js.
The example in C++ reads the entire Input and performs a few simple actions such as defining a line and boarding a passenger. This example obviously will not get any points, but you can use this as a template for your solution.
You have exactly one line and one train and all stations are available from the beginning. Each station has a different type. The input is fixed, i.e. every time you download an input you will get exactly the same file. You will get points depending on the number of passenger you managed to transport. If you did not transport all the passengers, you will get at most 60% of the points.
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.
You have several lines and trains from the beginning and all the stations are available from the beginning. The input is fixed, i.e. every time you download an input you will get exactly the same file. You will get points dependent on the number of passenger you managed to transport. If you did not transport all the passengers, you will get at most 60% of the points.
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.
There are no further restrictions. You will get points depending on the number of time steps reached before the network is overloaded. Let be this number. Then you will receive points. The input is fixed, i.e., every time you download an input, you will get exactly the same file.
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.
There are no further limits. You will get points depending on the performance of the other participants. On the SOI-Day, we will look at all the submissions and determine the best program. To submit a solution for this subtask, you have to score at least 15 points in subtask 3.
The input files, which will be used on the tournament, will be generated similarly to the inputs of subtask 3. In particular, the probabilities of the events and their parameters are the same. You can generate different inputs. You can also specify how large the input should 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.
Don’t hesitate to ask us any question about this task, programming or the website via email (info@soi.ch).
Rank | Username | Total (500) | marathon (100) | stickers (100) | bargain (100) | reversi (100) | sbb (100) |
---|---|---|---|---|---|---|---|
loading ... |
Rank | Username | Total (600) | bargain (100) | reversi (100) | sbb (100) | arcmatch (100) | earthwo… (100) earthwormsurgery | soiway (100) |
---|---|---|---|---|---|---|---|---|
loading ... |