MIST-IUPC-2019-ProblemSet, Summaries of Programming for Engineers

MIST IUPC 2019 Problemset is here. MIST IUPC 2019 Problemset.

Typology: Summaries

2019/2020

Uploaded on 12/13/2020

subhashis-mollick
subhashis-mollick 🇧🇩

1 document

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MIST Inter University Programming Contest 2019
MIST-IUPC'19
Hosted by MIST
Dhaka, Bangladesh
23rd February 2019
You get 14 Pages
9 Problems &
300 Minutes
Platform Support:
Problem Set By:
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download MIST-IUPC-2019-ProblemSet and more Summaries Programming for Engineers in PDF only on Docsity!

MIST Inter University Programming Contest 2019

MIST-IUPC'

Hosted by MIST

Dhaka, Bangladesh

23 rd^ February 2019

You get 14 Pages

9 Problems &

300 Minutes

Platform Support: Problem Set By:

Contest Rules for MIST IUPC 2019

  1. Solutions to the problems submitted for judging are called runs. Each run is judged as accepted or rejected by the judge, and the team is notified of the result. Only source code should be submitted, not the executables or any other files.
  2. Contest will be held on CodeMarshal online judge. Only this website will be accessible from contestant’s pc. Any attempt to access other websites or the Internet will result in disqualification. Any attempt to tamper with the online judge will also result in disqualification.
  3. A contestant may submit a clarification request to the judges only through CodeMarshal’s clarification system. If the judges agree that an ambiguity or error exists, a clarification will be issued to all contestants. Judges may decide not to answer a clarification at all in which case that particular clarification request will be marked as IGNORED in the CodeMarshal clarification page.
  4. If teams believe that there is something wrong with the judge data they are strongly advised to use the CodeMarshal clarification system to communicate with the judges rather than meeting them in person after the contest.
  5. Contestants are not to converse with anyone except members of their own team and personnel designated by the organizing committee while seated at the team desk. They may not even talk with their team members when they are walking around the contest floor to have food or any other purposes.
  6. While the contest is scheduled for a particular time length (five hours) , the contest director has the authority to alter the length of the contest in the event of any unforeseen difficulties. Should the contest duration be altered, every attempt will be made to notify contestants in a timely and uniform manner.
  7. A team may be disqualified for any activity that jeopardizes the contest such as dislodging extension cords, unauthorized modification of contest materials, distracting behavior or communicating with other teams. The judges can also recommend penalizing a team with additional penalty minutes for their distracting behavior.
  8. 9-12 problems will be posed. So far as possible, problems will avoid dependence on detailed knowledge of a particular applications area or particular contest language.
  9. Rank-list will be frozen in the final hour of the contest. During this period, teams will only get verdict of their own submissions.
  10. Contestants cannot leave the contest arena during the contest without explicit permission from the judges. The contestants are not allowed to communicate with any other contestants (even contestants of the same team) or coaches when they are outside the contest arena.
  11. Teams can bring any number of pages of printed materials with them. They can also bring five additional books. But they are not allowed to bring any electronic devices like calculator, CD, DVD, Pen-drive, IPOD, MP3/MP players, floppy disks, watches(smart, digital, analog) etc. Teams CANNOT bring their own keyboard, mouse etc.
  12. With the help of the volunteers and judges, the contestants can have printouts of their codes for debugging purposes. Passing printout of codes to other teams is strictly prohibited and may cause disqualifications of teams involved.
  13. Teams should inform the volunteers/judges if they don’t get any verdict/reply within 10 minutes of submission/clarification. Teams should also notify the volunteers if they cannot log into CodeMarshal. These sort of complains will not be entertained after the contest.
  14. Codes must not use any system command or use multi-threading. Contestants must not attempt to access any other computers other than their own in the network. Violating these rules may result in disqualification.
  15. Teams using Java should be extra careful about TL and ML, since problems are not tested with Java.
  16. Each team will be given the same machine in the same location during mock and main contest. That’s why, teams are strongly advised to attend the mock. Any issues during mock should be notified to the judges via the clarification system.
  17. Any member of a team, if late, may not be allowed to enter the contest arena after 30 minutes from the starting of the contest.
  18. The decision of the judges is final. IDEs :
    1. CodeBlocks
    2. Geany
      1. IntelliJ Idea
      2. Netbeans Compilers (In CodeMarshal):
    3. C, C++: GCC 8. a. C compile command: gcc -O2 -static filename.c -lm b. C++ compile command: g++ -O2 -static -std=c++11 filename.cpp
    4. Java: JDK 1.8 OpenJDK Java compile command: javac -J-Xmx2048M filename.java

B

Problem B

Input: Standard Input
Output: Standard Output

Mysterious LCM

