Time Limit: 2 seconds
As a special treat for your kindergarten class, you’re taking them on a field trip to a magical place of wonder.
Your class has
Aside from the
You’re getting ready to order buses for the trip, but there are two
issues. Firstly, the transportation company insists that every bus you
order must be filled exactly to its capacity of
All of the other students getting on that bus are acquaintances
of student
All of student
Unfortunately, it looks like you might not be able to bring your
whole class on this trip after all. However, you’ll do whatever it takes
to get as many students as possible on buses. As it turns out, “whatever
it takes” may involve putting an end to a friendship or two, for the
greater good. You may choose to sever
Determine the maximum number of students which can be brought on the
trip, such that they’re loaded onto buses with exactly
The first line contains three space-separated integers
The next
For 3 of the 25 marks available,
The output consists of two space-separated integers printed on one line. The first integer is the the maximum number of students which can be brought on the trip. The second integer is the minimum number of friendships which must be severed in order to bring that many students.
8 5 2
1 4
8 2
4 5
6 2
3 5
6 2
If the friendships between student pairs (8,2) and (4,5) are severed, then 3 buses can be filled as follows:
Bus 1: Students 1 and 4
Bus 2: Students 2 and 6
Bus 3: Students 3 and 5
Time Limit: 15 seconds
As you know, some bunnies are good bunnies, and some bunnies are bad bunnies.
You are given the location of all the bunnies, and their “goodness” weight (a positive integer for good bunnies and a negative integer for bad bunnies). No two bunnies are at the same location. Divide them into two groups using a straight line such that the sum of the “goodness” of the bunnies on one side of the line is as large as possible. A bunny on the line is counted in the sum of the weights on both sides of the line.
The first line contains
For 5 of the 25 marks available,
For an additional 10 of the 25 marks available, no three locations are collinear.
Output the maximum sum of weights that is possible by drawing a straight line and picking all the bunnies which are on one side of that line.
6
1 8 4
1 4 6
7 7 2
4 10 -3
4 6 -9
4 2 8
18
Take the bunnies with goodness weights of 4, 6 and 8, which are on the “left” side of the line, as shown in the diagram below:
Time Limit: 2 seconds
The country of Canadia consists of a network of cities and roads. Each road can be traversed in both directions. It is possible to get from any city to any other city using the roads.
Suzie studies the creation myths of the Canadiaan people. She is particularly interested in five myths (which correspond to the five subtasks of this problem). The myths are very similar. Each myth has the following form:
In the beginning, Canadia’s road network had a particular structure. As time went on, the network was modified to meet the needs of Canadia’s growing population. Each modification had one of the following forms:
A road was built between two cities that did not yet have a road going directly between them.
A new city was built. Cities built in this way were not initially connected to any existing cities.
A city
becomes
The five myths only differ in the structure that they believe Canadia began with. Here are the original structures, according to each myth:
Subtask 1 [The Myth of the Flask]
Subtask 2 [The Myth of the Moon]
Subtask 3 [The Myth of the Sun]
Subtask 4 [The Myth of the Eagle’s Talon]
Subtask 5 [The Myth of the Fox]
For each subtask, you must take the layout of Canadia as input and determine whether the myth might be correct.
Subtasks are worth 5 marks each.
The first line contains a single integer
In subtask 3, you may assume that the sum of
The same condition holds for
For each test case, output a single line containing the string
YES
or the string NO
.
1
2
4 5
1 2
2 3
3 4
1 3
2 4
7 8
1 2
2 3
3 4
4 1
4 5
5 6
6 7
7 4
YES
NO
Test Case Number | Network | Explanation |
---|---|---|
1 | matches The Myth of the Flask | |
2 | cannot match The Myth of the Flask |
2
2
2 1
1 2
5 6
1 3
5 1
2 3
4 5
1 2
3 5
NO
YES
Test Case Number | Network | Explanation |
---|---|---|
1 | cannot match The Myth of the Moon | |
2 | matches The Myth of the Moon, since we can add cities 4 and 5 along with some extra roads to the Moon formed by cities 1, 2 and 3. |
3
2
7 8
1 2
2 3
3 4
4 1
4 5
5 6
6 7
7 4
8 8
1 2
2 3
3 4
4 5
5 6
6 1
7 3
8 7
YES
YES
Test Case Number | Network | Explanation |
---|---|---|
1 | can match The Myth of the Sun, on cities 1, 2, 3 and 4 | |
2 | can match The Myth of the Sun, on cities 1, 2, 3 and 4 where some new cities have been inserted between cities 1 and 4 |
4
2
4 4
1 2
2 3
3 4
4 1
6 6
1 2
2 3
1 4
4 5
2 4
1 6
NO
YES
Test Case Number | Network | Explanation |
---|---|---|
1 | cannot match The Myth of the Talon | |
2 | can match The Myth of the Talon on cities 1, 2, 4 and 6 |
5
2
5 5
1 2
2 3
2 4
4 5
3 5
6 6
1 2
2 3
1 4
4 5
2 4
1 6
NO
YES
Test Case Number | Network | Explanation |
---|---|---|
1 | cannot match The Myth of the Fox | |
2 | can match The Myth of the Fox, on cities 1, 2, 4, 5 and 6 |
Time Limit: 1 second
In this problem, a grid is an
Some grids are similar to other grids. Grid
You are given
The first line of input contains R
or
W
, indicating the colour (red or white) for
that element in the grid. Moreover, after the first two lines of input,
the next
For 12 out of the 25 marks available for this question,
Output the number of pairs of grids which are similar.
2
2
RW
WR
WR
RW
1
There are exactly two grids, and they are similar because the first grid can be transformed into the second grid using one change (selecting the 2-by-2 square consisting of the entire grid).
Time Limit: 2 seconds
Your country has a problem with zombies. That is, it has zombies, which are a problem. Thankfully, you are gainfully employed at the Forsenic Institute for Zoology and Zombie Emerging Studies (FIZZES), and your job is simply to give a measure of how bad the problem is.
You have mapped out your country on an an
You have the exact locations of all the zombies, and know that no two zombies are in the same location. The cells containing a zombie are marked with 0. Next, all the unmarked cells touching a cell (where touching a cell means touching on any side or corner of a cell; so each cell touches up to 8 other cells) marked with 0 are marked with 1. Then, all the unmarked cells touching a cell marked with 1 are marked with 2. This process continues until all the cells are marked. These numbers indicate the level of concern your office has about the spread of zombies.
A small example is shown below.
2 2 1 1 1 2
2 1 1 0 1 2
2 1 0 1 1 2
2 1 1 1 2 2
2 2 2 2 2 3
Your boss has given you an integer
The first line of input will contain two space-separated integers
For 5 of the 25 marks available,
For an additional 5 of the 25 marks available,
For an additional 5 of the 25 marks available,
Output the number of cells in the grid that are marked with the
integer
5 6
2
3 3
2 4
2
15
The sample input is the example shown above, which has 15
Time Limit: 10 seconds
A group of
The oldest pirate proposes a distribution. (You can assume that all
the pirates’ ages are distinct.) A distribution assigns an non-negative
integer number of coins to each pirate such that the sum of these
numbers equals
Then, each pirate will vote either ‘yes’ or ‘no’ on the proposal. The
number of ‘yes’ votes required for the proposal to pass depends on the
number of pirates. If there are
The pirates act according to the following rules. The rules are given in order of priority; for example, rule 2 is only applied to distinguish between multiple options that are optimal according to rule 1.
A pirate will act to prevent himself from being thrown overboard.
A pirate will act to maximize the number of coins he receives.
A pirate will act to maximize the number of pirates thrown overboard (excepting himself, because rule 1 takes priority).
A pirate will act to maximize the number of coins received by the oldest pirate. If there are still multiple choices that fit these rules, he will maximize the gold received by the second-oldest pirate, then the third-oldest pirate, etc.
If there are multiple options that are optimal according to these rules, then the pirate chooses an action arbitrarily. (You can assume that the answer to this problem does not depend on the pirate’s choice in this case.) Additionally, all the pirates are perfectly logical and know all the information contained in this problem statement. They cannot form agreements or coalitions because they do not trust each other.
We will number the pirates from
If there were only
The first line of input will be the number
The second line of input will be the integer
The next
For 5 of the 25 available marks for this problem
For an additional 5 of the 25 available marks for this problem
For an additional 5 of the 25 available marks for this problem
The output should consist of
5
100
1
1
2
2
3
100
100
99
99
98
If there are 2 pirates left, pirate 2 can propose that all of the gold coins go to him. Only 1 vote is required for this proposal to pass, so he can guarantee that it passes by voting for it.
If there are 3 pirates left, pirate 3 needs someone else to vote for his proposal. He can ensure this by giving 1 coin to pirate 1 and 99 to himself. Pirate 1 knows that if the proposal doesn’t pass, he will receive nothing. So a single coin is enough to secure his vote.
If there are 4 pirates left, pirate 4 gives 1 gold coin to pirate 2 and 99 to himself.
If there are 5 pirates left, pirate 5 gives 1 gold coin to pirates 1 and 3 and keeps 98 coins for himself.
5
100
1
2
3
4
4
100
-1
-1
-1
100
In this case, a full consensus is required for a proposal to pass, except when there are 5 pirates, in which case only 4 of the 5 votes are required.
If there is full consensus required, and there are 2 or more pirates, the youngest pirate will vote against the proposal to maximize their coins and also throw the most pirates overboard.
In the case where there are 5 pirates, the oldest pirate will propose to give himself 100 coins. Everyone except the youngest pirate will vote ’yes’, because if this proposal doesn’t pass, the youngest pirate will get all of them thrown overboard and then take the coins for himself when only he remains. Since the pirates don’t want to be thrown overboard, they will vote ’yes’, even though the oldest pirate will offer them nothing.
4
100
1
1
2
3
100
100
99
97
The first three cases were explained in Sample Input 1.
When there are 4 pirates, the oldest pirate needs 3 votes. He will give 2 coins to the youngest pirate and 1 coin to the second-youngest pirate, keeping the rest for himself.
4
2
1
1
2
3
2
2
1
-1
The situation is the same as in Example 3, but now there are only 2 coins. With 1, 2 or 3 pirates, we have the same situations as in Example 3.
With 4 pirates, the oldest pirate does not have enough coins to ensure the 3 votes which he needs, so he will be thrown overboard.