problemset
problemset
Problem A. Charger
Input file: standard input
Output file: standard output
Balloon Color: Light Blue
Soudi’s new phone has a battery that he wants to keep in good health. To do this, he always charges it
to 100% before using it. Given that the phone charges at a rate of 1% per minute, Soudi wants to know
how many minutes he has to wait to fully charge his phone from its current battery percentage. Write a
program that calculates the time needed for the battery to reach 100% based on the current battery level.
Input
A single integer currentPercentage (0 ≤ currentP ercentage ≤ 100) represents the current battery
percentage of the phone.
Output
A single integer representing the number of minutes Soudi has to wait until the battery reaches 100%.
Examples
standard input standard output
92 8
5 95
37 63
Page 1 of 15
The 2024 ICPC Lebanese Collegiate Programming Contest
Beirut, Lebanon, November, 9, 2024
Problem B. Divisibility
Input file: standard input
Output file: standard output
Balloon Color: Red
Coach Zezo wants to test how smart his children are, so he will give them a hard problem. He will give
them an array of N elements consisting of zeroes and ones only and a number X and wants them to count
the number of non-empty subsequences such that their sum is divisible by X because the number can be
very big Print the answer mod 109 + 7. But this is a hard problem for small children to solve, Can you
help them?
Input
The first line contains one integer T , the number of test cases.
The first line of each test case contains two integers N ,X (2 ≤ N, X ≤ 2 · 105 ).
The second line of each test case contains N integers A1 , A2 , . . . , An (0 ≤ Ai ≤ 1).
Output
for each test case, print the number of non-empty subsequences that are divisible by X mod 109 + 7.
Example
standard input standard output
2 3
5 4 1
0 1 1 1 1
3 5
0 1 1
Page 2 of 15
The 2024 ICPC Lebanese Collegiate Programming Contest
Beirut, Lebanon, November, 9, 2024
Input
The first line contains a single integer N (1 ≤ N ≤ 105 ) — the number of elements in the array.
The second line contains N integers A1 , A2 , . . . , AN (1 ≤ Ai ≤ 230 ) — the elements of the array.
Output
Print "Yes"if it is possible to sort the array using the described operation, otherwise print "No".
Examples
standard input standard output
5 Yes
8 4 2 30 15
5 No
3 16 8 4 2
Page 3 of 15
The 2024 ICPC Lebanese Collegiate Programming Contest
Beirut, Lebanon, November, 9, 2024
Yassin is very obsessed with GCD and LCM, but he couldn’t solve this problem, so he asked you for help.
Can you assist him?
Eslam gave Yassin an array A of n integers, where the i-th element is represented as Ai . Then, Eslam
asked Yassin q queries. Each query is represented by an integer len. For each query, Yassin has to choose
one subarray of that length, such that its GCD is the maximum possible.
For example, consider the array A = [2, 6, 9, 24]:
• If Eslam asked Yassin about the length 3, then the answer would be 3, where the subarray Yassin
has to choose is [6, 9, 24].
• If Eslam asked about the length 1, then Yassin would answer 24.
Input
• The first line contains a single integer T (1 ≤ T ≤ 104 ) — the number of test cases.
• The first line of each test case contains a single integer n (1 ≤ n ≤ 105 ).
• The next q lines each contain a single integer len (1 ≤ len ≤ n).
Note: It is guaranteed that the sum of n over all test cases does not exceed 105 .
Output
For each query, output a single integer representing the answer to the i-th query.
Example
standard input standard output
2 5
4 55
10 20 55 43 1
3 1
3 3
1 3
4 3
5
2 6 3 9 24
4
5
3
4
2
Page 4 of 15
The 2024 ICPC Lebanese Collegiate Programming Contest
Beirut, Lebanon, November, 9, 2024
You are given an array of N integers initially filled with zeros. You have to perform Q queries on this
array the queries called KoT aa Addition. Each query is represented by three integers A, L, and R, where
1 ≤ A ≤ 104 , 1 ≤ L ≤ R ≤ N . The query operation updates the array as follows:
For each query (A, L, R):
• Continue this pattern until the element at index R, where K (R−L) is the highest power of K.
After performing all the queries, you need to print the final array modulo 109 + 7.
Input
The first line contains three space-separated integers N, Q, and K
(1 ≤ N ≤ 10 , 1 ≤ Q ≤ 10 , 1 ≤ K ≤ 10 ). The next Q lines contain three space-separated
6 6 9
Output
Print N space-separated integers representing the final array modulo 109 + 7.
Examples
standard input standard output
5 5 2 3 14 26 52 81
3 1 5
4 2 2
6 3 5
9 5 5
4 2 4
5 2 2 1 4 8 8 16
1 1 3
2 2 5
Page 5 of 15
The 2024 ICPC Lebanese Collegiate Programming Contest
Beirut, Lebanon, November, 9, 2024
Given an undirected connected graph with non-negative integer edge weights and node numbers from 1
to N , find a path from node 1 to node N such that the XOR of the weights of the edges along the path
is maximized.
A path can pass through certain nodes or edges repeatedly. This means you are allowed to revisit the
same node more than once, and if an edge is traversed multiple times, its weight must be included in the
XOR each time it is used.
Input
– The first line contains two integers N and M — the number of nodes and the number of edges.
(2 ≤ N ≤ 105 , N − 1 ≤ M ≤ 2 × 105 )
– The following M lines each contain three integers u, v, and w — representing an edge between
nodes u and v with a weight w. (0 ≤ w ≤ 1018 )
Output
For each test case, output a single integer, the maximum possible XOR sum for a path from node 1 to
node N .
Example
standard input standard output
1 6
5 7
1 2 2
1 3 2
2 4 1
2 5 1
4 5 3
5 3 4
4 3 2
Note
Example:
Consider the path 1 → 2 → 4 → 3 → 5 → 2 → 4 → 5 in the graph. Let’s denote the weight of the edge
between two nodes u and v as w(u, v).
Assume the following weights for the edges:
Page 6 of 15
The 2024 ICPC Lebanese Collegiate Programming Contest
Beirut, Lebanon, November, 9, 2024
The corresponding XOR for the path is calculated as follows:
XOR = 2 ⊕ 1 ⊕ 2 ⊕ 4 ⊕ 1 ⊕ 1 ⊕ 3
2 ⊕ 1 = 3, 3 ⊕ 2 = 1, 1 ⊕ 4 = 5, 5 ⊕ 1 = 4, 4 ⊕ 1 = 5, 5⊕3=6
Page 7 of 15
The 2024 ICPC Lebanese Collegiate Programming Contest
Beirut, Lebanon, November, 9, 2024
Problem G. Loser
Input file: standard input
Output file: standard output
Balloon Color: Dark Green
Y assin and M ostaf a played several chess games throughout the day. To keep track of the results, they
agreed that for every game Y assin won, they would write ’y’ on a piece of paper, and for every game
M ostaf a won, they would write ’m’. At the end of the day, they want to determine who won more games.
Given a string s consisting of the characters ’y’ and ’m’, where each character represents a win for Y assin
or M ostaf a respectively, determine the overall winner.
Input
A single string s (1 ≤ |s| ≤ 1000) where each character is either ’y’ (indicating a win for Y assin) or ’m’
(indicating a win for M ostaf a).
Output
Print "Y assin "M ostaf a or "Draw"based on who won more games or if they tied.
Examples
standard input standard output
mmmymymyy Mostafa
mmyy Draw
Page 8 of 15
The 2024 ICPC Lebanese Collegiate Programming Contest
Beirut, Lebanon, November, 9, 2024
In a large network of towns, there are n towns connected by n − 1 roads. These roads ensure that any
two towns can be reached either directly or indirectly.
Each town has its own way of doing business, which has made it difficult for the towns to trade with one
another. To solve this, the council decided to introduce m trade agreements.
For each of these m trade agreements, a representative travels from one town si to another town ti along
the shortest road path, encouraging all the towns along the way (including si and ti ) to join the agreement.
Once a trade agreement is in place, business can only occur between two towns ui and vi if there exists
a trade agreement such that all towns along the shortest road path between ui and vi (including ui and
vi ) are part of that agreement.
The council wants to see how effective these trade agreements are by counting how many pairs of towns
(u, v) (u < v) can do business with each other.
Input
The first line contains two positive integers n, m (2 ≤ n, m ≤ 105 ) — representing the number of towns
and the number of trade agreements.
The next n − 1 lines each contain two integers xi , yi (1 ≤ xi , yi ≤ n) — representing a road connecting
town xi and town yi .
The following m lines each contain two integers si , ti (1 ≤ si , ti ≤ n) — representing a trade agreement
between town si and town ti .
Output
Output a single integer, representing the number of pairs of towns that can engage in business.
Example
standard input standard output
7 2 6
1 2
1 3
2 4
2 5
3 6
3 7
6 7
4 5
Note
The first agreement includes towns 3,6,7 and the second agreement includes towns 2,4,5, the towns that
can engage in business are (6,3), (6,7), (3,7), (4,2), (4,5), and (2,5).
Page 9 of 15
The 2024 ICPC Lebanese Collegiate Programming Contest
Beirut, Lebanon, November, 9, 2024
3. Subtract 1 from all elements whose indices are greater than the index of this chosen element.
Input
Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 103 )
— the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer N (1 ≤ N ≤ 105 ) — the length of
array A.
The second line of each test case contains N integers (1 ≤ ai ≤ 109 ) — the elements of array
A.
The sum of N over all test cases does not exceed 105 .
Output
For each test case, output the lexicographically largest B.
Example
standard input standard output
2 7 5 2 -1
4 512 313 109 5 2 2
7 6 4 2
6
2 5 109 313 512 6
Page 10 of 15
The 2024 ICPC Lebanese Collegiate Programming Contest
Beirut, Lebanon, November, 9, 2024
In the village of Bardanoha, the rabbits are eager to master the art of crossing the river efficiently. Inspired
by the wise ducks who navigate waters with ease, they seek guidance from the ducks to help them.
However, the ducks in Bardanoha are busy and can only spare limited time to assist the rabbits. Each
duck i is only available to help a rabbit at precisely time Ti .
The rabbits, being patient creatures, have wider timeframes for their river-crossing endeavors. Rabbit j
can cross the river between time Aj and time Bj .
Each rabbit ideally seeks a duck to accompany them across the river. For their schedules to align, a duck
i and a rabbit j must satisfy the condition (Aj ≤ Ti ≤ Bj ).
Given that each rabbit can be paired with at most one duck, and each duck can assist at most one rabbit,
your task is to determine the maximum number of rabbit-duck pairs that can be established for efficient
river crossings.
Input
• The first line contains two integers D and R (1 ≤ D, R ≤ 200, 000) — the number of ducks and the
number of rabbits, respectively.
• The second line contains D integers T1 , T2 , . . . , TD — the times when each duck is available.
• The next R lines each contain two integers Aj and Bj (1 ≤ Aj ≤ Bj ≤ 109 ) — the start and end
times of the jth rabbit’s timeframe for crossing the river.
Output
Print a single integer representing the maximum number of rabbit-duck pairs that can be established.
Example
standard input standard output
6 5 5
5 6 8 9 10 4
2 6
4 8
6 9
3 7
1 5
Page 11 of 15
The 2024 ICPC Lebanese Collegiate Programming Contest
Beirut, Lebanon, November, 9, 2024
Amoor was walking in the forest when he discovered a tree with n magnetic nodes. Each node i has a
score si . The in-order traversal of this tree is (1, 2, 3, . . . , n), meaning the nodes are visited in ascending
order.
Amoor decided to climb this tree and calculate the score he could obtain. The score is calculated using
the following steps:
1. Multiply the score of the left subtree by the score of the right subtree.
Amoor aims to find a tree structure that adheres to the given in-order traversal (1, 2, 3, . . . , n) and
maximizes the total score points. Your task is to help Amoor by finding the following:
2. The pre-order traversal of the tree that yields this maximum score.
Input
• The first line contains a single integer n (1 ≤ n ≤ 50) — the number of nodes.
Output
• The first line should contain a single integer — the maximum score Amoor can get.
• The second line should contain the pre-order traversal of the tree that gives the maximum score.
Example
standard input standard output
4 23
3 4 2 3 3 1 2 4
Note
• In-order Traversal: Visits nodes in the left subtree, then the current node, and finally the right
subtree.
Page 12 of 15
The 2024 ICPC Lebanese Collegiate Programming Contest
Beirut, Lebanon, November, 9, 2024
Zezo discovered an intriguing equation: X = A ⊕ B, where ⊕ denotes the bitwise XOR operation.
Given an integer X, your task is to find two integers A and B such that:
1. A ⊕ B = X
If there are multiple pairs (A, B) that satisfy these conditions, return the pair where A is the smallest.
Input
The first line of Input contains a single Integer T (1 ≤ T ≤ 105 ) denoting the number of test cases.
The second line of Input contains a single Integer X (1 ≤ X ≤ 1018 )
Output
For each test case, output two integers A and B that satisfy the given conditions.
Example
standard input standard output
3 0 4
4 2 8
10 10 32
42
Note
For each test case, print the answer in a sorted order. If there are multiple solutions, print the smallest
pair.
Page 13 of 15
The 2024 ICPC Lebanese Collegiate Programming Contest
Beirut, Lebanon, November, 9, 2024
There are N groups each group contains ai people. You want to form a new team consisting of k people
selected from all groups(the people from the same group are different). However, two conditions must be
satisfied:
Your task is to count the number of different teams you can form while satisfying these conditions.
print the answer mod 109 + 7.
Input
The first line contains two integers N and k (1 ≤ N ≤ 1000, 1 ≤ k ≤ 500) representing the number of
groups and the number of people in the new team, respectively.
The second line contains N space-separated integers a1 , a2 , . . . , aN (2 ≤ ai ≤ 500) representing the number
of people in each group.
Output
Print a single integer representing the number of different teams you can form while satisfying the given
conditions, modulo 109 + 7.
Example
standard input standard output
2 3 6
2 3
Page 14 of 15
The 2024 ICPC Lebanese Collegiate Programming Contest
Beirut, Lebanon, November, 9, 2024
Problem N. Handshake
Input file: standard input
Output file: standard output
Balloon Color: Pink
You are given a row of n people numbered from 1 to n. Two people can perform a handshake if the number
of people standing between them is not greater than m.
Your task is to count the number of distinct pairs of people who can handshake.
Input
The first line contains an integer t (1 ≤ t ≤ 105 ) — the number of test cases.
Each of the next t lines contains two integers n (2 ≤ n ≤ 109 ) and m (0 ≤ m ≤ n − 2) — the number of
people in the row and the maximum allowable number of people between two handshaking individuals,
respectively.
Output
For each test case, output a single integer — the number of valid handshaking pairs.
Example
standard input standard output
3 9
5 2 4
5 0 10
5 3
Page 15 of 15