You are on page 1of 21

21st IUT Computer Programming

Contest (IUTCPC) 2020

https://toph.co/c/21st-iut-computer-iutcpc-2020
Schedule
The contest will run for 4h0m0s.

The standings will be frozen for the last 40m0s of the contest.

Authors
The authors of this contest are fsshakkhor, IamHot, ishtupeed, jackal_1586, kitorp,
Kryptonyte, shahed95, SilentG, tahmedge, and trojan_king.

Rules
You can use C++11 GCC 7.4, C++14 GCC 8.3, C++17 GCC 9.2, C11 GCC 9.2, Java 1.8, PyPy
7.1 (2.7), PyPy 7.1 (3.6), Python 2.7, Python 3.7, and Python 3.8 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.

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 2 of 21


A. Don't Stair at Me
Believe it or not, the most difficult part of a programming contest is to come up with a
problem that can be solved by anyone who knows how to write a simple print statement.
So when I was tasked to construct such a problem, you can understand that I was in a
pickle. So what I did is, I started walking on a road, scratching my head, brainstorming
different problem ideas. While walking, I encountered my friend Ociz. Ociz has this habit
of babbling about things that he did before. He said, “A few days ago, I encountered a
peculiar stairway. You know I like to skip steps while going up the stairs, don’t you?
Serves as a bit of exercise, as well. So if I go up this stairway, two steps at a time, at the
end of the stairs, I need to take a single step to reach the top landing. If I go up taking
three steps at a time, at the end of the stairs, I need two steps to reach the landing. If I
go up taking four steps at a time, three steps are required at the end. If I take five steps
at a time, four are left. If I take six steps at a time, five are left. If I take seven, six are
left.” So I started thinking one step (pun not intended) ahead: what is the minimum
number of steps that the stairway can have?
In this problem, your task is to print the number of steps in that stairway. Understand
that the bottom floor does not count as a step. However, the top landing can be
considered as a step.

To help you solve the problem here’s a C/C++ code we found on the internet that can be
used to print the answer:

#include <stdio.h>
int main(void)
{
printf("420");
return 0;
}

Input
There is no input to the problem.

Output
Output a single number, denoting the answer to the problem.

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 3 of 21


B. Find the Ship
You will be playing an interactive game in this problem.

The game is played on a square grid. Each cell of the grid is numbered with a pair
, where and are the row and column number .

The grid is covered with water and there is a ship inside it. The ship covers exactly 4
consecutive cells of the grid (either vertically or horizontally). Check the picture below to
get a clear idea:

In this figure, the ship is located on cell to cell .

Initially, you don’t have any information about the grid. You have to find the location of
the ship by performing the following operations:

• You can ask whether a cell contains some part of the ship. To do it, print a
line in the following format:

? r c

In response, you will read a single character S or W, where S means the cell
contains some part of the ship and W means it contains water.
There will be a limitation on the number of queries you can perform, see the
subtasks portion for more details.

• You have to end the interaction by printing the ship location. To do it, print a line in
the following format:

! r1 c1 r2 c2

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 4 of 21


Here, and are the cells that contain the two endpoints of the ship.
You can print them in any order.

Since this is an interactive problem, don’t forget to flush your output while
communicating with the driver program. You may use fflush(stdout) in C++,
system.out.flush() in Java, stdout.flush() in Python to flush the output. If you use
some other programming language, consult its documentation.

Input
In the beginning, you will read an integer , the number of test cases.
Interaction for the first test case will start right after that.

You will read one of the following as a response of query operation (details are already
mentioned above):

• S
• W

Subtasks

• Subtask 1 (35 points): Perform no more than 13 queries for each case.
• Subtask 2 (65 points): Perform no more than 12 queries for each case.

In each subtask, You will get a “Wrong Answer” verdict if you use more queries than
mentioned.

Output
There are two types of output (details are already mentioned above):

1. ? r c
2. ! r1 c1 r2 c2

After printing the ship location, interaction for the next test case will start (if there is
any).

Here is what a possible interaction would look like:

