Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
25 views14 pages

epc40 (1)

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 14

EPC 4.

0
Tunis, December, 1, 2024

Problem A. Balloon Quest (Navy Blue)


Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Seif, Jridi and Bobzzz are preparing for the ENSI Programming Challenge 4.0 (EPC 4.0). During the
contest, balloons are used to represent the participants’ success in solving problems. Each problem has a
specific color associated with it, and the team needs at least k balloons of each color to ensure there are
enough for all participants who solve that problem.
After revising their stock of balloons, they found they currently have ai balloons of color i for all 1 ≤ i ≤ n.
To ensure the contest runs smoothly, they need to calculate how many additional balloons they must buy
to meet the requirements.

Input
The first line contains two integers n and k (1 ≤ n, k ≤ 100) – the number of problem colors and the
minimum required balloons for each color .
The second line contains n integers a1 , a2 , ..., an (0 ≤ ai ≤ 100) – the current number of balloons available
for each problem color .

Output
Print a single integer a single integer, the total number of additional balloons Seif, Jridi and Bobzzz need
to buy.

Example
standard input standard output
5 7 6
6 8 5 9 4

Page 1 of 14
EPC 4.0
Tunis, December, 1, 2024

Problem B. Requirements (White)


Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Ibrahim and his friend are planning to create new hardware that uses their custom protocol, ’BARSOU’.
The hardware must meet a set of requirements.
After several days of gathering these requirements, the team collected n requirements, labeled from r1
to rn . Since it’s difficult to implement all the requirements at once, Ibrahim asked his m friends to help
prioritize them.
Each friend chose a subsequence of requirements they thought should come first.
Once the voting was done, Ibrahim asked you to compile and share the voting results.

Input
The first line contains two integer n number of requirement and m number of ibrahim’s friends
(1 ≤ n ≤ 105 ,1 ≤ m ≤ 105 )
. The next m lines contains two integers l, r the subsequense that ibrahim’s friend wanted

Output
n integer representing the voting results

Example
standard input standard output
5 6 2 4 5 4 3
5 5
2 5
1 3
2 4
3 5
1 4

Page 2 of 14
EPC 4.0
Tunis, December, 1, 2024

Problem C. Who is the winner? (Green)


Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Fares and Helmi are both enthusiastic gamers who invented a turn-based game with the following rules:

• They start with a score of 0.

• On each turn, a player can increase the score by any amount from 1 to x.

• The objective of this game is to avoid reaching or exceeding a score of n.

The player who reaches or exceeds n loses the game, and the other player wins. Given that both players
play optimally, who will be the winner?

Input
The first line contains integer t (1 ≤ T ≤ 105 ) – the number of games fares and Helmi will play .
The second line contains two integers n and x (1 ≤ x ≤ 105 , 1 ≤ x ≤ 105 ) – following what is described
in the statement.

Output
For t lines, each line indicates the winning player. Please format the output as "Player 1"or "Player
2."Player 1 is the one who starts first, while Player 2 is the second player to begin.

Example
standard input standard output
1 Player 1
20 3

Page 3 of 14
EPC 4.0
Tunis, December, 1, 2024

Problem D. Password (Sky Blue)


Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

One of the security requirements for the "BARSOU"protocol is the implementation of a wake-up security
password. The process to generate this password is as follows:
After receiving a wake-up signal, an exchange of n messages occurs, with the messages having IDs
id1 , id2 , ..., idn .
To generate the password, two numbers are computed for each message ID:

• BAR Number: This is obtained by taking the binary inverse of the message ID (in binarry 1–>0
and 0–>1).

• SOU Number: This is the smallest power of two that is greater than the message ID.

Once the BAR and SOU numbers are calculated for each message, the next step is to compute the absolute
difference between the BAR and SOU numbers.
Xn
|BARi − SOUi |
i=1
Can you help Ibrahim generate the password key based on this process?

Input
The first line contains n (1 ≤ n ≤ 105 ) – the number of messages.
The second line contains n integer id1 , id2 , ..., idn (1 ≤ idi ≤ 109 ) – the ids of the message.

Output
Output The calculated password.

Example
standard input standard output
5 382
55 62 70 100 90

Page 4 of 14
EPC 4.0
Tunis, December, 1, 2024

Problem E. Hardware Queue (Yellow)


Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Ibrahim and his friend are planning to create new hardware that supports a protocol called "BARSOU".
On the physical layer, multiple nodes can be connected via a shared communication bus.

