2015 German Collegiate Programming Contest GCPC 15 en
2015 German Collegiate Programming Contest GCPC 15 en
2015 German Collegiate Programming Contest GCPC 15 en
Problems
A A Journey to Greece
B Bounty Hunter II
C Cake
D Carpets
E Change of Scenery
F Divisions
G Extreme Sort
H Legacy Code
I Milling machines
J Souvenirs
K Upside down primes
Sponsored by
This page is intentionally left (almost) blank.
Problem A: A Journey to Greece
For a long time Tim wanted to visit Greece. He has already purchased his flight to and from
Athens. Tim has a list of historical sites he wants to visit, e.g., Olympia and Delphi. However,
due to recent political events in Greece, the public transport has gotten a little complicated. To
make the Greek happy and content with their new government, many short-range bus and train
lines have been created. They shall take the citizens around in their neighborhoods, to work or
to their doctor. At the same time, long-range trains that are perfect for tourists have been closed
down as they are too expensive. This is bad for people like Tim, who really likes to travel by
train. Moreover, he has already purchased the Greece’ Card for Public Conveyance (GCPC)
making all trains and buses free for him.
taxi 5
stay 2
3
4 2
1 2 6 3
2 10
stay 2 5 3 1 stay 2
5 2
2
0 Athens
Figure A.1: Visual representation of the Sample Input: Tim’s tour has length 18.
Despite his preferred railway lines being closed down, he still wants to make his travel trough
Greece. But taking all these local bus and train connections is slower than expected, so he wants
to know whether he can still visit all his favorite sites in the timeframe given by his flights. He
knows his schedule will be tight, but he has some emergency money to buy a single ticket for a
special Greek taxi service. It promises to bring you from any point in Greece to any other in a
certain amount of time.
For simplicity we assume, that Tim does never have to wait for the next bus or train at a station.
Tell Tim, whether he can still visit all sites and if so, whether he needs to use this taxi ticket.
Input
The first line contains five integers N , P , M , G and T , where N denotes the number of places
in Greece, P the number of sites Tim wants to visit, M the number of connections, G the total
amount of time Tim can spend in Greece, and T the time the taxi ride takes (1 ≤ N ≤ 2 · 104 ;
1 ≤ P ≤ 15; 1 ≤ M, G ≤ 105 ; 1 ≤ T ≤ 500).
Then follow P lines, each with two integers pi and ti , specifying the places Tim wants to visit
and the time Tim spends at each site (0 ≤ pi < N ; 1 ≤ ti ≤ 500). The sites pi are distinct from
each other.
Then follow M lines, each describing one connection by three integers si , di and ti , where si
and di specify the start and destination of the connection and ti the amount of time it takes
(0 ≤ si , di < N ; 1 ≤ ti ≤ 500).
All connections are bi-directional. Tim’s journey starts and ends in Athens, which is always the
place 0.
0 4
0 1 2 1 2 5
3 3
Input
The input begins with an integer N specifying the number of planets (0 < N ≤ 1000). The
planets are numbered from 0 to N −1. The following N lines specify the hyperspace connections.
The i-th of those lines first contains the count of connections K (0 ≤ K ≤ N − 1) from planet i
followed by K integers specifying the destination planets.
Output
Output the minimum number of persons needed to visit every planet.
3 1
4 4
1
4
3
4
Sophie does not want to cut more from the cake than necessary for obvious reasons. Can you
tell her how to choose s?
Input
The first line contains a floating point number a and an integer N , where a denotes the ratio of
the cake’s weight allowed by the carrier and N the number of vertices of the cake (0.25 ≤ a < 1;
3 ≤ N ≤ 100). a will be specified with at most 7 digits after the decimal point.
Then follow N lines, each describing one of the cake’s vertices with two integers xi and yi , the
coordinates of the vertex (0 ≤ xi , yi ≤ 108 for all 1 ≤ i ≤ N ). The vertices are given in the
order in which they form a strictly convex shape.
You may safely assume that the weight is uniformly distributed over the area of the cake.
Furthermore, it will always be possible to cut the cake with some 2 ≤ s ≤ 1000 such that the
proportion of the remaining cake is a of the original weight.
Output
Print a line containing s, the biggest value as specified above such that the remaining cake’s
weight is at most the proportion a of its original weight.
Your answer will be considered correct if the absolute error is at most 10−4 .
But when checking the supermarket’s stock he begins to wonder whether he can accomplish his
plan at all. Can you help him?
Input
The first line contains two integers W and H describing the size of his room (1 ≤ W, H ≤ 100).
The second line contains an integer c, denoting the number of different carpet colors the
supermarket has in stock (1 ≤ c ≤ 7).
Each of the following c lines consists of three integers ai , wi , and hi , which means: the
supermarket’s stock contains ai carpets of size wi , hi and color i (1 ≤ ai ≤ 7; 1 ≤ wi ≤ 100;
1 ≤ hi ≤ 100). P
The supermarket has at most 7 carpets, i.e. i ai ≤ 7.
Output
For the given room dimensions and the supermarket’s stock of carpets, print “yes” if it is
possible to cover the room with carpets as specified above and “no” otherwise.
Input
The first line of the input starts with three integers N M and K, where N is the number of
junctions and M is the number of streets in your city, and K is the number of junctions you pass
every day (1 ≤ K ≤ N ≤ 10 000, 0 ≤ M ≤ 1 000 000).
The next line contains K integers, the (1-based) indices of the junctions you pass every day. The
first integer in this line will always be 1, the last integer will always be N . There is a shortest
path from 1 to N along the K junctions given.
M lines follow. The i-th of those lines contains three integers ai bi ci and describes a street from
junction ai to junction bi of length ci (1 ≤ ai , bi ≤ N , 1 ≤ ci ≤ 10 000). Streets are always
undirected.
Note that there may be multiple streets connecting the same pair of junctions. The shortest path
given uses for every pair of successive junctions a and b a street of minimal length between a
and b.
Output
Print one line of output containing “yes” if there is another way you can take without losing
time, “no” otherwise.
The parents of David are very careful and they would like to ensure that David experiences
enough happiness. Therefore they decide which number David will use as the dividend for this
day.
There is still a problem: The parents are not very good at math and don’t know how to calculate
the number of positive integral divisors for a given dividend N , which lead to an integral result.
Now it’s up to you to help David’s parents.
Input
The single input line contains the single integer N , where N is chosen as a dividend (1 ≤ N ≤
1018 ).
Output
Print the number of positive integral divisors of N that lead to an integral result of the division.
Well, enough about the past. Today John is playing with sorting algorithms again. This time it’s
numbers. He has an idea for a new algorithm, “extreme sort”. It’s extremely fast, performance
levels are OVER NINETHOUSAND. Before he tells anyone any details, he wants to make sure
that it works correctly.
Your task is to help him and verify that the so-called extreme property holds after the first phase
of the algorithm. The extreme property is defined as min (xi,j ) ≥ 0, where
(
aj − ai for 1 ≤ i < j ≤ N
xi,j =
9001 otherwise
Input
The first line contains a single integer N (1 ≤ N ≤ 1024). The second line contains N integers
a1 a2 . . . aN (1 ≤ ai ≤ 1024).
Output
Print one line of output containing “yes” if the extreme property holds for the given input, “no”
otherwise.
Sample Input 1 Sample Output 1
2 yes
1 2
Input
The first line of the input contains an integer N , the number of methods in your software
(1 ≤ N ≤ 400).
Each method is described by two lines, totaling in 2 · N lines. The first line consists of the unique
identifier of the method and ki , the number of methods directly invoking this one (0 ≤ ki ≤ N ).
The second line consists of a set of ki identifiers of these calling methods or is empty if there are
no such methods, i.e. ki = 0.
Method identifiers consist of a package name followed by two colons and a method name
like Packagename::Methodname. Both strings, the package and the method name, each
consist of up to 20 lowercase, uppercase characters or digits (a-z, A-Z, 0-9).
There will be exactly N different method identifiers mentioned in the input.
Output
A line containing the number of unused methods in your software.
HelpPackage::HelpFunction 2
HelpPackage::HelpFunction SuperGame::PROGRAM
Input
The first line consists of two integers W and S, where W gives the number of workpieces and
S the number of steps in the milling program (1 ≤ W, S ≤ 104 ). The next line consists of
two integers X and Y , where X gives the width and Y gives the maximal possible height of
workpieces (1 ≤ X, Y ≤ 100).
Then follow W lines, each describing one workpiece. Each workpiece description consists of X
non-negative integers specifying the surface height in that column.
Then follow S lines, each describing one milling step of the milling progam. Each milling
step description consists of X non-negative integers si (0 ≤ si ≤ Y ) specifying the amount of
surface to cut off in each column (relative to the height of the milling area, i.e. Y , not relative to
the top of the workpiece). See Fig. I.1 for details.
Output
For each workpiece, output one line containing X integers specifying the remaining surface
heights (in the same order as in the input).
Figure I.1: Second workpiece in first sample: initial workpiece followed by milling in each
column – the value in the milling program determines the vertical position of the cutter head.
Input
The first line contains three integers g, c, and n, where g denotes the value of one gold coin in
silver coins, c denotes the number of gold coins you have and n the number of merchants on the
market (1 < g ≤ 100, 1 ≤ c, n ≤ 100).
Then follow n lines each describing one merchant. Each of these lines starts with a string
“greedy”, “honest” or “generous” describing the rounding habit of the merchant. The
string is followed by two integers pi and si , where pi denotes the package size of silver coins
the merchant uses and si specifies the prices of the souvenir at that merchant in silver coins
(1 ≤ pi ≤ g, 1 ≤ si < g).
Output
One line containing the maximal number of souvenirs you can buy.
Figure K.1: Prime number 18115211 on a seven segment display (see third sample).
Figure K.2: 18115211 turned upside down (i.e. rotated by 180 degrees) gives 11251181, which
is not prime.
Input
One line with the integer N in question (1 ≤ N ≤ 1016 ). N will not have leading zeros.
Output
Print one line of output containing “yes” if the number is a prime and still a prime if turned
upside down, “no” otherwise.
Problem L. Treasure
Input file: standard input
Output file: standard output
King Byteasar had hidden a treasure in his castle, and he kept his hiding place in secret. However,
whenever he went to war he was afraid he could die and the treasure would get lost. Therefore he chose
trustworthy guards and confided partial information needed to find the treasure to each of them. Next
he ordered them to go to the underground vaults that lie under the castle and to walk there using the
right-hand rule. The vaults were connected by corridors. The corridors did not cross outside the vaults
but they could run under other corridors. There were no corridors leading to the same vault they led off.
The right-hand rule stated that a guard after entering a vault left it by the next corridor to the right.
The guards were appointed different starting positions at entrances to corridors. It might happen that
many guards started from the same vault, unless they were entering the same corridor.
The king knew that until he fell or returned from war all guards would loyally follow his orders. However,
he was aware that whenever any two or more guards met in some vault they could not resist sharing all
the information they knew about the treasure. The guards were not selfish and they shared information
even if some of them would not learnt anything new. If some guards started from the same vault they
immediately shared the information they initially knew. If they passed one another in corridors, however,
they did not talk.
The king pondered if the treasure would still be secure when he safely returned from war. He wanted to
know which guards might obtain all the information needed to find the treasure.
Write a program which:
• reads from the standard input the description of the castle basement, the starting positions of the
guards and information each of the guards initially knows,
• determines the guards who could ever know all the information needed to find the treasure,
Input
In the first line of the standard input there is one integer n. That is the number of the underground
vaults, 2 ≤ n ≤ 100. The vaults are numbered from 1 to n. In the following n lines corridors connecting
the vaults are described. In the (i + 1)-st line the corridors leading off the i-th vault are described in
clockwise order. In each of those lines there are integers separated by single spaces. The first of those
numbers, ki , is the number of corridors leading off the i-th vault, 1 ≤ ki ≤ n − 1. It is followed, in
the same line, by 2ki integers: each leading off corridor is described by two integers. The former is the
number of the vault the corridor leads to, and the latter is the length of the corridor: an integer in the
range from 1 to 100. The corridors are two-way, i.e. if from a vault a a corridor of length l leads to
a vault b then from the vault b a corridor of length l leads to the vault a. Each pair of vaults may be
connected by at most one corridor. A guard to walk along a corridor needs exactly the amount of time
that is equal to the length of that corridor. We assume the time guards spend in vaults negligible.
In the (n + 2)-nd line there are written two integers k and l, 1 ≤ k, l ≤ 100, where k is the number
of guards, and l is the number of pieces of information needed to find the treasure. The guards are
numbered from 1 to k. The pieces of information concerning the treasure are numbered from 1 to l. The
guards are described in the following k lines (the i-th guard is described in the (i + n + 2)-nd line). Each
of those lines consists of integers separated by single spaces. The first integer in a line is the number of
the vault the corresponding guard starts from. The second number is the number of the vault the guard
goes to first. The third number, mi , is the number of pieces of information concerning the treasure the
i-th guard initially knows, 0 ≤ mi ≤ l. The following mi integers in the line are the numbers of the pieces
of information initially known to the i-th guard.
Page 23 of 25
2015 German Collegiate Programming Contest (GCPC 15) + Poland Problems
Output
In the first line of the standard output your program should write one integer: the number of guards
who could ever know all the information needed to find the treasure. In the following lines there should
be written the numbers of those guards in ascending order, one number per line.
Page 24 of 25
2015 German Collegiate Programming Contest (GCPC 15) + Poland Problems
Problem M. Sums
Input file: standard input
Output file: standard output
We are given a set of positive integers A. Consider a set of non-negative integers A′ , such that a number
x belongs to A if and only if x is a sum of some elements from A (the elements may be repeated). For
example, if A = {2, 5, 7}, then sample numbers belonging to the set A′ are: 0 (the sum of 0 elements), 2,
4 (2 + 2) and 12(5 + 7 or 7 + 5 or 2 + 2 + 2 + 2 + 2 + 2); and the following do not belong to A′ : 1 and 3.
Write a program which:
• reads from the standard input the description of the set A and the sequence of numbers bi ,
Input
In the first line there is one integer n: the number of elements of the set A, 1 ≤ n ≤ 50000. The following
n lines contain the elements of the set A, one per line. In the (i + 1)-st line there is one positive integer
ai , 1 ≤ ai ≤ 50000. A = {a1 , a2 , . . . , an }, a1 < a2 < · · · < an .
In the (n + 2)-nd line there is one integer k, 1 ≤ k ≤ 10000. Each of the following k lines contains one
integer in the range from 0 to 109 , they are respectively the numbers bi .
Output
The output should consist of k lines. The i-th line should contain the word TAK (“yes” in Polish), if bi
belongs to A′ , and it should contain the word NIE (“no”) otherwise.
Page 25 of 25