0% found this document useful (0 votes)
83 views

Acm Icpc2015 Finalround

The document describes the ACM-ICPC 2015-2016 Team Selection Final Round competition to be held at Ho Chi Minh City University of Science on October 11, 2015, consisting of 10 problems in 13 pages for the 5 hour contest, with Problem A describing a banquet planning problem for minions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

Acm Icpc2015 Finalround

The document describes the ACM-ICPC 2015-2016 Team Selection Final Round competition to be held at Ho Chi Minh City University of Science on October 11, 2015, consisting of 10 problems in 13 pages for the 5 hour contest, with Problem A describing a banquet planning problem for minions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

ACM-ICPC 2015-2016

Ho Chi Minh City University of Science


Team Selection Final Round
HCMUS, October 11, 2015

Contest length: 5 hours


The problem set consists of 10 problems in 13 pages (excluding the cover page):

Problem A: Freshmen Banquet

Problem B: Skiing Map

Problem C: Cups and Balls

Problem D: Save My Brother

Problem E: Wizard-of-Ozs Spells

Problem F: Baymax Insider Expo

Problem G: Anywhere Door 2.0

Problem H: WICKED Is Good?

Problem I: Coming Home

Problem J: When a Fighter Has to Think

ACM ICPC 2015-2016, Ho Chi Minh City University of Science Training Camp
Team Selection Final Round, HCMUS October 11, 2015

Problem A. Freshmen Banquet


Input le:
Output le:
Time limit:
Memory limit:

stdin
stdout
1 second
512 megabytes

Today is the back-to-school day of Minions! Traditionally, Dr. Nefario


will open a banquet to welcome freshmen. N minions are invited and
numbered by 1, 2, . . . , N . Chocolate and vanilla gelatos are served at
the banquet. Each minion has his own preference, he may eat only
chocolate or only vanilla gelato or accept both.
There are P pairs of minions who dislike each other. They will ght
when they are serving the same type of gelato. Fortunately, these P
pairs are so particular that minions can always be divided into 2 groups
such that no two minions in the same group dislike each other.
Minions love bananas. If the i-th minion can be served gi bananas
instead of gelatos, he will not ght with others anymore. As banana is much more expensive than gelato,
Dr. Nefario has to decide how to serve the banquet with minimum total bananas while still possible to
avoid ghts.

Input
The input consists of multiple (at most 5) test cases. For each test case:
The rst line contains 2 integers N , P (1 N 1000, 0 P 104 ).
The second line contains N integers g1 , g2 , . . . , gN (1 gi 106 ).
The third line contains N integers q1 , q2 , . . . , qN (1 qi 3): qi = 1 means the i-th minion eats
only chocolate gelato; qi = 2 means he eats only vanilla one; and qi = 3 means he accepts both.
Each of the following P lines contains 2 integers ai , bi , which denotes minion numbered ai and bi dislike
each other (1 ai , bi N ).

Output
For each test case, print one integer which denotes the minimum total bananas served.

Example
stdin
2 1
10 10
2 2
1 2
3 2
3 3 2
2 1 3
1 3
2 3
3 0
1 1 1
3 3 3

stdout
10
2
0

Page 1 of 13

ACM ICPC 2015-2016, Ho Chi Minh City University of Science Training Camp
Team Selection Final Round, HCMUS October 11, 2015

Problem B. Skiing Map


Input le:
Output le:
Time limit:
Memory limit:

stdin
stdout
1 second
512 megabytes

Elsa the queen of Arendelle wants to create a winter wonderland to play


with her sister Anna, even in summer time! With her unique ability to create
and control ice and snow, she plans to design skiing trails of great gliding
challenges.
Let consider the area where Elsa locates her wonderland as a 2D plane, and
P1 (x1 , y1 ), P2 (x2 , y2 ), . . ., PN (xN , yN ) be a sequence of N dierent points
in the plane with nonnegative integer coordinates. She supposes that a skiing trail is challenging if in this sequence, for any two points Pi (xi , yi ) and
Pi+1 (xi+1 , yi+1 ) (for 1 i < N ), it is justied that xi xi+1 and yi yi+1 .
For example, the sequence of points P1 (0, 5), P2 (0, 4), P3 (1, 3), P4 (2, 3), P5 (3, 0) forms a great gliding
challenge.
Elsa has found a dozen of such challenging trails, and it seems there are many more. With limited time
left for preparation, Elsa ought to set some constraints for the trails. To give her a hand, can you tell
her number of challenging sequences of points for which all of these equations are justied: x1 + y1 = w1 ,
x2 + y2 = w2 , . . ., xN + yN = wN ?