This bus allows for the connection of n nodes, but the nodes are not synchronized. To handle potential
collisions on the bus, they decided to implement a system similar to the CAN standard: messages with
the lowest ID are given transmission priority.
Each node maintains a queue of messages, and the order within the queue cannot be changed. If the bus
is idle(empty), the node with the lowest message ID will transmit first, while the other nodes will be
blocked until the transmission is complete.
To test the hardware, Ibrahim took snapshots of the message queues from the devices and asked you to
predict the order in which the frames will be transmitted.
It is guaranteed that the frame during the execution of the test case is distinct.

Input
The first line contains an integer n (1 ≤ n ≤ 105 ) – the number of connected devices.
For each of the n devices, we have m messages in its queue (1 ≤ m ≤ 105 ) where the id of the message I
1 ≤ idI ≤ 109 .
It is guaranteed that the total number of messages in all devices will not exceed 5 · 105 .

Output
One line representing the order in which each message will be transmitted.

Page 5 of 14
EPC 4.0
Tunis, December, 1, 2024

Example
standard input standard output
3 29 76 63 16 27 15 84 36 92 97
5
76 63 16 27 15
3
84 36 92
2
29 97

Page 6 of 14
EPC 4.0
Tunis, December, 1, 2024

Problem F. Sweet Combination (Powder Blue)


Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

It’s EPC day, and Chadi and Aymen have gotten very hungry after working hard to organize the event;
thankfully, the team has kept a box of n distinct sweets just in case.
Chadi is currently very busy with some preparations, so he tells Aymen to grab a pile A of sweets from
the box (possibly all of them). Aymen will deliver them to him, where he in turn will pick another pile B
of sweets from Aymen’s pile (of course, he won’t take everything to keep some for Aymen).
Before they do this, Chadi asks Aymen a question: "For all n sweets inside the box, how many different
pairs of piles (A, B) do you think we can get?"
Aymen is also busy and doesn’t have time to answer that question; therefore, he asks you to do that for
him.
Since the result is pretty large, print it modulo 109 + 7.

Input
The first line consists of t (1 ≤ t ≤ 104 ) – the number of test cases.
Each test case consists of a number n (1 ≤ n ≤ 1018 ) – the number of sweets in the box.

Output
Print the different possible pairs of piles Chadi and Aymen can get.

Example
standard input standard output
3 211
5 19
3 441651107
40

Page 7 of 14
EPC 4.0
Tunis, December, 1, 2024

Problem G. Volleyball Game - Easy Version (Purple)


Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

In a team of n volleyball players numbered from 1 to n and arranged in a straight line from left to right,
each player stands 1 meter apart. The goal is to pass a single volleyball from the first player (Player
1) to the last player (Player n). Each player can only throw the volleyball to another player on his right,
as long as that player is within his throwing range.
Specifically, each Player i has a throwing range ri . Therefore, Player i can throw the volleyball to Player
j (where i < j) if and only if Player j is within Player i’s range, satisfying j ≤ i + ri .
Knowing that the calorie cost for each throw between two players is fixed at 1 calorie. Can you determine
the minimum total calorie cost required to pass the volleyball from the first Player to the last Player ?

Input
The first line contains an integer n — the number of players (2 ≤ n ≤ 2 · 105 ).
The second line contains n integers r1 , r2 , . . . , rn (1 ≤ ri ≤ 2 · 105 ).

Output
Print a single integer — the minimum calorie cost of passing the volleyball from the first Player to the
last Player.

Example
standard input standard output
6 2
3 2 3 1 2 3

Page 8 of 14
EPC 4.0
Tunis, December, 1, 2024

Problem H. Faulty Routers (Orange)


Input file: standard input
Output file: standard output
Time limit: 0.5 seconds
Memory limit: 256 megabytes

Aymen and Chadi are setting up the network for the competition; they prepared n routers to be distributed
across different rooms. Each router can transmit to any other router before reaching the final destination
(the transmission time between router i and router j will be denoted as ai,j ).
Suddenly, Chadi realizes that they were scammed and the routers they got are programmed incorrectly.
He calls the distribution center and starts complaining about how upset he is. They apologize and tell
him that if he can compute the shortest transmission time between the routers, he can fix the problem.
Since Chadi is a problem solver, he starts working on it right away. He knows that for q separate queries,
he will get a transmission from router i. During that time, he also knows that his laptop will be sitting
next to router j. Therefore, for each query, he wants to compute the minimum transmission time passing
through the router network so that he can code it into the router.
Given that the event is progressing, you know that he was able to finish the task successfully. Could you
do that too?