> 2
< ? 1 1
> S
< ? 1 2
> S
< ! 1 1 1 4
< ? 1 1
> W

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 5 of 21


< ? 1 2
> S
< ? 1 3
> W
< ! 1 2 4 2

>indicates what your program reads and < indicates what your program writes. These
symbols are here to make it easy to understand. You do not have to print such symbols
from your program.

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 6 of 21


C. Boom Bot
Raze is a new agent in Valorant Inc. Currently, she is training on how to use Boom Bot.

The training arena is an grid where each cell has a height. We call a cell ground
cell if its height is .

The boom bot is placed on a cell in the grid. In each second, the bot can move to an
adjacent cell whose height is not greater than the current cell. If there are multiple such
cells, the bot picks a cell out of them randomly. If the bot reaches a ground cell, it blasts
off immediately.

Raze has queries to ask. She will place the bot on a cell and wants to know the
expected time required for the boom bot to blast off.

Two cells are called adjacent if they share a side horizontally or vertically.

It is guaranteed that there will be at least one ground cell and no two ground cells
will be adjacent.

Input
First line contains an integer , denoting the number of testcases.

In each testcase, the first line contains two integers and


, denoting the number of rows and columns in the grid respectively.

Each of the next lines contains integers, where each integer


denotes the height of the cell .

Following line contains an integer , denoting the number of


queries.

Each of the next lines contains two integers and ,


denoting the cell where the bot will be placed.

Subtask

• Subtask 1 (25 points):

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 7 of 21


• Subtask 2 (75 points): Original constraints

Output
For each query, you need to print the expected time required for the bot to blast off.

The answer can be written in form where and are relatively prime integers and
.

Output the value of modulo .

Samples
Input Output
1 0
1 3 3
1 2 2 4
3
1 1
1 2
1 3

Input Output
1 4
2 2 3
2 2 0
2 1
3
1 1
1 2
2 2

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 8 of 21


D. Mickey the Magician
Mickey the magician is working on a vaccine for COVID-19. But he is not sure if the
vaccine which is made of potions will pass the high test standards set by our IUT medical
system.

Megaland has many cities. Mickey the Magician is travelling from one city to another
collecting magic potions. His goal is to travel to the farthest city in Megaland collecting
all potions. Every city in Megaland has some amount of magic potions. He travels day
and night.

Amount of potions in city is represented by an array Potions where is the


amount of potion in city . Mickey will go from a city to a city only if , and he will go in
two ways.

During the day: Mickey can go from to the city such that
and is the smallest possible value. If there are multiple such indices , Mickey
can only go to the smallest such index .

During the night: Mickey can go from i to the city j such that
and is the largest possible value. If there are multiple such indices , Mickey
can only go to the smallest such index .

Starting in the day Mickey will continuously go from one city to another travelling
alternatively in day and night. He will not take rest because, come on, we are in the
middle of a global pandemic. Who got time for rest? But Mickey wants to know in
advance if the vaccine made by potions will work or not.

A good city is a city by which you can go to the end of Megaland (the last indexed city) by
moving some number of times (possibly 0 or more than once). Let’s say is the number
of good cities.

To calculate the effect of the potions Mickey first need to modify the potion array by
repeating it times. For example, if potion array = and then the modified
potion array will be .

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 9 of 21


The effect of the vaccine made by potions is the maximum sub-array sum in the modified
array.

Input
First line contain an integer , denoting the number of testcases.

Each testcase will contain an integer , denoting the number of cities in Megaland.
Then for each city , there will be an integer ,
denoting the amount of potions available in that city.

Subtask

• Subtask 1 (25 points):


• Subtask 2 (75 points):

In subtask , sum of over all testcases will not exceed .

In subtask , sum of over all testcases will not exceed .

Output
Output one integer denoting the effect of the vaccine.

Samples
Input Output
1 45
5
5 1 3 4 2

We can reach the end city from cities indexed 1, 2, and 4. So The number of good cities K =
3.

