Professional Documents
Culture Documents
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.
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.
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.
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:
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
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).
> 2
< ? 1 1
> S
< ? 1 2
> S
< ! 1 1 1 4
< ? 1 1
> W
>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.
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.
Subtask
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
.
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
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.
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 .
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
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]
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.
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.
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
Input
First line contains an integer , denoting the number of testcases.
Subtask
Output
For each testcase, print the answer in a separate line.
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.
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
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.
Samples
Input Output
1 67.0000
40 31 21
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.
Subtask
Output
For each testcase, print the answer in seperate lines.
Samples
Input Output
3 3
3 5
4 9
7