You will be given an array A of N integers and another integer X. You have to find the minimum length of a subsequence from A such that, the LCM of all the elements in that subsequence is exactly X.

Input The first line of the input contains a single integer T , which denotes the number of test cases. The first line of each test cases contains two integers N and X. The second line of a test case contains N space separated integers of the array A.

Constraints ● 1 ≤ T ≤ 50 ● 1 ≤ N ≤ 50000 ● 1 ≤ Ai , X ≤ 10^18

The sum of N over all the test cases in an input file ≤ 106

Output

For each test case, output a single line in the format “ Case T: D ” without the quotes. Here, T is the case number and D is the desired answer denoting the minimum length of a valid subsequence whose LCM is exactly X. If there is no solution, then print -1 instead.

Sample Input Output for Sample Input

3 8 60 2 9 12 15 16 21 25 40 8 90 2 36 44 49 50 63 64 81 8 138600 40 2200 45 216 175 735 15 36

Case 1: 2 Case 2: - Case 3: 3

Explanation

In our first sample case, the LCM of the elements in the valid subsequence (12, 15) is 60. There is no way to select a valid subsequence of length less than 2.

Warning: Dataset is huge. Please use faster I/O methods.

C

Problem C

Input: Standard Input
Output: Standard Output

Swipe Your Time Away

Bangladesh Association of Problematic Society (BAPS) is about to release their new mobile game SYTA (Swipe Your Time Away). According to the opinion of several game specialists and psychologists, this is going to be one of the greatest addictive game in the history of mankind. This game will ruin the civil society. Students will drop out of schools, family bonding and relationships will be destroyed, people will only swipe their time away just playing SYTA day and night.

SYTA is a board game played on N by M board ( N rows and M columns). The left uppermost cell is numbered as (1, 1 ) and the right lowermost cell is numbered as ( N , M ). Each cell contains exactly

one ball. The colors of these balls are of different types. There are five colors and they are: 1. Red 2.Green 3.Blue 4.Yellow and 5. Purple. The goal of the game is to determine the largest Cross shape with the same color within the board. Formally, cell ( x , y ) is a center of a Cross shape if it has the

following properties:

  1. In xth^ row all the balls from column y 0 to y 1 are of same color
  2. In yth^ column all the balls from row x 0 to x 1 are of same color
  3. x 0 < x < x 1
  4. y 0 < y < y 1
  5. The size of that Cross shape is, D = ( x (^) 1 − x 0 ) + ( y (^) 1 − y 0 ) + 1

We are looking for someone who can crack down this devastating game. All you need to do is to find out the size of the largest Cross shape in shortest period of time. If you can do so, world will be saved, and in return we will gift you one colorful balloon.

In the first test case, there are 2 Cross shapes.

cell (2,2) and (3,5) are the center of these Cross and the size of these cross shapes are 7 and 8 respectively.

So, the largest size is 8.

Input

Input starts with an integer T denoting the number of test cases. Each of the test cases starts with two integer N and M denoting the number of rows and columns in the board. Next, there will be N lines of inputs each containing M space separated integers. The jth^ integer of the ith^ line is Cij , representing

the color of ball in the cell numbered ( i , ) j

D

Problem D

Input: Standard Input
Output: Standard Output

DarkCity, CrimsonCity of FlightLand

Flightland is a wonderful country. There are N cities in Flightland. A city’s position can be determined

by 2D coordinate system. You can go from any city to another city using an airplane.

Say an airplane is departed from City P and landed on City Q. City P ’s coordinate is (Xp, Yp) and

City Q ’s coordinate is (Xq, Yq). Here is some calculation for air travel costs for a single flight:

● The airplane chooses a path from City P to City Q according to your choice. But remember, you have to choose a path such that the length of the path is always an integer. It’s for the safety of the passengers. You don’t have to worry much about that. And you can ignore the altitude of the airplane. So, you can think this path to be a straight line, polyline or curve on a 2D plane. Say the length of the path is L. Example: Say, the airplane took-off from (0, 0) and landed on (5, 5). You can not choose the straight line between these points, as the length of the path will not be an integer. Rather you can choose a path from (0, 0) to (1, 0) to (1, 2) to (5, 5) with straight lines. In that case, the length of the path will be 8 , which is an integer. But these turning points of the airplane can also be non-integer coordinates and also the paths can be arbitrary curves too. Like you can choose an arc from (0, 0) to (5, 5) such that the length of the arc is 11 , 10 , 9 etc. Simply, you can choose any route plan as your choice. This can be a straight line, polyline, curve etc. But the length of the path must be an integer. ● The airplane has a mass of A , including the mass of all passenger, the luggages and some other stuffs. It’s basically the mass of the whole plane except its fuel’s mass. ● The airplane starts with F amount of fuel, which is a positive real number. You can choose the amount of fuel for the journey. So, the total mass of the airplane is T = A + F. It is obvious that the airplane needs sufficient amount of fuel to complete the flight. Otherwise the airplane will crash and you are never going to meet your destination. ● For a unit distance of flight, Airplane consumes TotalMass / D amount of fuel. So, you can see the plane is constantly(in this case, per unit distance) losing its fuel thus its total mass. Here, D is the consumption rate which is constant. ● Price of a unit amount of fuel is C. ● There is some extra base cost for take-off, landing, airport fee etc. Say this extra cost is B. ● So, the total cost for a single flight is F × C + B. ● Size of airplane and airports are negligible. You can think them as points. ● You can not do a mid-air refueling. That means you start your flight with F amount of fuel and you have to finish your flight using that fuel only.