Modifing the potions array by repeating it 3 times will look like, [5, 1, 3, 4, 2, 5, 1, 3, 4, 2, 5,
1, 3, 4, 2]

The Maximum Sub-Array sum for this array is 45.

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 10 of 21


Notes

Sub- array is any continuous part of an array. The length of the sub-array can be 0 and its
sum in that case is 0.

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 11 of 21


E. Christmas in Vikendi
Once upon a time, there was an ancient city called Vikendi. In the city of Vikendi, there
were shops. As Christmas was just knocking on the door, all the shops brought
Christmas trees to sell.

All the shops had decided to sell Christmas trees of different heights. Also, one
particular shop would only sell trees of a particular height. There were citizens in the
city. As the city of Vikendi is very ancient, its society was divided into many classes. All of
the citizens belong to different and unique classes numbered from to . Each
citizen was only allowed to go to a particular segment of the market. In that segment, he
or she would roam around to different shops and buy the tallest Christmas tree. Once
all the citizens bought Christmas trees, they would bring them back and plant them in
front of their houses.

In the city of Vikendi, there was only one road and all the houses were situated beside
the road. Now, a citizen can be evil. An evil citizen would come out of his/her house and
start going right. He/she would steal the Christmas trees from the houses that were
situated on the right side of his/her house if and only if the class level of the house
owner is lower than himself/herself.

You will be given heights of Christmas trees that are sold at different shops in
Vikendi, class level of different citizens and the range of shops that he/she are
allowed to go and finally the sequence of houses that are situated from left to right
sequentially. You need to calculate the sum of total heights of Christmas trees that a
citizen will steal considering he/she is evil. Calculate this sum for all the citizens and
while doing so for a particular citizen, you can safely assume that he/she is the only evil
citizen in the city.

Input
The first line of the input contains one integer - the number of test
cases.

The first line of each test case contains one integer - the number of
shops in the city.

The next line of each test case will contain space separated integers
. The -th of them represents the height of the Christmas
tree that the -th shop sells.

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 12 of 21


The next line will contain one integer - the number of citizens in the
city. The following lines will contain three integers where
represents the class level of the citizen and and represent the range of shops
(inclusive) where the citizen is allowed to go.

Finally, the last line of each test case will have a sequence of integers. The -th of
them denotes the class level of the citizen that resides in the -th house. All the houses
are organized from left to right.

Output
Output integers. The -th of them will be the sum of the heights of the Christmas
trees that the -th person would steal considering he/she was evil.

Samples
Input Output
1 46 46 0 23 0
10
1 2 5 8 23 3 10 7 9 100
5
1 5 6
2 1 7
3 4 8
4 7 9
5 6 10
3 4 1 5 2

Input Output
1 123 0 100 100 0
10
1 100 2 8 23 3 10 7 9 50
5
1 5 6
2 1 7
3 4 8
4 7 9
5 6 10
3 1 4 5 2

Dataset is large, use fast I/O Method.

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 13 of 21


F. Fun With Functions
Let’s define a function :

We know, and . We can write a generalized


form,
, where .

You will be given five integers: , , , , and . Find the value of .


As the answer can be huge, print it modulo .

Input
First line contains an integer , denoting the number of testcases.

Each tescase contains five integers , , , and

For all subtasks, .

Subtask

• Subtask 1 (10 points):


,

• Subtask 2 (30 points):


,

• Subtask 3 (60 points):


,

Output
For each testcase, print the answer in a separate line.

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 14 of 21


Samples
Input Output
4 5
2 3 1 1 100000000 21
2 3 1 3 100000000 15
1 3 1 3 100000000 51
2 3 2 3 100000000

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 15 of 21


G. European Rover Challenge!
The European Rover Challenge (ERC) Space and Robotics Event is a prestigious space-
robotics event combining international competitions of mobile robots with scientific and
technological shows. University teams from around the world build their own Martian
robots, and then take part in competitions similar to the tasks performed by rovers on
the surfaces of Mars and the Moon. This year your university team has been selected to
participate and you are the chief programmer of your team.

