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

Diu Unlock The Algorithm Fall 24 Preliminary Mock

Mock test algorithm problems in daffodil International University

Uploaded by

shafinahmed757
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
241 views

Diu Unlock The Algorithm Fall 24 Preliminary Mock

Mock test algorithm problems in daffodil International University

Uploaded by

shafinahmed757
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

DIU Unlock the Algorithm

Programming Contest 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.

Be fair, be honest. Plagiarism will result in disqualification. Judges’ decisions will be


final.

Notes
There are 9 challenges in this contest.

Please make sure this booklet contains all of the pages.

If you find any discrepencies between the printed copy and the problem statements in
Toph Arena, please rely on the later.

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 2 of 17


A. Exponential Factorial
In the last season we learned about an uncommon mathematical term named
“Tetration”. In this season we will learn another interesting topic.

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}

The explanation of calculating Exponential Factorial of 33


3 is given bellow:

Your tasks is to find the exponential factorial of 44


4.

Input
There is no input for this problem.

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 3 of 17


Output
FF
You have to print a single integer number FFF
. Here, F represents the value
of exponential factorial of 44
4.
N.B: Don’t forget to print newline at the end.

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 4 of 17


B. Treasure Hunt
You find yourself on a journey through a treasure-laden 2D square grid, with each cell
holding its own riches. Starting from the top-left (1,
cell (1, 1), your objective is to
(n,n)
traverse to the bottom-right cell 1) right or down at each step.
(n, n), moving only
(1,about whether to collect the
(n, to make choices
However, there's a twist: you have
n) past it.
treasures in each cell or simply move 1)

Here's the catch: if you decide to collect treasures from cells


(x1,y1),
(x 1 , y1 ), (x2 , y2 ), (x3 , y3 ), ..., (xk , yk ) in sequence, you magically get some
(x2,y2), treasures equal to the Manhattan distance between consecutive cells:
additional
(x3,y3),...,
k
∑i=2k∣xi−xi−1∣+∣yi−yi−1∣\sum_{i=2}
∑ i=2 ∣xi − xi−1 ∣ + ∣yi − yi−1 ∣
(xk,yk)
^{k}
(x_1,
Your
|y_1),ultimate goal is to maximize the total number of treasures collected, ensuring
that
x_i you gather treasures from at least two different cells along the way.
(x_2,
-y_2),
x_{i-1}|
Input
(x_3,
+
y_3),...,
The first line contains a single integernn n(2≤n≤500)
(2 ≤ n ≤ 500), denoting the side length of
|(x_k,
the
y_i square grid. (2
y_k) \leq
-Each of the nextnn n lines containnn n integers,
y_{i-1}| n describing the treasures of each cell. The
number of treasures in each cell is at least 11 109 .
1 and does not exceed 10910^9
\leq
500)
Output
Output a single integer representing the maximum number of treasures you can
(n,n)
collect while traversing from cell (1, 1) to cell (n, n), adhering to the given rules.
1) (n,
(1, n)
Samples
1)
Input Output
4 32
3 3 3 3
2 3 4 5
3 2 1 3
4 5 2 5

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 5 of 17


C. Fortitude 9.8
Disaster strikes the Defense Force exam grounds! A Honju, a colossal Kaiju (a monster),
has taken down the surveillance drones. Vice Captain Hoshina is desperately analyzing
the remaining intel – a power grid displaying the current threat levels of Kaiju within
the exam zone. Think of this grid as a special kind of list where the last number
connects back to the first, like a looped circular array.

Two critical power levels stand out:

1. The maximum power level – the monstrous power of Kaiju No. 8 (Kafka Hibino)!

2. The second-maximum power level – the destructive force of the Honju!

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.

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 6 of 17


Samples
Input Output
5 1
2.7 8.9 1.3 7.2 5.4

Input Output
9 3
4.2 8.7 7.9 3.1 2.8 1.4 9.5 5.0 7.1

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 7 of 17


Input Output

The sample test cases have been visualized for better understanding.

Please do not forget to print a line break (‘\n‘) at the end.

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 8 of 17


D. Transfer Treats: Turning Footballers
into Cash Cows
Profit United FC is renowned football club for its smart transfer strategies. The club's
management excels at buying young, undervalued talent, developing their skills, and
turning them into superstars. The club's primary goal is to maximize profit by buying
players when their market value is low and selling them when their value is high during
future transfer windows.

What is a Transfer Market?


In football, the transfer market is a period during which football clubs can buy and sell
players. There are typically two main transfer windows each year:

1. Summer Transfer Window: Open from June to August.

2. Winter Transfer Window: A shorter period in January.

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

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 9 of 17


\leq
100000
00≤arr[i]≤100000
≤ arr[i] ≤ 10000
arr[i]
\leq
\leq10000
arr[i]
Output
\leq10000
An integer representing the maximum profit that can be achieved. If no profit is
possible, print 00
0.

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.

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 10 of 17


E. GCD
You are given an arrayaa
a consisting ofnn qqq queries, each
n integers. You need to answer
of the following type:

• For a given integerkk


k , find the maximum greatest common divisor (gcd) of any
increasing subsequence of length kk
k in the array aa
a. If there are not any increasing
subsequences of length kk
k , print 00
0.

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

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 11 of 17


