2020 Canadian Computing Olympiad
Day 1, Problem 1: A Game with Grundy
Time Limit: 1 second
Problem Description
Grundy is playing his favourite game - hide and seek.
His friends stand at locations
on the -axis of a two-dimensional
plane - the -th one is at
coordinates . Each friend
can see things in a triangular wedge extending vertically upwards from
their position – the -th friend’s
triangular wedge of vision will be specified by two lines: one with
slope of and
the other with slope . A friend cannot see
a point that lies exactly on one of these two lines.
Grundy may choose to hide at any location , where is an integer satisfying , and , , and are given integer constants.
Each possible location may be in view of some of Grundy’s friends
(namely, strictly within their triangular wedge of vision).
Grundy would like to know in how many different spots he can stand
such that he will be in view of at most i of his friends, for every
possible value of from to .
The first line of input contains the integer .
The next line contains three integers: ,
and .
Each of the next lines contain
three integers: the -th such line
contains , the -value of the position of friend followed by two integers and . The slopes and define the
triangular wedge of vision for friend .
For of the marks available, .
Output
Specification
The output is lines, where
each line () contains the integer
number of positions in which Grundy can stand and be in view of at most
of his friends.
3
-7 7 3
0 2 3
-4 2 1
3 3 1
5
12
15
15
There are three friends with the following triangular wedges of
vision, along with the possible positions that Grundy can be placed, as shown in the diagram below:
Notice the points and
are visible only by the
friend at position , since they
lie on the boundary of the triangular wedge of vision for the friend at
position .
Day 1, Problem 2: Exercise Deadlines
Time Limit: 1 second
Problem
Description
Bob has programming exercises
that he needs to complete before their deadlines. Exercise only takes one time unit to complete,
but has a deadline () time units from
now.
Bob will solve the exercises in an order described by a sequence
, such that
is the first exercise he
solves, is the second exercise
he solves, and so on. Bob’s original plan is described by the sequence
. With one swap
operation, Bob can exchange two adjacent numbers in this sequence. What
is the minimum number of swaps required to change this sequence into one
that completes all exercises on time?
The first line consists of a single integer . The next line contains space-separated integers (). For of the marks available, .
Output
Specification
Output a single integer, the minimum number of swaps required for Bob
to solve all exercises on time, or -1
if this is
impossible.
4
4 4 3 2
3
One valid sequence is , which can be obtained from by three swaps.
3
1 1 3
-1
There are two exercises that are due at time 1
, but only
one exercise can be solved by this time.
Day 1,
Problem 3: Mountains and Valleys
Time Limit: 7 seconds
Problem Description
You are planning a long hiking trip through some interesting, but well-known terrain. There are interesting sites you would like to visit and trails connecting pairs of sites. Each trail has a difficulty level indicated as a positive integer.
The trail system is a bit special, however. There are exactly trails with difficulty level (these are completely flat trails), and
the rest of the trails all have a difficulty level of at least (these are very
mountainous trails). (The ceiling of , denoted as , is the smallest integer
greater than or equal to .)
Additionally, it is possible to travel between any two sites using
only the trails with difficulty level .
You would like to visit every site, starting your walk from any site
of your choice and finishing at some other site, such that you visit
each site at least once and the total sum of difficulty levels is
minimum among all walks. Note that walking a trail times with difficulty level contributes a value of to the sum of difficulty
levels.
The first line of input contains two space-separated integers and .
The next lines contain three
space-separated integers , , and describing the trail between sites
and with difficulty level . Note
that there is at most one trail between every pair of sites, and that
or .
For of the marks available, and .
For an additional of the marks available, and .
For an additional of the marks available, , , and either or .
For an additional of the marks available, and .
For an additional of the marks available, and .
For an additional of the marks available, and .
For an additional of the marks available, and .
Output
Specification
Output one integer, which is the minimum sum of difficulty levels taken for all trails walked to visit each site at least once.
9 10
0 1 1
0 2 1
0 3 1
1 4 1
2 5 1
2 6 1
3 7 1
3 8 1
2 4 5
6 7 3
11
This is the set of flat trails:
This is the entire set of trails with all the difficulty levels.
This is the entire set of trails, with trails with difficulty level 1
being omitted.
An optimal walk for this set of trails is with a total cost of .
There is no way to make a walk that visits all the sites at least once
with a lower total difficulty level cost.
Day 2, Problem 1: Travelling Salesperson
Time Limit: 7 seconds
Problem
Description
In the city of RedBlue, every pair of buildings is connected by a
road, either red or blue. To switch from travelling along red roads to
blue roads or vice versa costs one ticket. The length of a route is the
number of buildings that are visited. For example, the following route
has a length of five and costs one ticket.
If we wanted to travel on a blue road again after visiting vertex 3
for the second time, we would need another ticket, for a total of two
tickets:
You are a travelling salesperson visiting the city of RedBlue, and
you wish to visit each building at least once, while minimizing repeated
visits of the same buildings. You have not yet decided which building
you are starting your route from, so you would like to plan out all
possible routes. Furthermore, you only have access to one ticket. For
each building, you would like to find a route of minimum length that
begins at that building, visits all the buildings at least once, and
uses at most one ticket.
The first line will contain a single integer , the number of buildings in RedBlue.
Lines to each contain a string, with line containing the string , representing the colours of the
roads connected to building i. The string has
a length of and consists only
of the characters R
and B
. If is R
, then the road
between buildings and is red. Otherwise, it is blue.
Output
Specification
Output lines. Lines for should contain a single
integer , representing the
length of the travel plan starting at building . Lines for should each contain space separated integers, describing
the order in which you visit the buildings, starting at building .
Scoring
For every one of your travel plans, a score is computed. Let be the length of the optimal route
starting at each building, and let be the length of your route. If is greater than , then your score will be , and you will receive a verdict of
Wrong Answer. If is equal to
, then your score will be . Otherwise you will a receive a score
of . Your score for the test
case is the minimum score for each travel plan.
If any of your plans are invalid, your score will be , and you will receive a verdict of
Wrong Answer.
Your submission’s score is the minimum score over all test cases.
4
R
RR
BRB
5
1 4 2 1 3
6
2 3 1 2 3 4
5
3 1 2 3 4
4
4 3 1 2
RedBlue looks like this:
The route starting from building has an optimal length of by visiting the buildings in the order
, , , . The solution’s route has a length of
, meaning the score is equal to
Day 2, Problem 2: Interval Collection
Time Limit: 3.5 seconds
Problem
Description
Altina is starting an interval collection. An interval is defined as
two positive integers such
that . We say that the
length of this interval is .
Additionally, we say that an interval contains another interval if and . In particular, each interval
contains itself.
For a non-empty set S of intervals, we define the set of common
intervals as all the intervals [x, y] that are contained within every
interval [l, r] in S. If the set of common intervals is non-empty, then
we say the greatest common interval of S is equal to the common interval
with the largest length.
For the same set S, we define the set of enclosing intervals as all
the intervals [x, y] that contain every interval [l,r] in S. Note that
this set is always non-empty, so we say the least enclosing interval of
S is equal to the enclosing interval with the smallest length.
Initially, Altina owns no intervals in her collection. There are Q
events that change the set of intervals she owns.
The first type of event is when Altina adds an interval [l, r] to her
collection. Note that this interval could have the same [l, r] as
another interval in her collection. They should be treated as separate
intervals.
The second type of event is when Altina removes an existing interval
[l, r] from her collection. Note that if Altina has more than one
interval with the same [l, r], she removes exactly one of them.
After each event, Altina chooses a non-empty subset S of intervals
she owns in her collection that satisfy the following conditions:
Among all sets Altina
could choose, she chooses one that has no greatest
common interval, if possible. If this is impossible, then she chooses
one which has the length of its greatest common interval as small as
possible.
Among all sets that
satisfy the previous condition, she chooses one which has the length of
its least enclosing interval as small as possible.
Your task is to determine the length of the least enclosing interval
of the set Altina chose after
each event.
The first line of input contains , the number of add and remove operations in
total. The next Q lines are in one of the following forms:
A
: add the interval to Altina’s collection.
R
: remove one of the instances of the
interval from Altina’s
collection. It is guaranteed the interval to be removed exists and that
the collection will be non-empty after the interval is removed.
For all subtasks, .
For of the marks available, .
For an additional of the marks available, .
For an additional of the marks available, .
For an additional of the marks available, the following
condition holds after each event: for every two separate intervals and in Altina’s collection, either
or .
Output
Specification
The output consists of lines,
each line containing the length of the least enclosing interval for
Altina’s choice of as described
in the problem description.
5
A 1 5
A 2 7
A 4 6
A 6 8
R 4 6
4
6
5
4
7
After the interval is added, there is only one interval, so is the only valid choice and the least enclosing interval is .
After the interval is added, has the greatest common interval and least enclosing interval .
After the interval is added, has the greatest common interval and least enclosing interval .
After the interval is added, has no
greatest common interval and least enclosing interval . Note that also has no greatest
common interval but its least enclosing interval has a greater length than .
After the interval is
removed, has
no greatest common interval and least enclosing interval .
Day 2, Problem 3: Shopping Plans
Time Limit: 2 seconds
Problem
Description
You are shopping from a store that sells a total of items. The -th item has a type which is an integer between and . A feasible shopping plan is a subset
of these items such that for all types , the number of items of type is in the interval .
The -th item in the store has a
cost of , and the cost of a
shopping plan is the sum of the costs of items in the plan. You are
interested in the possible costs of feasible shopping plans. Find the
costs of the cheapest feasible
shopping plans. Note that if there are two different shopping plans with
the same cost, they should be counted separately in the output.
The first line consists of three space-separated integers , , and .
lines follow, the -th of which
contains two space-separated integers and . lines follow, the -th of which contains two
space-separated integers and
.
For of the marks available, and .
For an additional of the marks available, and .
For an additional of the marks available, .
For an additional of the marks available, .
Output
Specification
Output lines. On the -th line, output the cost of the -th cheapest feasible shopping plan, if
one exists, or -1
if there are fewer than feasible shopping plans.
5 2 7
1 5
1 3
2 3
1 6
2 1
1 1
1 1
4
6
6
7
8
9
-1
A feasible shopping plan must combine exactly one item with a cost in with exactly one item with a cost in .