You are on page 1of 10

Intra SUST Programming Contest

2020 Preliminary 1

https://toph.co/c/intra-sust-2020-preliminary-1
Schedule
The contest will run for 2h30m0s.

Authors
The authors of this contest are anis028, Apu_hasan, arnab0sust, avivilla, foyaz05,
humayan7711, jubair_123, manetsus, Maruf_75, mridul_sust, ovis96, Rajan_sust,
saif_sust, shahriarsust13, shourov.sust, and Wiz_Khalipha.

Rules
This contest is formatted as per the official rules of ICPC Regional Programming
Contests.

You can use Bash 5.0, Brainf*ck, C# Mono 6.0, C++11 GCC 7.4, C++14 GCC 8.3, C++17 GCC
9.2, C11 GCC 9.2, Common Lisp SBCL 2.0, Erlang 22.3, Free Pascal 3.0, Go 1.13, Haskell
8.6, Java 1.8, Kotlin 1.1, Node.js 10.16, Perl 5.30, PHP 7.2, PyPy 7.1 (2.7), PyPy 7.1 (3.6),
Python 2.7, Python 3.7, Ruby 2.6, and Whitespace in this contest.

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


final.

Notes
There are 6 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.

Intra SUST Programming Contest 2020 Preliminary 1 | Toph 2 of 10


A. Find The Pairs
You are given a non-negative integer N. A pair(a, b) is called atomic if (a | b) = N (“|”
means bitwise OR). You have to find number of such atomic pairs. Here, (a | b) and (b | a)
are considered as different pairs. For the first sample test case, for N = 2 , atomic pairs
are (2 , 0) , (0 , 2) , (2 , 2).

Input
First line will contain number of test case T. Each subsequent line will contain a number
N.
1 ≤ T ≤ 1000
1≤N≤

Output
For each test case output one integer. Number of atomic pair for N.

Samples
Input Output
1 3
2

Intra SUST Programming Contest 2020 Preliminary 1 | Toph 3 of 10


B. Story of A4
You all know the A4 papers. But do you know why are they called A4 or why are they so
special? Well, there’s a very interesting fact about these. If you cut an A4 paper in half
(the larger side should be cut), you’ll get two mini versions of A4 papers. That means the
ratio of height to width of the small papers will be the same as the original A4 paper
.

Since this is called A4, maybe you can guess this is a part of a series of A papers. Yes, you
are right ! The paper with 1 square meter of area is called A0. If you cut this into half, you’ll
get two A1 papers. And from one A1 you’ll get two A2, from one A2, you’ll get two A3,
from one A3, you’ll get two A4 and so on… Please refer to the figure to clearly
understand how you should make the cuts. So, now you know the story behind the so
familiar name A4.

We want to make a name to size calculator. And you can now forget the traditional size
of an A0 paper (1 square meter area). This may vary now.

You are given the width ( ) of an paper in centimeters. You need to find the sum
of the dimensions (in centimeters) of an paper.

Intra SUST Programming Contest 2020 Preliminary 1 | Toph 4 of 10


Consider the smaller side as width and larger side as height.

Input
The input starts with an integer T (T ≤ 100 ) denoting the number of test cases.
Each of the next T lines contains three integers m, and n (0 ≤ n ≤ m ≤ 70, 1 ≤ ≤
1000 ).

Output
For each case, output a single line containing a floating point number denoting the sum
of the width and the height of an paper. Print exactly 4 digits after decimal point.

Please refer to the sample input/output section for better understanding.

Samples
Input Output
2 102.4264
3 15 0 168.9949
5 35 3

Intra SUST Programming Contest 2020 Preliminary 1 | Toph 5 of 10


C. Restore Magic Rectangle
Random coder boy Kiny once had a rectangle (2D grid) as quarantine gift. Every random
people have something like that, what is the specialty then? The main specialty of the
grid is for every row and column all the values are unique.

More formally suppose the grid size is , which means the grid has rows and
columns.
For every row i, 1 ≤ i ≤ n, let is the set of all values in the row i then = m (size of
is m). Similarly, for every column j, 1 ≤ j ≤ m, let is the set of all values in the
column j then = n.

But this was Kiny’s rectangle before last night. Yesterday night, Kiny suddenly woke up
by the barking of the street dog near his house. He assumes that someone (thief)
entered his room and shuffled his rectangle. So that the order of the rectangle is not the
same as before. For this, the main specialty of the grid might be lost. But he is desperate
to have its specialty back. So he came to you to solve his problem.