Input
The positive integer N (1 N 104 ) is given on the rst line of the standard input. There are N
nonnegative integers on the second line w1 , w2 , . . . , wN separated by a single space (0 wi 104 for
1 i N and wi = wi+1 for 1 i < N ).

Output
On a line of the standard output, print by modulo 20151011 the number of satised sequences.

Example
stdin
2
3 1

stdout
3

Explanation: There are 3 decreasing sequences:


(0, 3), (0, 1)
(0, 3), (1, 0)
(1, 2), (1, 0)

Page 2 of 13

ACM ICPC 2015-2016, Ho Chi Minh City University of Science Training Camp
Team Selection Final Round, HCMUS October 11, 2015

Problem C. Cups and Balls


Input le:
Output le:
Time limit:
Memory limit:

stdin
stdout
1 second
512 megabytes

Cups and Balls is a classic performance of magic, with various adaptations around the world. The most
widely performed version is:
There are 3 identical cups set down in a line on a table. Initally, a ball is concealed under the
middle cup. The magician will quickly and magically swap the cups for a number of times.
After that, the audience will guess where the ball is.
Here is the Minions version: There are N identical cups set down in a
line on a table. Under each cup is a ball labelled with a natural number
in range [1, N ]. These N numbers are distinct; and initially the cups
are arranged from the left-hand side to the right-hand side such that
the numbers form an ascending sequence.
The magician will perform T turns, which can be described as a triple
i j k:
First, reverse all cups from position i to position j in the line.
Then, the audience should tell the ball concealed under the cup
at position k is labelled with what number.
You are invited by Dave the smartest minion in town to play the audience role.

Input
The rst line of input contains 2 integers N , T (1 N 105 , 1 T 50 000). Next T lines, each
contains a triple i j k (1 i < j N , 1 k N ) as described above. Numbers on the same line are
separated by spaces.

Output
Print T lines, i-th line contains the corresponding answer for i-th turn in input.

Example
stdin
5
1
4
2

3
3 3
5 4
4 1

stdout
1
5
3

Explanation:
Initial sequence: 1 2 3 4 5
After the rst turn: 3 2 1 4 5
After the second turn: 3 2 1 5 4
After the third turn: 3 5 1 2 4
Page 3 of 13

ACM ICPC 2015-2016, Ho Chi Minh City University of Science Training Camp
Team Selection Final Round, HCMUS October 11, 2015

Problem D. Save My Brother


Input le:
Output le:
Time limit:
Memory limit:

stdin
stdout
1 second
512 megabytes

Hiro was very proud to demonstrate his microbots at the universitys


science fair. However, he soon faced a tragedy that his older brother
Tadashi was killed in the explosion in the university when he tried to
rescue Professor Callaghan.
In the last part of the movie, Baymax used his armors rocket st to
propel Hiro and Abigail out of the portal while it was left inside the
portals space. It was so sad!
However, a few months later, Hiro receives a special message sent by
Baymax inside the portals space. The message tells Hiro that both his
brother Tadashi and Baymax are now safe somewhere in the universe. To rescue them, Hiro should build
several Worm Tunnels to travel quickly in the universe. There are N possible Worm Tunnels. It takes ci
energy units to establish the ith tunnel. If Hiro builds the ith tunnel, for all points (x, y) in the universe
and a nonnegative number k, he can travel from (x, y) to (x + kai , y + kbi ).
Hiro is very enthusiastic to see his brother Tadashi and Baymax again. Therefore, he should compute
the minimum total energy units to establish Worm Tunnels so that he can travel between any two points
in the universe.

Input
First line of the input contains one integer N (1 N 2 105 ). Then N lines follow; ith of these lines
contains three integers ai , bi , ci (109 ai , bi 109 , 1 ci 109 ).

Output
Print the minimum total energy units Hiro should use to build Worm Tunnels in order to be able to move
between any two points in the universe. If this is impossible, print -1 instead.

Example
stdin
3
0 1 1
0 0 1
1 -1 2
5
10 2 5
0 1 20
1 0 11
0 -1 2
-1 0 3

stdout
-1

10

Page 4 of 13

ACM ICPC 2015-2016, Ho Chi Minh City University of Science Training Camp
Team Selection Final Round, HCMUS October 11, 2015