This year, the task of the competition is to collect valuable samples from the surface of
Mars. Of course, it is a simulation area designed for the competition and the specifics are
as follows:

1. The planet Mars has been divided into certain Areas of Interest (AoI) where the
valuable samples may be present. There are three possible samples: a rock sample,
a water sample, and a micro-organism sample.
2. The rover robot of your team must travel to these AoIs and collect all the samples
as they are essential to determine whether life is sustainable in Mars.
3. The distances between the AoIs and the location of the samples will be known
beforehand. There maybe multiple roads between two AoIs but no road connects
the same AoI with itself (What’s the point, right?).
4. The battery life of your rover robot is limited and the samples must be collected
using minimum energy.
5. The distance travelled by the robot is directly proportional to the battery life
consumed.
6. The robot will always start from a specific location and will have to carry all the
samples to the retrieval AoI to end the competition.

Given the input parameters of the simulation area, find the minimum distance covered
as output. Assume that it is always possible to carry all the samples to the retrieval
location.

Input
There maybe simulations in the competition and you have to complete
all of them.

Each simulation starts with six integers: , the number of AoIs,


- the number of roads connecting the AoIs,
, the three sample locations and, , the retrieval
location.

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 16 of 21


The next lines each contain three road parameters:
, where and are the connecting ends of the roads and, is the distance between the
end AoIs. The starting location is always ‘1’.

Subtasks

• Subtask 1 (40 points): The roads connecting the AoIs have identical distances.
• Subtask 2 (60 points): The roads connecting the AoIs have variable distances.

Output
Output only one integer for every simulation: the distance travelled by the robot while
collecting all the samples and returning to the retrieval location using minimum battery
energy.

Samples
Input Output
1 6
6 6 3 5 4 6
1 2 1
2 3 1
2 5 1
5 4 1
2 4 1
4 6 1

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 17 of 21


Input Output
2 28
10 11 5 2 7 10 16
1 2 1
1 3 2
2 3 5
3 5 1
3 4 2
5 4 2
4 6 5
6 7 6
6 8 1
8 10 3
8 9 3
10 15 5 7 9 10
1 2 1
1 3 2
2 3 5
4 7 4
3 5 1
3 4 2
2 6 2
5 4 2
4 6 5
6 7 6
6 8 1
7 9 1
8 10 3
8 9 3
6 10 7

Dataset can be large, use fast I/O methods.

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 18 of 21


H. Why the Long Face?
Consider the following figure:

Ciri and her horse Kelpie are standing at point . She needs to go to a coffee bar located
at point . In front of them are the sand region (the shaded region) with width and
the grass region with width . Assume that both the grass region and the sand region
extend towards infinity with the same respective width in both directions. Kelpie can go
twice as fast over the grass than the sand. Ciri wants to ride her horse to reach as fast
as possible.

Given the length of , , and , find out the length of the path that Ciri and
Kelpie will take.

Input
The first line of the input will contain an integer , denoting the number
of test cases.

For each test case, there will be three integers, , , and - as described in the problem
statement.

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 19 of 21


Output
For each test case, print a single value denoting the length of the path followed by a
newline. Absolute errors less than will be ignored.

Samples
Input Output
1 67.0000
40 31 21

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 20 of 21


I. Learning New Algorithms Every Day
Shak is a new programmer and he knows nothing about algorithms. He has made a plan
and decided to learn a new algorithm every day. Saturday and Sunday are specials. He
will learn one extra algorithm these days.

Today is Wednesday. Shak is going to start today. He wants to know how many
algorithms he will learn exactly after N days.

Input
First line contains an integer , denoting the number of testcases.

Each testcase contains an integer , denoting the number of days.

Subtask

• Subtask 1 (10 points):


• Subtask 2 (70 points):
• Subtask 3 (20 points):

Output
For each testcase, print the answer in seperate lines.

Samples
Input Output
3 3
3 5
4 9
7

21st IUT Computer Programming Contest (IUTCPC) 2020 | Toph 21 of 21

You might also like