Diu Unlock The Algorithm Fall 24 Preliminary Mock
Diu Unlock The Algorithm Fall 24 Preliminary Mock
https://toph.co/c/diu-unlock-the-algorithm-fall-24-preliminary-mock
Schedule
The contest will run for 3h0m0s.
Authors
The author of this contest is diuacm.
Rules
This contest is formatted as per the official rules of ICPC Regional Programming
Contests.
You can use Bash 5.2, Brainf*ck, C# Mono 6.0, 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, Common
Lisp SBCL 2.0, D8 11.8, Erlang 22.3, Free Pascal 3.0, Go 1.22, Grep 3.7, Haskell 8.6, Java
1.8, Kotlin 1.9, Kotlin 2.0, Lua 5.4, Node.js 10.16, Perl 5.30, PHP 8.3, PyPy 7.3 (3.10),
Python 3.12, Ruby 3.2, Rust 1.57, Swift 5.3, and Whitespace in this contest.
Notes
There are 9 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.
We all know about the factorial operation. The formula behind factorial operation is
stated bellow:
n∗(n−1)∗(n−2)∗(n−3)∗……..∗1{n
n ∗ (n − 1) ∗ (n − 2) ∗ (n − 3) ∗ …… .. ∗ 1
*
There
(n-1) exists many uncommon variations of factorial operations. Today, we will know
about
* an interesting one, named “Exponential Factorial”. The exponential factorial is
a positive integer nn
(n-2) n raised to the power ofn−1n
n − 1, which in turn is raised to the power
of
* nn−2n − That is,
− 2, and so on in a right-grouping manner.
−
(n-3) 1
* 2
……..
*
1}
Input
There is no input for this problem.
1. The maximum power level – the monstrous power of Kaiju No. 8 (Kafka Hibino)!
Movement within the exam zone is restricted due to the chaos. You can only navigate
between adjacent areas, mimicking the circular layout of the power grid.
Determine the shortest distance between these two crucial power readings –
essentially, how close Kafka Hibino is to the Honju within this confined zone. This intel
is vital for the Defense Force to formulate a counterattack!
Time is of the Essence! Every moment wasted analyzing the data puts the Defense
Force at a disadvantage. Develop an algorithm to find the shortest distance as
quickly as possible! Can you decipher the power grid and aid the Defense Force in this
critical moment?
Input
The first line will contain an integer nn (2≤ n ≤ 100), denoting the size of the power
grid circular array. (2≤n≤100)n\,
(2
The second line will containnnn real numbers,
\leq ranging between0.10.1 10.010.0
0.1 and 10.0 inclusive,
denoting the power levels in each area.
n
It will be ensured that no two numbers
\leqin the array are the same.
100)
Output
You have to output a single integer, denoting the shortest distance between Kafka and
the Honju.
Input Output
9 3
4.2 8.7 7.9 3.1 2.8 1.4 9.5 5.0 7.1
The sample test cases have been visualized for better understanding.
During these windows, clubs can negotiate to buy players from other clubs, develop
their skills, and sell them later for a higher price if their market value increases.
arr
You are given an array arr (market values) where arr[i]arr[i]
arr[i] represents the market
(market
value (in millions of dollars) of a player in the i’thi’th
i’th transfer window. Your task is to help
values)arr\:
Profit United FC maximize their profit by choosing the best transfer window to buy a
(market\:
player and a different future transfer window to sell him when his market value has
increased the most. If values)
no profit can be achieved, then Profit United FC will not buy or
sell a player, so their profit will be zero.
Note: The sale of the player must occur in any of the transfer windows that come after
the window in which the player was bought. Profit United FC cannot buy the same
player twice. You must choose the best transfer windows to maximize profit.
Input
• The First line will contain an integer NN
N.
• The second line will contain NN
N integers which denote the array arrarr
arr where arr[i]arr[i]
arr[i]
represents the market value of a football player on the i’thi’th
i’th transfer window.
11≤N≤1000001\le
≤ N ≤ 100000
N\le
Samples
Input Output
6 100
170 50 100 90 150 130
Input Output
5 0
70 60 40 30 10
Explanation 1: Buy at the 2nd transfer window (value = 50 million) and sell at the 5th
transfer window (value = 150 million). Profit = 150 - 50 = 100 million.
Input
The input consists of:
• The first line contains an integer nn ≤ n ≤ 104 ), the size of the array.
(1≤n≤104)
n (1
(1
• The second line contains nn
n integers a1,a2,...,ana_1, (1 ≤ ai ≤ 105 ), representing
a1 , a2 , ..., an (1≤ai≤105)
≤
the elements of the array. na_2, ..., (1
a_n ≤
q≤
• The third line contains an integer qq ≤ q ≤ 104 )a_i
(1≤q≤104)
(1 , the number of queries.
10^4)
(1
• Each of the nextqq kk
q lines contains a≤single integer ≤(1≤k≤n)
k (1 ≤ k ≤ n), representing
10^5)
(1
the length of the subsequence to consider
q in the query.
≤ ≤
10^4) k
Output
≤
For each query, print the maximum gcd of any increasing n)subsequence of lengthkkk in
the array aa 00 0if there are not any increasing subsequences of
a on a new line or print
length kk
k.
Samples
Input Output
6 6
2 6 4 9 6 12 3
5 12
2 0
3 2
1
6
4
Input
N (1 ≤ N ≤ 105 ), the length of
N(1≤N≤105)N
The first line of the input contains a single integer
the array. (1
\leq
The second line contains NN N A1,A2,A3,…,ANA_1,
N space-separated integers A1 , A2 , A3 , … , A(0≤Ai≤103)
N , (0 ≤
3
\leqA_2,
Ai ≤ 10 ), representing the number of steps Shakib can move backward or (0 forward
from ithi^{th}
ith index. A_3,\ldots,A_N \leq
10^5)
A_i
\leq
Output 10^3)
Print "Yes" if Shakib can reach theNthN^{th}
N index from the1st1^{st}
th
1 index, otherwise print "No"
st
(without quotes).
Samples
Input Output
10 Yes
2 0 1 3 0 4 1 1 0 0
Let's break down Shakib's journey step by step to see how he can reach the 10th10^{th}
10th index:
1. Start at index 1: Shakib can move forward 2 steps to index 3.
Input
T(1≤T≤15)T
Input starts with an integer T (1 ≤ T ≤ 15), denoting the number of test cases.
(1
Each case starts with a blank line and four integers
\leq n(1 ≤ n ≤ 105 ), m(0 ≤ m ≤
n(1≤n≤105),m(0≤m≤106),A(1≤A≤n)n( 1
6
10 ), A(1 ≤ A ≤ n) and B(1≤B≤n)B . n, m,\leq
B(1 ≤ B ≤ n)n,m,An,
T A andBBB represents number of
(1
cities, number of road, starting m, ncity.
\leqcity and destination
\leq
15) A \leq
Then mmm lines follow. Each line
B contains three integersu(1≤u≤n),v(1≤v≤n)u(1
u(1 ≤ u ≤ n), v(1 ≤ v ≤ n)
10^5),
and w(1≤w≤1)w(1
w(1 ≤ w ≤ 1).(u,v)
(u, v)
\leqrepresents undirected \leq link from uu
m road city vv
uwwto v . w
\leq distance from
represents (u, uu
un)to vv
v. u
(0\leq
w v) m \leq
guaranteed that the sum of the values ofmm
It is \leq m across
n),all test cases in the test does
6
\leq
not exceed
1) 2.1062.10^6
2.10 . v(1
10^6),
A \leq
Output (1 v
\leq
\leq
For each case, print YESYES
Y ES and minimum travel distance betweenAA A andBB B if there is a
A n)
way to travel fromAA A toBB
B , otherwise printNONO
NO and minimum number of roads need
\leq
to build to connect those two city. n)
Samples
Input Output
2 YES 2
5 4 1 5 NO 1
1 2 1
2 5 1
3 4 1
Input
First line of the test case contains two space separated integersnn
n andqqq — represent
the size if the string ss
s and number of queries.
Next qq
q lines of the each test case contains a single integer xx
x.
≤ n, q ≤ 105
11≤n,q≤1051\le
n,
1≤x≤n∗(n+1)21\le
n∗(n+1)
1q\le10^5
≤x≤ 2
x\le\Large\frac{n
*
Output
(n+1)}
{2}
countcount
In each query you have to print a single integer count— represent number of
characters in the xthx^{th}
xth lexicographically smallest substring of ss
s.
Samples
Input Output
3 3 1
2 1
3 3
6
Samples
Input Output
4 2 8
1 2 9 4 26
2
4