Input
The first line consists of 2 integers n and q (1 ≤ n ≤ 100), (1 ≤ q ≤ 105 ) – the number of routers and the
number of queries, respectively.
Each line i of the next n lines consists of n integers ai,0 , ai,1 , ..., ai,n (1 ≤ ai,j ≤ 109 ) – ai,j representing the
distance between router i and router j, note that the route from router i to itself will always be 0.
The next q lines consist of 2 integers a and b (1 ≤ a, b ≤ n) – the start and finish router, respectively.

Output
Output q lines, each line consisting of the minimum transmission time for the ith query.

Example
standard input standard output
3 3 3
0 5 2 1
5 0 1 2
2 1 0
1 2
2 3
1 3

Page 9 of 14
EPC 4.0
Tunis, December, 1, 2024

Problem I. Best climbing route (Red)


Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Fares likes climbing so much but he still needs so much training before going to the mountains. So, he
enrolled in an indoor climbing gym in order to improve himself. He discovered multiple types of holds (A
climbing hold is a shaped grip that is usually attached to a climbing wall so that climbers can grab or
step on it.) and decided to give each type a difficulty score. The following are the holds types and his
thoughts about it:

• Jugs: difficulty 1

• Crimps: difficulty 2

• Pinches: difficulty 3

• Pockets and Slots: difficulty 4

• Slopers: difficulty 5

Given that the wall is compromised of n rows and m columns and each case has a different hold, Fares
want to go on the hardest route. Note that, since this is climbing, there is no going down. Fares can only
move upwards or diagonally upwards by one hold. To make it even harder, he’s only allowed to put both
his hands on one hold at a time (the same for his feet).
More formally, for a given position (i, j) the player can only move to positions (i + 1, j) , (i + 1, j − 1)
or (i + 1, j + 1) assuming the position exists, the start position can be any hold within the first row (i.e
i = 0).
Can you help him identify the score of the hardest route? The score of the route is the sum of difficulty
of all the holds that constitute that particular route.

Input
The first line contains two integers n and m (1 ≤ n · m ≤ 105 ) – the number of rows and columns
respectively.
The next n lines contains m integers representing the difficulty of the hold di,j at the ith row and j th
column (1 ≤ di,j ≤ 5).

Output
Output the score of the hardest route.

Example
standard input standard output
3 5 11
1 2 3 4 5
5 3 2 1 3
2 3 2 3 2

Page 10 of 14
EPC 4.0
Tunis, December, 1, 2024

Problem J. Volleyball Game - Hard Version (Silver)


Input file: standard input
Output file: standard output
Time limit: 3 seconds
Memory limit: 256 megabytes

In a team of n volleyball players numbered from 1 to n and arranged in a straight line from left to right,
each player stands 1 meter apart. The goal is to pass n volleyballs sequentially from the first player
(Player on the far left) to the last player (Player on the far right). However, once the last player receives
the volleyball, he will move with it to the position of the first Player (becoming the new first
Player), and the remaining players will shift one position to the right (each player moves 1 meter
to the right). This rotation allows each player to experience all positions, ensuring fairness.
As in the easy version, each player can throw the volleyball only to another player positioned to his right,
provided that player is within his throwing range. Also, each player i has a throwing range ri . Therefore,
Player i can throw the volleyball to Player j (where i < j) if and only if Player j is within Player i’s
range, satisfying j ≤ i + ri .
Knowing that the calorie cost for each throw between two players is fixed at 1 calorie. Can you determine
the minimum total calorie cost required to pass n volleyballs sequentially from the first Player to the last
Player ?

Input
The first line contains an integer n — the number of players (2 ≤ n ≤ 2 · 105 ).
The second line contains n integers r1 , r2 , . . . , rn (1 ≤ ri ≤ 2 · 105 ).

Output
Print a single integer — the minimum calorie cost of passing n volleyballs sequentially from the first Player
to the last Player.

Examples
standard input standard output
4 4
4 4 4 4
7 25
1 1 2 5 3 1 1

Page 11 of 14
EPC 4.0
Tunis, December, 1, 2024

Problem K. Hunter Games (Pink)


Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 256 megabytes

While preparing the problemset for the contest, Chadi was enjoying his time playing a game called
Hunter Games. This game consists of n players playing inside a 2D plane; each player will be positioned
at coordinates (i, j) such that all the players have distinct coordinates.
There are q turns in the game. For each turn, 2 players called "hunters"are selected, and a rectangular
barrier is formed such that the players’ coordinates form the diagonal of an axis-aligned∗ rectangle. The
other players inside this barrier are therefore called "prey"and need to survive as long as they can before
the time limit ends.
As Chadi is very meticulous at maximizing his score, he is interested in knowing how many prey can be
hunted in each turn. Can you help him do that?

