booklet 11_38
booklet 11_38
https://toph.co/contests/training/h8fkzn8
Schedule
The contest will run for 3h0m0s.
Rules
This contest is formatted as per the official rules of ICPC Regional Programming
Contests.
You can use C++17 GCC 13.2, C++20 Clang 16.0, C++20 GCC 13.2, C++23 GCC 13.2, C11
GCC 13.2, C17 GCC 13.2, C23 GCC 13.2, D8 11.8, Free Pascal 3.0, Java 1.8, Node.js
10.16, PHP 8.3, PyPy 7.1 (3.6), Python 3.12, Ruby 3.2, and Whitespace in this contest.
Notes
There are 7 challenges in this contest.
If you find any discrepencies between the printed copy and the problem statements in
Toph Arena, please rely on the later.
Disclaimer
The contents of this contest have not been reviewed by Toph and do not necessarily
represent Toph's views.
You're given a time specified by hour and minute in the 24-hour format. What was the
last minute?
In the 24-hour format, time runs from 00:00 (midnight) to 23:59 (one minute before
midnight). Hours are represented from 00 to 23 and minutes from 00 to 59. After
23:59, the clock resets to 00:00, marking the start of a new day, and the cycle repeats
continuously.
Input
Only line contains two integers, h and m (0 ≤\leq
≤ h ≤\leq
≤ 23, 0 <= m <= 59).
Output
Output the previous minute.
Samples
Input Output
03 24 03 23
Input Output
14 00 13 59
Input Output
00 00 23 59
Your task is to find the position of the late student of semester X in the final queue.
Input
The first line contains an integer T (1 ≤ T ≤ 10) - the number of test cases.
Second line contains the initial queue denoting the semester of the students. The
semesters will be represented without any spaces in between them.
It is guaranteed that all the students will be from the 1st to the 8th semester.
Output
Print an integer: the position of the student from semester X.
Samples
Input Output
2 4
7 2 5
2213887
5 5
34622
Input
The first line contains a single integer TT
T ( 11
1 ≤\leq
≤ TT
T ≤\leq
≤ 10) — the number of test cases.
10)
The only line of each test case contains two integers, XX
X and YY
Y (11
1 ≤\leq
≤ XX
X <<
< YY 107 ).
Y ≤\leq
≤ 10710^7
Output
For each test case, output “YesYes
Y es” if you can multiply33
3distinctdistinct
distinct integers withXX
X such
that X∗A∗B∗C=YX*A*B*C=Y
X ∗ A ∗ B ∗ C = Y where
(2<=A<B<C<=1e7)
(2 <= A < B < C <= 1e7).
(2
If
<= there are no such 33
3 distinctdistinct
distinct integers, output “NoNo
N o”.
A
Samples
<
B
<Input Output
C3 Yes
<=1 210 No
2 4 No
1e7)
2 11
In the 1st1st
1st case: we can transform XX
X into YY
Y by multiplying XX
X by 5, 6, 7.
6,
In 2nd2nd
2nd and3rd3rd 33distinctdistinct
3rd cases: we don't have any 3 distinct integers75,6,7X∗A∗B∗C=YX*A*B*C=Y
such that X ∗A∗B∗
C =Y.
1)Add1)
1)Add 1 to every AiA_i (L≤i<R)
Ai where (L ≤ i < R) and
Add (L
2)Add2)
2)Add (-1) to ARA_R
AR \leq
Add i operations:
More formally do the following
<
ALA_L
AL = ALA_L
AL + 1 R)
AL+1A_{L+1}
AL+1 = AL+1A_{L+1}
AL+1 + 1
AL+2A_{L+2}
AL+2 = AL+2A_{L+2}
AL+2 + 1
………………………………….
………………………………….
AR−1A_{R-1}
AR−1 = AR−1A_{R-1}
AR−1 + 1
ARA_R
AR = ARA_R
AR - 1
After processing all queries, print the maximummaximum
maximum element of the special array A.
NOTE:NOTE:
NOTE : All L and R are distinct. In other words, there are no repeated values for
any of the queries.
Input
The first line contains a single integer QQ ≤ Q ≤ 2 ∗ 105 )— the number of query.
(1≤Q≤2∗105)
Q (1
(1
Next QQ
Q lines contain two integer LL
L and RR
R ≤ L < R ≤ 109 ).
(1≤L<R≤109)
(1
\leq
Q(1
\leq
Output \leq
L
2*10^5)
After processing all queries, print the maximummaximum
<
maximum value of the array A.
R
Explanation:
In this game, each player is given an undirected graph with N vertices and M
undirected edges and The graph is not necessarily connected. Each player has the
choice to remove one or more edges from the given graph to make it Largest
Special Component.
The winner of the game is the one who constructs the largest special component.
Note:
Input
2 ∗ 105 , 1 ≤ m ≤2∗1052*10^5
The first line contains two integer numbers n and m ( 2 ≤ n ≤2∗1052*10^5 2 ∗ 105 )
— the number of vertices and edges, respectively.
ii
The second following m lines contain edges for Riktika: edge i is given as a pair of
vertices viv_i
vi and uiu_i
ui (1≤viv_i
vi ,uiu_i
ui ≤ n, viv_i
vi ≠uiu_i
ui ).
ii
The third following m lines contain edges for Ankita: edge i is given as a pair of
vertices viv_i
vi and uiu_i
ui (1≤viv_i
vi ,uiu_i
ui ≤ n, viv_i
vi ≠uiu_i
ui ).
Output
Print one integer — the maximum number of nodes and one character — the first
letter of the winner ( ‘R’ or ‘A’ ) and in case of a draw (‘D’).
Samples
Input Output
6 6 4 A
Explanation:
The picture below shows the graph of Riktika.
Riktika's initial graph consists of two cyclic components (displayed on the left). To
construct special components, we can remove a single edge from each component. For
example, removing edges (1 - 2) and (5 - 6) creates two special components (displayed
on the right). One special component includes nodes (1, 2, 3) while the other comprises
nodes (4, 5, 6).
Both components have 3 nodes each. Thus, the largest special component in Riktika's
graph contains 3 nodes.
In Ankita's initial graph, there is one cyclic component and two single nodes without
edges (displayed on the left). One of the ways to make the cyclic component special, we
can remove edges (1 - 2), (1 - 3) and (3 - 4). This results in a graph with three special
components consisting of nodes (5), (6) and (1, 2, 3, 4) (displayed on the right).
Among these components, the largest one consists of nodes (1, 2, 3, 4); totaling four
nodes.
The growth of these trees is not natural; instead, it depends on the application of
nutrients. Each tree takes b days to grow by 1 millimeter with the aid of nutrients.
Additionally, once nutrients are applied to a tree at day-x, no more nutrients can be
added to that tree before day-(x+b).
Also, trees can be trimmed from the top. It takes c days for a tree to be trimmed by 1
millimeter.
Nutrients can be applied to a tree multiple times and also a tree can be trimmed
multiple times.
In a single day, any number of trees can receive nutrients and any number of trees can
be trimmed.
Your task is to determine the minimum number of days required to make all the trees
equal in height. You can choose any desired height for the trees of your choice.
Input
The first line contains an integer t (1 ≤\leq 105 ) — the number of test cases.
≤ t ≤\leq
≤ 10510^5
Each test case contains two lines.
The first line of each test case contains three integer n, a, b (1≤\leq 105 , ≤\leq
≤ n≤\leq
≤10510^51 ≤ a, ≤\leq
b≤
109 ) - the number of trees, days required by trees to grow 1 millimeter and days
10910^9
required to trim a tree by 1 millimeter.
Output
For each test case, output the minimum number of days required for all the trees to be
of equal height.
After 3 days, both trees are of equal height of 2 millimeters. It can be shown that they
cannot be made of equal height in less than 3 days.
1. Before reaching the city with the highest Power, Gopher can go from city ii
i to city
jj
j only if the Power of city iii is lower than that of city jj (Poweri<Powerj)
j (P oweri < P owerj ).
(Power_i
2. Once he reaches the city with the highest Power, Gopher's path can go from city
<
ii
i to cityjjj if the Power of ii city i is higher than that jjof(Poweri>Powerj)
Power_j)city j (P oweri >
P owerj ). (Power_i
>
The cost of moving fromii city ijjto city j is calculatedPower_j) using the formula
(xi − xj )2 + (yi − yj )2 , where (xi,yi)
(xi−xj)2+ (xi , yi ) represents the coordinates of city ii i and
(yi−yj)2\sqrt{(x_i
(x j , yj ) represents the coordinates (x_i,
(xj,yj) of city jj
j.
-
(x_j, y_i)
Gopher
x_j)^2
y_j) could complete his tour through various routes, he wants to accomplish it with
the
+ minimum cost. Thus, he turns to you for assistance in this.
(y_i
-Input
y_j)^2}
N (2 ≤ N ≤ 3 × 103 ) denoting the number of
The first line will contain one integerN(2≤N≤3×103)N(2\leq
cities Gopher will visit in his tour. N
\leq
Next NN N lines will contain three integers Poweri(1≤Poweri≤N)Power_i(1
P oweri (1 ≤ P oweri ≤ Nxi,yi(1≤xi,yi≤106)x_i,y_i
3\times{10} ), xi , yi (1 ≤
6
xi , yi ≤ 10 ), PoweriPower_i
P oweri denoting the ^3)\leq
Power ithi_{th} and xi , yi\leq
of ith cityxi,yix_i,y_i denoting the
coordinator of ithi_{th}
ith city. Power_i\leq x_i,y_i
N) \leq
{10}
Output ^6)
Print a single line containing the minimum cost to visit all the cities in the Gophers
10−4 will be ignored.
tour. Errors less than 10−410^{-4}
Samples
Input Output
14.9225