Input
The first line will contain T ( number of test cases, T ≤ ). For each test case there will
be n m ( which means the grid has n rows and m colums, ≤ ) and for following
n lines, each will contain m numbers (1 ≤ each number ≤ ) describing the grid. As
mentioned earlier in the problem, this grid might have lost its speciality.

Output
For each test case output n lines, for each n lines there will be m integers which indicates
the special rectangle. There can be multiple possible solutions, any of them would be
enough.

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

Note: Use Faster I/O.

Intra SUST Programming Contest 2020 Preliminary 1 | Toph 6 of 10


D. 1 March 2023
Don’t waste your time on the title. You will be given two vectors and

. Let and form angles and with the positive - axis

respectively. Note that the magnitude of is defined by .

We expect a third vector from you. And you have to make sure 2 properties
of .

1. The magnitude of should be equal to the product of magnitudes of and .


2. Angle formed with the positive - axis of should be equal to the sum of and
.

Input
The first line will contain an integer ( ) denoting the number of test
cases. For each test case there will be exactly one line that contains four integers

. The values of will be in the range .

Output
Print and in a line for each test case. It is guaranteed that and will be integers.

Please refer to the sample input/output section for better understanding.

Samples
Input Output
2 0 10
2 0 0 5 0 -2
1 1 -1 -1

Intra SUST Programming Contest 2020 Preliminary 1 | Toph 7 of 10


E. Sayadpur City
Bob wants to visit a new country called sayadpur. There are N cities(1, 2, 3….., N) in
sayadpur, and they are connected by n-1 undirected roads. You can go from one city to
any other city using these roads. Each city except city 1 is directly connected with at
most two cities. Bob wants to start his journey from a city and then move to any adjacent
city. In his journey, he does not want to visit a city twice. For visiting a city he has to pay a
cost. Suppose he visits total “k” cities and the cost of those cities are .
The overall cost will be the bitwise “or” of those costs ( ). You have to
find the maximum overall cost.

Input
First-line there is a number ( ). Each of the next N-1 lines contains two
integers u and v (1 ≤ u,v ≤ n, u≠v), denoting an edge connecting vertex u and vertex v.
Next line contains N integers . The first element is the cost of city number
1, the second element is the cost of city number 2 city and so on.
(1 ≤ ≤ 2047, 1 ≤ i ≤ N)

Output
Output one integer, the maximum overall cost.

Samples
Input Output
3 7
1 2
1 3
1 2 4

Intra SUST Programming Contest 2020 Preliminary 1 | Toph 8 of 10


F. Beautiful Subsequences
You are given a string. You have to find the number of beautiful subsequences in the
string.

A subsequence is a sequence of characters that can be derived from a string by deleting


some characters without changing the order of the remaining characters. For example,
“abba” is a subsequence in “bacbdeba”, but “bbaa” is not.

Beauty of a character is the sum of positions of that character in the string. For example,
beauty of ‘a’ in the string “bacbdeba” is , becuase the positions of ‘a’ in the
string are and . Beauty of a subsequence is the sum of beauties of the characters in
the subsequence. For example, the beauty of the subsequence “aa” of string “bacbdeba”
is .

A subsequence is beautiful, if both of the following conditions hold.

1. If you include a character to a subsequence, you should include all of its occurences.
For example, for the string “bacbdeba”, “babba” can be beautiful (if it obeys the other
condition), but “ba” can not be. Because, if ‘b’ is chosen to be in the subsequence, all
occurrences of ‘b’ in the string should be in the subsequence, same for ‘a’.
2. Beauty of the subsequence should be at least M.

You are given a string of length N. Can you find how many beautiful subsequences can be
derived from the string?

Input
The first line of the input contains two integers and . The next line contains the
string. The string contains lowercase English letters (‘a’ to ‘z’ ) and digits (‘0’ to ‘9’ ).

Output
Print an integer in a single line denoting the number of beautiful subsequences.

Intra SUST Programming Contest 2020 Preliminary 1 | Toph 9 of 10


Samples
Input Output
2 2 1
aa

Input Output
3 5 2
a1a

For the first case, “aa” is the only beautiful subsequence.


For the second case, “aa” and “a1a” are the two beautiful subsequences

Intra SUST Programming Contest 2020 Preliminary 1 | Toph 10 of 10

You might also like