Input
The first line consists of 2 integers n and q (1 ≤ n, q ≤ 105 ) – the number of players and the number of
turns respectively.
The next n lines consist of integers xi and yi (0 ≤ xi , yi ≤ 105 ) – the coordinates of the i-th player.
The next q lines consist of 2 integers ai and bi (1 ≤ ai , bi ≤ n) – the index of the 2 chosen players for the
i-th turn.
Note that for each query the chosen points will always form a rectangle (meaning that for players i and
j we get xi 6= xj and yi 6= yj ).

Output
Output the number of prey for each different turn.

Example
standard input standard output
5 2 2
1 1 1
3 2
2 5
5 3
4 1
1 4
5 3


an axis-aligned rectangle is a rectangle where its sides are either parallel or perpendicular to each of the plane axis.

Page 12 of 14
EPC 4.0
Tunis, December, 1, 2024

Problem L. Trick Shot on The Golf Course (Gold)


Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Aymen and Chadi are out on the golf course, enjoying a friendly game. Aymen, feeling confident, decides
to show off his skills with a tricky shot. He points out a nearby wall and boasts, "I bet I can bounce the
ball off that wall and still get it into the hole!"
Chadi raises an eyebrow, skeptical of Aymen’s plan.
The challenge is hitting the ball so it first bounces off the wall before landing in the hole. The shot must
follow the rules of reflection, meaning the angle at which it hits the wall is the same as the angle at which
it bounces off.
Help Aymen determine if his ambitious trick shot is possible.
Note that neither the ball nor the hole can be aligned with the wall.

Input
The first line contains an integer t (1 ≤ t ≤ 104 ) – the number of test cases. The following lines describe
the test cases.
Each test case consists of one line containing 8 space-separated integers:
(−1018 ≤ xb , yb , xh , yh , xw1 , yw1 , xw2 , yw2 ≤ 1018 ) — the coordinates of the ball, the hole, and the
two endpoints of the wall.

Output
For each test case, print “YES” if it is possible for Aymen to make the shot. Otherwise, print “NO”.

Example
standard input standard output
2 YES
3 0 5 2 1 1 2 3 NO
0 0 2 2 2 4 3 5

Page 13 of 14
EPC 4.0
Tunis, December, 1, 2024

Problem M. Ctrl-H Magic!!! (Black)


Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Chadi has written a program and now tries to improve its readability. One of the ways to improve
readability is to give good names to the variables, so now Chadi wants to rename some variables in his
program. In his IDE he makes use of the magical "Ctrl-H"shortcut, which can replace names of many
variable in just one run.
To use it, Chadi needs to select two strings s and t, and after that for each variable the following algorithm
is performed: if the variable’s name contains s as a substring, then the first (and only first) occurrence of
s is replaced with t. If the name doesn’t contain s, then this variable’s name stays the same.
Chadi has n variables that he wants to rename overall, for each variables he knows what name he wants
to change it to, the question Chadi is thinking of is that if he can choose s and t such as he can change
all of the variables to their desired name using the "Ctrl-H"command only once.
Note that to keep the indentation clean, Chadi will choose the desired names to be of the same length as
the initial variable names.

Input
The first line contains the only integer n (1 ≤ n ≤ 3000) — the number of variables in Chadi’s program.
Each of the following n lines contain the initial names of variables s1 , s2 , . . . , sn . After that, n more lines go,
the ith of them contains the desired name s0i for the ith variable. It is guaranteed that 1 ≤ |si | = |s0i | ≤ 3000.
It is guaranteed that there is at least one variable having its desired name different from the initial
name. Both initial and desired names consist of lowercase English letters only. For each variable the length
of its initial name is equal to the length of its desired name.

Output
If it is impossible to rename all variables, print “NO”.
Otherwise, on the first line print “YES” and on the following lines print s and t (1 ≤ |s|, |t| ≤ 5000),
which should be used for replacement. Strings s and t should consist only of lowercase letters of English
alphabet.
If there are multiple ways to perform the operation, you can use any of them.

Examples
standard input standard output
3 YES
bab a
cac d
cdc
bdb
cdc
cdc
2 NO
aaa
bab
aba
bbb

Page 14 of 14

You might also like