Problem E. Wizard-of-Ozs Spells


Input le:
Output le:
Time limit:
Memory limit:

stdin
stdout
1 second
512 megabytes

In the magic land of Oz, wizards are taught a list of spells since they were
young. The Oz spells are strings, which consist only of letters o and z.
Furthermore, for all Oz strings, the following property is true:
If we denote by nO the number of os and by nZ the number of zs in the
string, then for every substring of the Oz string, it should be true that
|nZ nO| 3 for this substring. For example, the string ozozzo is an Oz
string; while the string ozzzzzo is not an Oz string because it contains
the substring zzzzz and for this substring |nZ nO| = 5, which is greater
than 3.
If we sort the Oz strings by length and then lexicographically we will obtain a sorted list of the Oz strings.
The K th Oz string is the one that is in the K th position, starting from one, in this list. The rst 10
strings of this list are: {o, z, oo, oz, zo, zz, ooo, ooz, ozo, ozz, ...}. As the list is too long for a novice wizard
like Quinlan, can you help him to recall the K th Oz string?

Input
On the rst and only line of the standard input is a number K (1 K 1014 ) the position of the Oz
string that Quinlan wants to recall.

Output
On the rst and only line of the output, print the K th Oz string.

Example
stdin
8

stdout
ooz

Page 5 of 13

ACM ICPC 2015-2016, Ho Chi Minh City University of Science Training Camp
Team Selection Final Round, HCMUS October 11, 2015

Problem F. Baymax Insider Expo


Input le:
Output le:
Time limit:
Memory limit:

stdin
stdout
1 second
512 megabytes

In memory of his brilliant brother Tadashi the creator of Baymax, Hiro


organizes an annual Expo with healthcare robots as the central theme.
Learning from the experience of last Autumn Lantern Exhibition, Hiro
also displayed robots in several lines arranged by their heights. However,
as each kiosk at the Expo is too small, this plan did not hold. Hiro had
to gure out another way.
There are N robots to be displayed. Given that the heights of these
N robots are distinct integers with values in range [1, N ]. Hiro decided
to display all of them in a single line from the left-hand side to the
right-hand side, with a special arrangement that brought most attraction to visitors. Accidentally, few
hours before the opening day, his computer was crashed and all details about the arrangement were lost!
Now, the only way for Hiro to recover that arrangement is investigating some notes written by
his assistant. Assume that the arrangement can be denoted by a sequence of N robots heights
p(1), p(2), . . . , p(N ). An assistants note consists of Rmin + Rmax records in form (si , ei , hi ), which are
listed in below order:
For each of the rst Rmin records, (si , ei , hi ) means min{p(si ), p(si + 1), . . . , p(ei )} = hi ;
For each of next Rmax records, (si , ei , hi ) means max{p(si ), p(si + 1), . . . , p(ei )} = hi .
Please help Hiro to recover the nal arrangement from the records, or tell him that the records contain
contradictions. If there are more than one valid sequences, just show one with the smallest lexicographical
order.
A sequence p(1), p(2), . . . , p(N ) is lexicographically smaller than q(1), q(2), . . . , q(N ) if and only if there
exists 1 i N which p(i) < q(i) and for all 1 j < i, p(j) = q(j).

Input
The input consists of multiple notes (at most 5) that Hiro wants to investigate. For each note:
The rst line contains 3 integers N, Rmin , Rmax (1 n 50, 0 Rmin + Rmax 50).
Each of the following (Rmin +Rmax ) lines contains 3 integers si , ei , hi (1 si ei N , 1 hi N ).

Output
For each note, print N integers p(1), p(2), . . . , p(N ) separated by a single space, which denote the smallest
lexicographical sequence; or Impossible if records contain contradiction.

Page 6 of 13

ACM ICPC 2015-2016, Ho Chi Minh City University of Science Training Camp
Team Selection Final Round, HCMUS October 11, 2015

Example
stdin
8
3
3
3
1
2
1
2

1
5
5
2
3
3
3
3

1
2
2
2
1
1
3
3

stdout
Impossible
2 1 3

Page 7 of 13

ACM ICPC 2015-2016, Ho Chi Minh City University of Science Training Camp
Team Selection Final Round, HCMUS October 11, 2015

Problem G. Anywhere Door 2.0


Input le:
Output le:
Time limit:
Memory limit:

stdin
stdout
2 seconds
512 megabytes