● Each flight is independent, and they will be operated with a brand new airplane. So, if you have some fuel remaining on your last flight, you can not use it in this flight. Besides, the initial amount of fuel used for each flight can be different too. ● You can take flights only from one city to another, and every city has an airport. Note that, airports are situated only in the cities.

Here is an example of fuel consumption. Say, L = 5, A = 100, D = 100.

If you choose F = 10, then here is the fuel consumption history:

When airplane travels 0 unit distance, means when the airplane will take-off, TotalMass = 100 + 10 =

110. So, in the next unit distance airplane will need 110 / 100 = 1.1 unit of fuel.

When airplane travels 1 unit distance, TotalMass = 100 + 8.9 = 108.9. So, in the next unit distance

airplane will need 108.9 / 100 = 1.089 unit of fuel.

When airplane travels 2 unit distance, TotalMass = 100 + 7.811 = 107.811. So, in the next unit

distance airplane will need 107.811 / 100 = 1.07811 unit of fuel.

When airplane travels 3 unit distance, TotalMass = 100 + 6.73289 = 106.73289. So, in the next unit

distance airplane will need 106.73289 / 100 = 1.0673289 unit of fuel.

When airplane travels 4 unit distance, TotalMass = 100 + 5.6655611 = 105.6655611. So, in the next

unit distance airplane will need 105.6655611 / 100 = 1.056655611 unit of fuel.

When airplane travels 5 unit distance, The airplane will land and 4.608905489 unit of fuel will remain

the airplane.

You live in DarkCity and your dream girl/boy lives in CrimsonCity. You want to go from DarkCity to

Crimson city. You have to bear the full cost for each flight. Can you calculate the minimum cost to

visit your dream girl/boy?

Input

Input starts with an integer, TC , denoting number of test cases. For each test case, the first line

contains 5 integers N , A , B , C , D denoting number of cities in Flightland, mass of airplane, extra base

cost per flight, fuel cost, consumption rate. The next N lines contain 2 integers denoting the

coordinates for each city. First city is always DarkCity and the last city is always CrimsonCity.

Output

For each test case print a single line containing a real number that denotes the minimum cost.

Your answer will be accepted if its relative or absolute error does not exceed 10 −9.

Mathematically, if your answer is A and the jury's answer is B, then your answer is accepted if and

only if (^) max | A^ (1, |−^ BB ||)≤ 10−9.

E

Problem E

Input: Standard Input
Output: Standard Output

Consecutive Letters

You are given a string S containing only uppercase English letters. There are Q queries. Each query can be of two types,

1 i : Find the maximum size of the segment [b, e] where 0 ≤ b ≤ i ≤ e < |S| and substring S[b...e] contains only the letter S[i]. A Substring is a contiguous sequences of characters in a string. ● 2 i : Change the character in index i with the character ‘ # ’.

For both type of queries, S[i] will not contain the character ‘#’.The characters of the string are indexed from 0.

Input

The first line contains number of test cases T (1 ≤ T ≤ 25). For each test cases, the first line contains the string S (1 ≤ |S| ≤ 200000). The 2nd^ line contains number of queries Q (1 ≤ Q ≤ 100000). Each of the next Q lines contains one query in the format mentioned in the problem statement.

Output

For each test case, first print the test case number and output of every query of type 1 in a single line.

Sample Input Output for Sample Input

2 AABBBCCCC 5 1 0 2 1 1 0 2 2 1 3 XXYYY 3 1 3 2 3 1 2

Case 1: 2 1 2 Case 2: 3 1

Warning: The input file is huge, please use fast I/O.

F

Problem F

Input: Standard Input
Output: Standard Output

Palindromadness