F. SHA75
Shakib Al Hasan, the legendary all-rounder, is on a thrilling journey through the ICC
T20 World Cup 2024. This tournament is a series of intense matches, each representing
a milestone in Shakib’s illustrious career. He starts his journey at the very beginning,
aiming to reach the grand finale, which is the last milestone in his path.

His path is represented as an array AA


A of length NN
N , where each element in the array, AiA_i
Ai
denotes the number of steps exactly he can move either forward or backward from his
1st1^{st}
current position. Starting from the 1st index, symbolizing the beginning of the
tournament, Shakib aims to reach the grand finale, represented by the NthN^{th}
N th index.
For each move, he can go fromithi^{th} (i+Ai)
ith position to either forward (i + Ai ), or backward
(i−Ai)
(i (i These strategies are
− Ai ), or stay in the same position, indicating his strategy.
(i
important + be necessary to step
because, in order to reach the final position, it may
-
back to make a better move. A_i)
A_i)
Note: Shakib can't move outside of the array, so if any move takes him outside of the
range 11
1 to NN
N , he can’t take that move.
The ultimate question is, can Shakib navigate through all these challenges and reach
the final, showcasing his determination, resilience, and unmatched skill to the world?
You are tasked with determining if it’s possible for Shakib to reach theNthN^{th}
N th index from
the 1st1^{st}
1st index.
Write a program to print "Yes" if it’s possible to reach to the final match, otherwise
print "No".

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).

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 12 of 17


You can output Yes and No in any case (for example, strings yES, yes, and Yes will be
recognized as a positive response).

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.

2. At index 3: Shakib can move forward 1 step to index 4.

3. At index 4: Shakib can move forward 3 steps to index 7.

4. At index 7: Shakib can move backward 1 step to index 6.

5. At index 6: Shakib can move forward 4 step to index 10.

The given sequence illustrates that it's possible to reach NthN^{th}


the N th index by utilizing
strategic backward move when necessary. Hence, the output is "Yes".

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 13 of 17


G. New roads in Zootopia
There are several cities in the country - zootopia, and there are some roads between
different cities. The government of Zootopia wants to improve the transport system.
They don't want to build new roads between two cities if there is a way to go from city
AA
A to city BB
B otherwise they will build roads. They wants to know that is there any way
to go from city AA
A to cityBB
B , if any then what is minimum traveling distances between
those city otherwise what is minimum number of roads need to build to connect those
cities.

The cities are numbered from 11


1 to nn
n and each road has a cost. There are mm
m roads.

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

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 14 of 17


Input Output
5 4 1
20 0 1 10

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 15 of 17


H. StringOFaaa
After being disappointed with the Mayer Dua cricket team, the problem setter couldn’t
think of any story, so he asked you to solve this problem instead.
′ ′
You are given a stringss
s of lengthnn ′a′'a'
n. It consists of only one lowercase Latin letter a.
For example, aa
a, aaaa
aa, aaaaaa
aaa are valid strings, whilebb
b,abab
, aac are not. You have to answer
abaacaac
qq
q independent queries. In each query, you will be given an integerxx x. You need to find
the total number of characters in the xthx^{th}
xth lexicographically smallest substring of ss
s.

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

The string aaaaaa


aaa has six substrings:aaaaa
, aaaa
, aaaaaaaa
, aa aaaaaa
, aa, aaa. Among them, the second and
third smallest substrings have one character each, and the sixth smallest substring has
three characters.

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 16 of 17


I. World T20 X Team
The T20 World Cup is approaching, and the ICC has listed all players' performances,
which range from11 107 . There are a total of
1 to10710^7 NNN players. The ICC wants to form a
team with XX
X players and maximize the team's performance. The team performance is
calculated as the sum of the absolute differences between all possible pairs of players
in the team. For example, if there are 4 players in a team with performances
(1, 2, 9, 4), the team performance is calculated as: ∣1−2∣+∣1−9∣+∣1−4∣+∣2−9∣+∣2−4∣+∣9−4∣=
∣1 − 2∣ + ∣1 − 9∣ + ∣1 − 4∣ +
2,
∣2 − 9∣ + ∣2 − 4∣ + ∣9 − 4∣ = 26 1-2|
9, ICC seeks your help to determine the maximum
The + team performance for different
4)
numbers of players. |
(1,
You will be given QQQ independent queries. 1-9|
2, +
9, |
Input
4) 1-4|
• The first line contains two integers NN Q (+
N and QQ ≤ N ≤ 2 × 105 , 11≤Q≤N1
22≤N≤2×1052 ≤ Q ≤ N ).
|\leq \leq
7
• The second line contains NNN integers Ai (2-9|
AiA_i
1≤Ai≤1071
1
N ≤ A i ≤ 10 ), representing
Q the
performances of the players. \leq+ \leq \leq
A_i |2 N
• Each of the nextQQ Q lines contains a single integer XXX2≤X≤N2
( 2 ≤ X ≤ N ), indicating
\leq 2-4|
\times\leq
the number of players to form a team. 10^7+
10^5 X
|
Output 9-4| \leq
= N
• For each query, output the maximum possible 26team performance when forming
a team with XXX players.

Samples
Input Output
4 2 8
1 2 9 4 26
2
4

XXX players from the NN


Note: You can choose any total N players. Your goal is to
maximize the team performance.

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 17 of 17

You might also like