Anywhere Door is one of the most famous gadgets of Doraemon. When you want
to go to somewhere, just tell the door, then open and go through it. The location
behind the door is your expected destination. This magic door, however, has
certain limitation. Namely, it cannot be used if it has been exposed to strong
electromagnetic waves like solar winds. Or the door has only one instance and is
always kept inside Doraemons pocket; thus there is no way for Nobita to use the
door when Doraemon is not beside him.
Being aware of such limitation, Doraemon is about to upgrade his door to the
next version. In version 2.0, the Anywhere Door is a portable and reective
device. Suppose that the Earth map can be modelled as a 2D plane, where places
are points with integer coordinates. The Anywhere Door device provides a list of
N actuators placed at N dierent coordinates (xi , yi ) (1 i N ). And it functions with the following
behavior: when one stays at (u, v) and decides to use the actuator at (xi , yi ), then he or she will be
magicially moved to a destination at (2xi u, 2yi v).
Doraemon is not so good at implementation, you are trusted to write a program to verify his device.
Herein, Nobita will give you a list of test cases, each of which is asked to check if there is a path from
his home at (xS , yS ) to a destination (e.g., Shizukas house) at (xE , yE ).
Good luck to Doraemon, and wish his device early released!

Input
The rst line contains one integer T (1 T 105 ) the number of test cases in the input. Description
of each test is as following:
Each test consists of N + 3 lines.
The rst line contains one integer N (1 N 105 ) - the number of actuators.
The following N +2 lines contain two integers x, y (103 x, y 103 ) coordinates of N actuators,
Nobitas home (xS , yS ) and someones house (xE , yE ) respectively.
It is guaranteed that the sum of N in all the tests does not exceed 105 .

Output
For each test case, if Nobita can get to the destination print YES, otherwise print NO.

Page 8 of 13

ACM ICPC 2015-2016, Ho Chi Minh City University of Science Training Camp
Team Selection Final Round, HCMUS October 11, 2015

Example
stdin
2
2
1 1
1 3
1 1
1 3
3
-1 1
1 1
1 -1
0 0
0 4

stdout
NO
YES

Explanation: For the second test case, Nobita starts at (0, 0) and uses actuator (1, 1) to move to
(2, 2). Then from (2, 2), he uses actuator (1, 1) to reach someones house at (0, 4).

Page 9 of 13

ACM ICPC 2015-2016, Ho Chi Minh City University of Science Training Camp
Team Selection Final Round, HCMUS October 11, 2015

Problem H. WICKED Is Good?


Input le:
Output le:
Time limit:
Memory limit:

stdin
stdout
1 second
512 megabytes

Thomas is a brave young man who has made an amazing escape from the
hand of WICKED - an organization which uses human as the experimental
subject. However, one of his best friends named Minho was caught in the
last ght. As a result, Thomas decided to ght back. With a short
inspirational speech, he surprisingly became the head of the Right Arm an armed group formed by people who escaped from WICKED.
The Right Arm decided to battle from the inside, which means that they
need access to all the security doors. Since all the people in the Right
Arm used to be in WICKED, they can remember some of the access codes
in there. However, the security system works in a unusual way:
Step 1: enter the access code L.
Step 2: press the OK button. L will be displayed on the screen.
Step 3: press the OK button again. The system calculates the sum of the current number displayed
on the screen and the access code L. It means that after the second time, the result will be L + L
Continue pressing the OK button until we get a number which consists of equal digits only.
Since time is not on their side, Thomas wants to make sure if they could reach a valid number from a
particular access code.

Input
A single line containing a positive integer L (1 L 999) - the access code.

Output
If it is impossible to reach a valid number from the given access code, print I dont know! (without
quotes). Otherwise, print a pair of two integers digit and length denoted the digit and the length of the
valid number.

Example
stdin
74
50

stdout
2 3
I dont know!

Explanation: 74 + 74 + 74 = 222.

Page 10 of 13

ACM ICPC 2015-2016, Ho Chi Minh City University of Science Training Camp
Team Selection Final Round, HCMUS October 11, 2015

Problem I. Coming Home


Input le:
Output le:
Time limit:
Memory limit:

stdin
stdout
3 seconds
512 megabytes

Riley is a lovely eleven-year-old girl. However, when her family