You'll be given a string S of length N , containing lowercase English letters only. Let's define a function f(x) over this string. f(x) denotes the number of quadruple of indices (i, j, p, q) where,

  1. A = S[i...j] and B = S[p...q] are substrings of string S where 1 ≤ i, j, p, q ≤ N , i ≤ j and p ≤ q. That is, A and B can partially overlap, or contain each other, or be completely separate or be the same substrings in string S.
  2. Both A and B are palindromes.
  3. A is a substring of B
  4. Length of A is equal to x.

Substrings are contiguous sequences of characters in a string. Palindromes are strings, that read the same forwards and backwards.

You'll also be given a base and a mod value. You'll have to print ( ∑ ( i ).

n i =

f (^) * base ni ) % mod

Input

First line of input will contain an integer T (1 ≤ T ≤ 10^5 ) , denoting the number of test cases. First line of each test case will contain three integers N, base (1 ≤ base ≤ 10^9 ), mod (1 ≤ mod ≤ 2 × 109 ). Following line will contain a string of length N , containing lowercase English letters only. Summation of N over all test cases will not be greater than 106.

Output

For each test case, first print the case number, starting with 1, followed by the answer for that case. Check the sample I/O for more details.

Sample Input Output for Sample Input

5 13 100 999 welcometomist 7 1000 1000000000 topspot 11 23167 21898192 abbabobaxab 21 123456 123456789 amanaplanacanalpanama 32 72817 728917897 bobxyxthehtxyxbuildercantfixyxit

Case 1: 21 Case 2: 2000001 Case 3: 4104229 Case 4: 85459969 Case 5: 721428038

Explanation

The f(x) function(1 based) for the first three cases are given below. Case 1: { 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } Case 2: { 28, 0, 3, 0, 2, 0, 1 } Case 3: { 97, 2, 5, 1, 2, 0, 0, 0, 0, 0, 0 }

H

Problem H

Input: Standard Input
Output: Standard Output

Triangle Inside Rectangle Inside Pentagon

So last day I was teaching geometry to my cousin. He is interested in learning geometry but could not keep his attention. So I tried to make things interesting by asking him to give me any geometric challenges he can think of.

All was going good, but then I started to teach him regular convex polygon. A regular convex polygon is a polygon that is equiangular (all angles are equal in measure), equilateral (all sides have the same length) and all interior angles are strictly less than 180 degrees. Like equilateral triangle, square and so on. But then he gave me a challenge:

- Brother, can you fit a equilateral triangle in a square

  • Ok, here it is. - Ok, now fit the square in a regular convex pentagon.
  • Umm, ok, this might take some time!
  • Then fit that in a regular convex hexagon.
  • Stop!
  • Then fit that in a regular convex heptagon.
  • Please Stop!! - Also make them as small as possible
  • ಠ_ಠ You will be given the length of side of the equilateral triangle s and N. You have to print the area of minimum regular convex N -gon, which will contain a regular convex N-1 -gon(if N > 3), which will contain a regular convex N-2 -gon(if N > 4), which will contain a regular convex N-3 -gon(if N > 5 ) and so on. Finally, a square( 4 -gon)(if N > 3) will contain the triangle.

Input

The first line contains an integer T ( T ≤ 10^5 ), denoting the number of test cases. Each test case contains two integers N ( 3 ≤ N ≤ 10^5 ) and s ( 1 ≤ s ≤ 10^3 ).

Output

For each test case, print a single line containing a real number that denotes the minimum area. Your

answer will be accepted if its relative or absolute error does not exceed 10 −4. Mathematically, if your

answer is A and the jury's answer is B, then your answer is accepted if and only if

max | A^ (1, |−^ BB ||)≤ 10−^.

Sample Input Output for Sample Input

3 3 1 5 4 10 1

I

Problem I

Input: Standard Input
Output: Standard Output

Fibonacci Power Sum

The fibonacci series is defined as below:

fib(0) = 0, fib(1) = 1

fib(n) = fib(n-1) + fib(n-2) for n > 1

Given three integers N , C and K, find the summation of the following series:

fib(0)K^ + fib(C)K^ + fib(2C)K^ + fib(3C)K^ + … + fib(NC)K*

Since the answer can be huge, output it modulo 1000000007 ( 109 +7).

Input

The first line contains an integer T , denoting the number of test cases. Each test case contains three space separated integers in the order: N , C and K.

Constraints

● 1 ≤ T ≤ 100 ● 0 ≤ N ≤ 1015 ● 1 ≤ C, K ≤ 10

Output

For each test case, output a single line in the format “ Case T: D ” without the quotes. Here, T is the case number and D is the desired answer denoting the sum of the series.

Sample Input Output for Sample Input

5 10 1 1 5 2 2 3 3 4 1000000007 7 9 996969696969696 9 6

Case 1: 143 Case 2: 3540 Case 3: 1340448 Case 4: 880410497 Case 5: 689328397