moves to a new city, she becomes sad as she really misses her old
life. Eventually, she prepares to leave her parents and to board a
bus to go back to her old house! Joy, Sadness, Disgust, Fear, and
Anger are the five core emotions of Riley. Now they have to
bring Riley back to her parents.
There are N personality islands in Rileys mind. There are roads
to connect all islands. However, because Riley is really sad, many
roads have been broken. Currently all personality islands are connected with only N 1 roads.
The personality islands are numbered from 1 through N . The island 1 is the Headquarter (the root).
For each personality island i, the predecessor of that island is pi and the distance between i and pi is di .
To restore the stability state for all personality islands so that Riley will return to her house and share
her feeling with her parents, the ve emotions (Joy, Sadness, Disgust, Fear, and Anger) must quickly
send a special signal via train of thought from one island to all islands (from 1 to k where 1 k N ).
For each value of k, please help the ve emotions to choose the best personality island where they can
start to send the signal to all islands from 1 to k. The best island is the island with the minimum total
distances for that island to all other islands
min {

1vN

dist(i, v)}

i=1

where dist(i, v) denotes the distance between the two personality islands i and v.

Input
First line of the input contains one integer N (1 N 2 105 ). Then N 1 lines follow, ith of them
contains two integers pi+1 and di+1 predecessor of a island i + 1 and the distance between (i + 1)th
island and its predecessor (1 pi N , 1 di 2 105 , the graph represented by pi is a tree).

Output
Print N lines. In the ith line, print the answer when k = i.

Example
stdin
5
1
1
2
4

1
2
3
1

stdout
0
1
3
7
11

Page 11 of 13

ACM ICPC 2015-2016, Ho Chi Minh City University of Science Training Camp
Team Selection Final Round, HCMUS October 11, 2015

Problem J. When A Fighter Has To Think


Input le:
Output le:
Time limit:
Memory limit:

stdin
stdout
1 second
512 megabytes

Hidden Leaf Village is considered as the most powerful ninja village


in the Land of Fire. This village is the symbol of peace in the ninja
world. They provide N ninjas for ordered tasks but they are also
responsible for national requests like protecting the kings. The
ninjas are numbered from 1 to N .
Naruto - the hero of the ninja world after the world war against
Madara - is considered to be promoted as the seventh Hokage
(Hokage is the head of the Hidden Leaf Village). In order to make
sure that Naruto is mature enough to lead the village, the council
decides to give him the nal test: to identify the natural elements of all the ninjas in the village.
There are ve elements named Fire, Lightning, Water, Wind, Earth. There is an relationship between
any pair of two elements - a supportive one or an opposite one. There are ve supportive relationships:
Wind supports Fire, Fire supports Water, Water supports Earth, Earth supports Lightning and Lightning supports Wind. There are also ve opposite relationships: Wind restricts Water, Water restricts
Lightning, Lightning restricts Fire, Fire restricts Earth and Earth restricts Wind.
Naruto knows that he is numbered 1 and Wind is his natural element. He also has access to the database
which contain details about all the missions in the past. However, he cannot nd anything about the
natural element of each ninja. The only useful thing is the result of M tests of relationship between the
ninjas. A test result is described in one of the 5 following ways:
0 A B: means that ninja A and ninja B have the same natural element.
1 A B: means that ninja A restricts ninja B.
2 A B: means that ninja B supports ninja A.
3 A B: means that ninja A supports ninja B.
4 A B: means that ninja B restricts ninja A.
Please help Naruto to check if there is any errors in the database. If not, he wants to know the minimum
number of tests he still has to perform in order to nd the natural elements of all the ninjas.

Input
The rst line contains an integer T (1 T 30) - the number of test cases.
The rst line of each test case contains two integers N , M (2 M, N 105 ) - the number of ninjas
and the number of tests respectively. Then there are M lines following.
Each line contains three integers res, A, B (0 res 4, 1 A, B N , A = B) denotes the result
of the test following the format described above.

Output
For each test case, print the minimal number of tests Naruto still needs to perform. If there is some error
in the database, print "-1" (without quotes).
Page 12 of 13

ACM ICPC 2015-2016, Ho Chi Minh City University of Science Training Camp
Team Selection Final Round, HCMUS October 11, 2015

Example
stdin
2
5
1
4
0
2
6
1
1
0

4
1
2
3
4
3
1
3
2

stdout
0
-1

2
3
4
5
3
1
4

Explanation: In the rst case, Naruto can gure out that 1 is Wind (because thats him), 2 is
Water, 3 is Wind, 4 is Wind and 5 is Lightning, so he will not need any more information. In the second
case, there is an error in the rst two tests.

Page 13 of 13

You might also like