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

Problem Set

The document outlines the 2024 Asia Dhaka Regional Contest of the International Collegiate Programming Contest (ICPC) hosted by Daffodil International University. It includes multiple programming problems, each with specific requirements and input/output formats, covering topics such as graph theory, bitwise operations, combinatorial counting, and string manipulation. The contest will take place on December 7, 2024, and consists of 12 problems to be solved within 300 minutes.

Uploaded by

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

Problem Set

The document outlines the 2024 Asia Dhaka Regional Contest of the International Collegiate Programming Contest (ICPC) hosted by Daffodil International University. It includes multiple programming problems, each with specific requirements and input/output formats, covering topics such as graph theory, bitwise operations, combinatorial counting, and string manipulation. The contest will take place on December 7, 2024, and consists of 12 problems to be solved within 300 minutes.

Uploaded by

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

International Collegiate Programming Contest (ICPC)

2024 Asia Dhaka Regional Contest


Onsite Round

Hosted By
Department of Computer Science and Engineering,
Daffodil International University

Supported by

07 December, 2024
You get 16 Pages, 12 Problems & 300 Minutes
ICPC Asia Dhaka Regional Contest, 2024
Hosted by: Daffodil International University

Problem A
Are the Nodes Reachable?

You are given a directed acyclic graph consisting of N nodes, numbered from 1 to N, and M directed edges.
Your task is to answer Q queries about reachability between nodes.
For each query, you will be given two nodes, U and V:
● If node V is reachable from node U through existing roads (directed edges), you should output 0 as
no additional road is required.
● If V is not reachable from U, you are allowed to build one temporary edge between any two nodes in
the graph to make V reachable from U. After the query is answered, this road will be destroyed.
You must determine the minimum cost of constructing this road, if needed. The cost of building a road
between node 𝑋 and node 𝑌 is defined as |𝑋 − 𝑌|, i.e., the absolute difference between their node labels.

Input
The first line will contain a single integer 𝑇(1 ≤ 𝑇 ≤ 100). First line of each test case will contain two
4 6
integers 𝑁 (1 ≤ 𝑁 ≤ 10 ) and 𝑀 (1 ≤ 𝑀 ≤ 10 ) where 𝑁 denotes the number of nodes in the graph and 𝑀
denotes the number of directed edges.
Each of the next 𝑀 lines will contain two integers 𝑈 and 𝑉 (1 ≤ 𝑈, 𝑉 ≤ 𝑁, 𝑈 ≠ 𝑉) denoting a directed edge
6
from 𝑈 to 𝑉. Next line of the input will contain a single integer 𝑄(1 ≤ 𝑄 ≤ 10 ) denoting the number of
queries. Next 𝑄 lines will contain two integers 𝑈 and 𝑉 (1 ≤ 𝑈, 𝑉 ≤ 𝑁) for which the answer of the query
needs to be processed.
5 6 6
It is guaranteed that, Σ𝑁 ≤ 2 × 10 , Σ𝑀 ≤ 10 , Σ𝑄 ≤ 10 across all test cases.

Output
For each test case, you need to print the case number on the first line in the format “Case T:” where T is the
case number. Each of the next Q lines should contain one integer, the answer to the query.

Sample Input Output for Sample Input


1 Case 1:
4 4 1
1 2 1
1 3
1 4
4 3
2
2 3
2 4
It is recommended to use fast input/output methods due to the large input size.

2
ICPC Asia Dhaka Regional Contest, 2024
Hosted by: Daffodil International University

Problem B
Yet Another Crossover Episode

Pebae has an integer array 𝑎1 , 𝑎2 , ···, 𝑎𝑛 . Please help her find the maximum of 𝑔𝑐𝑑(𝑎𝑖 ⊕ 𝑎𝑗 , 𝑎𝑖 & 𝑎𝑗) over

all 1 ≤ 𝑖, 𝑗 ≤ 𝑛. Additionally, you need to count the total number of pairs (𝑖, 𝑗) that achieve this maximum
value.

Here, 𝑔𝑐𝑑(𝑥, 𝑦) is the greatest common divisor of 𝑥 and 𝑦, 𝑔𝑐𝑑(𝑥, 0) = 𝑥 for 𝑥 ≥ 0, ⊕ is the bitwise XOR
operator, and & is the bitwise AND operator.

Input 5
The first line of the input contains an integer 𝑡 (1 ≤ 𝑡 ≤ 10 ) — the number of test cases.
19
The first line of each test case contains an integer 𝑛 (1 ≤ 𝑛 ≤ 2 ).
The second line contains 𝑛 space-separated integers 𝑎1 , 𝑎2 , ···, 𝑎𝑛(0 ≤ 𝑎𝑖 < 16𝑛) .
20
It is guaranteed that the sum of 𝑛 over all test cases does not exceed 2 .

Output
For each test case, output two space-separated integers — the maximum value and the number of pairs
that achieve this maximum value.

Sample Input Output for Sample Input


4 9 4
4 0 1
1 9 1 9 1 5
1 111 2
0
3
0 0 1
7
12 2 3 0 110 1 69

It is recommended to use fast input/output methods due to the large input size.

Note
In the first test case, the maximum value that can be obtained is 9 for the pairs (2, 2), (2, 4), (4, 2) and
(4, 4).

3
ICPC Asia Dhaka Regional Contest, 2024
Hosted by: Daffodil International University

Problem C
Cut the Stick, Share You Must

Yoda recently noticed his stick is worn out after years of use. Thinking it’s time for an upgrade, he decides
to get a new stick. But the old one holds so many memories that he cannot part with it entirely. Instead, he
plans to cut the stick into pieces, share them with his friends, and keep one piece for himself.

However, he doesn’t want to make the cuts randomly. Being fond of primes and integers, Yoda wants the
stick to be cut into integer lengths such that the GCD of the resulting lengths is a prime number. The stick’s
total length is also an integer.

At first, the task seems simple. But as Yoda starts counting the possibilities, he realizes there are too many
ways to cut the stick. Frustrated, he turns to you and says: "Overwhelmed, I am, with the possibilities. Help
me figure out the answer, will you? Only then, satisfied, I shall be."

More formally, Yoda will give you two integers 𝑛 and 𝑘, where:
● 𝑛 denotes the length of his stick
● 𝑘 is the number of cuts you need to make on the stick.

Your task is to count the number of ways to make exactly 𝑘 cuts Cut Lengths of The
such that the GCD (Greatest Common Divisor) of the lengths of the Positions Stick Pieces GCD
resultant 𝑘 + 1 stick pieces is a prime number. {2, 4} {2, 2, 6} 2
A prime number is an integer greater than 1 and only divisible by 1
and itself. {2, 6} {2, 4, 4} 2

The cuts must be made at integer points along the stick, and each {2, 8} {2, 6, 2} 2
resulting stick piece must have a positive integer length.
{4, 6} {4, 2, 4} 2
For 𝑛 = 10 & 𝑘 = 2, there are 6 valid ways to cut the stick.
Please, refer to the table. We can also see that the order in {4, 8} {4, 4, 2} 2
which you perform the cuts does not matter. {6, 8} {6, 2, 2} 2

Input 5
The first line contains an integer 𝑇 (1 ≤ 𝑇 ≤ 10 ), the number of test cases. Each of the next 𝑇 lines
6
contains two integers 𝑛 and 𝑘 (1 ≤ 𝑘 < 𝑛 ≤ 10 ) .

Output
For each test case, you need to print the number of valid ways to cut the stick in a single line. Since the
9
result can be quite large, output the value of the result modulo 1000000007(10 + 7).

Sample Input Output for Sample Input


4 1
4 1 3
8 2 6
10 2 11
12 3
It is recommended to use fast input/output methods due to the large input size.

4
ICPC Asia Dhaka Regional Contest, 2024
Hosted by: Daffodil International University

Problem D
CatGPT

A group of cats is called a clowder. There are 𝑁 cats living in a street, each of them belongs to exactly one
clowder. The cats are numbered from 1 to 𝑁, and the 𝑖-th cat belongs to clowder 𝑐𝑖.

Sometimes two or more cats with consecutive IDs convince their respective clowders to hang out together
and form one big clowder, where every cat from those old clowders would be a part of this new clowder
even if they were not part of the group of cats who came up with this idea. These types of events can be
described by an interval 𝑒 = [𝐿, 𝑅], where cats 𝐿, 𝐿 + 1, ... 𝑅 convinces their clowders to merge. There are
[
𝑀 such possible events – the i’th can be described by 𝑒𝑖 = 𝐿𝑖, 𝑅𝑖 . ]
For example, let’s assume that there are 5 cats and they belong to clowders A, B, C, A, D respectively. If
cats 2, 3 and 4 convince their respective clowders B, C, A to form a new clowder X, the new clowder X will
consist of cats 1, 2, 3 and 4. Notice that although cat 1 was not one of the cats who convinced its clowder, it
does belong to the new clowder because cat 4 convinced clowder A. This example event can be described
as [2, 4].
A query is defined as an interval of events [𝑥, 𝑦] where 1 ≤ 𝑥 ≤ 𝑦 ≤ 𝑀. For each such query, report the
maximum possible size of a clowder if any number of events in 𝑒𝑥, 𝑒𝑥+1, ···, 𝑒𝑦 were to take place in any
order. The size of a clowder is the number of cats belonging to it.

Please note that each query is independent i.e. one query neither impacts other queries, nor the original
clowders.

Input
The first line contains a single integer 𝑇(1 ≤ 𝑇 ≤ 10) - the number of test cases. 𝑇 test cases follow.
5
The first line of each test case contains a positive integer 𝑁(1 ≤ 𝑁 ≤ 10 ) - the total number of cats. The
following line contains 𝑁 uppercase English letters without any spaces between them. The i’th letter
represents the clowder 𝑐𝑖 of the i’th cat.
5
The next line contains a positive integer 𝑀 (1 ≤ 𝑀 ≤ 10 ) - the total number of events. 𝑀 lines follow, i’th
line contains two integers 𝐿𝑖 and 𝑅𝑖 representing event 𝑒𝑖.
5
The next line contains a positive integer 𝑄 (1 ≤ 𝑄 ≤ 10 ) - the total number of queries. 𝑄 lines follow, i’th
line contains two integers 𝑥𝑖 and 𝑦𝑖 representing a query.
5 5 5
It is guaranteed that, Σ𝑁 ≤ 10 , Σ𝑀 ≤ 10 , Σ𝑄 ≤ 10 across all test cases.

Output
For each test case, print the case number in one line in the format “Case T:”, where T is the test case
number. Then for each query, output the result (maximum possible size of a clowder) in a single line.

5
ICPC Asia Dhaka Regional Contest, 2024
Hosted by: Daffodil International University

Sample Input Output for Sample Input


1 Case 1:
12 12
AABCBBDCEEEE 5
4 7
1 12 4
1 3
3 4
7 8
4
1 1
2 2
2 3
4 4
It is recommended to use fast input/output methods due to the large input size.

Explanation
In the sample I/O above –
● for query 1 ([1, 1]), it is optimal for event 1 to take place. As a result, all of the cats belong to a single
clowder.
● for query 2 ([2, 2]), it is optimal for event 2 to take place. Clowders A and B form a new clowder of 5
cats.
● for query 3 ([2, 3]), it is optimal for all events to take place sequentially. In event 2, clowders A and B
form a new clowder X of 5 cats. In event 3, clowders X and C form a new clowder Y of a total 7 cats.
● for query 4 ([4, 4]), we can choose not to have any events at all. If event 4 was to take place,
clowders C and D would form a new clowder of 3 cats whereas clowder E already has 4 cats.

6
ICPC Asia Dhaka Regional Contest, 2024
Hosted by: Daffodil International University

Problem E
Quasi-binary Representations

Every positive integer has a unique binary representation using only the digits 0 and 1. However, if we allow
digits other than 0 and 1, a number may have multiple valid representations.

For example, the number 4 can be represented in the standard binary system as 100. However, if the digit
2 is allowed, it can also be represented as 20 or 12. Here:
1 0
● 20 represents 2⋅2 + 0⋅2 = 4 + 0 = 4
1 0
● 12 represents 1⋅2 + 2⋅2 = 2 + 2 = 4

These are called quasi-binary representations of a number. Note that, as usual, we do not allow leading
zeros in the representation, so, 020 is not a valid representation.

You are given 𝑛 and 𝑘. Your task is to find the number of distinct quasi-binary representations of 𝑛 using
digits from {0, 1, 2, ···, 𝑘}. Since this number can be large, you need to output its value modulo 998244353.

Input
Input starts with an integer 𝑇 — the number of test cases.
Each test case is described by a single line containing two integers, 𝑛 and 𝑘.

Constraints
● 1 ≤ 𝑇 ≤ 1000
● 1 ≤ 𝑘 ≤ 1000
18
● 1 ≤ 𝑛 ≤ 10

Output
For each test case, print one line containing a single integer, the number of quasi-binary representations
modulo 998244353.

Sample Input Output for Sample Input


3 3
4 2 2
3 3 14
10 10

7
ICPC Asia Dhaka Regional Contest, 2024
Hosted by: Daffodil International University

Problem F
Flowers

In this problem, You will be given a forest. This forest consists of one or multiple directed binary trees.
Nodes of the tree can be black or white. You will reconstruct the forest by executing some queries. Note
that, each edge directs the relation from parent to child and each node will always have at most one parent.
When asked a query, determine the number of unique flower shapes in a tree.

Definitions
● Tree Root: A node with no parent.
● Flower Root: A white node with no parent or a black parent.
● Flower: A flower consists of a Flower Root and all the white nodes that can be reached from the
flower root via directed edges, with no black nodes appearing along the path.
● Unique Flower Shapes: Two Flowers are considered to have the same unique shape if they are
structurally identical, meaning:
○ Both flowers have the same number of nodes.
○ The arrangement of left and right children at every node is the same.

Figure: The flowers are in different shapes.

There will be 𝑁 nodes in the forest. For each node in the forest, you will be given three pieces of
information (Left child, Right Child, and Color of that node). After that, there will be 𝑄 instructions. Each of
the instructions can be any of the two types below. After each query, the vertices will not break the directed
binary tree property.

● 1𝑋𝑌
Let, 𝑅𝑋 = The root of the tree containing the node 𝑋, and 𝐿𝑌 = The leftmost leftless node of the tree
containing the node 𝑌. Add 𝑅𝑋 as the left child of 𝐿𝑌. It is guaranteed that 𝑋 and 𝑌 are not in the
same tree.
The leftmost leftless node in a directed binary tree is the first node encountered during a pre-order
traversal (starting at the root and prioritizing the left child first, then the right child) that does not
have a left child. If the tree has only one node, that node is the leftmost leftless node.
● 2𝑋
Determine the number of unique flower shapes in the tree containing the node 𝑋.

8
ICPC Asia Dhaka Regional Contest, 2024
Hosted by: Daffodil International University

Input 5
The first line will contain a single integer 𝑇(1 ≤ 𝑇 ≤ 5×10 ) denoting the number of test cases.
5 5
Each test case will start with two integers 𝑁(1 ≤ 𝑁 ≤ 5×10 ) and 𝑄(1 ≤ 𝑄 ≤ 5×10 ).

The next 𝑁 lines will contain three space-separated integers 𝐿𝑖, 𝑅𝑖 & 𝐶𝑖(𝐶𝑖 ∈ {0, 1}). It is guaranteed that with
𝑡ℎ
this information, a valid forest with valid directed binary trees can be formed. 𝐿𝑖 or 𝑅𝑖 is -1 if the 𝑖 node
doesn’t contain the respective child node. Otherwise, they follow the constraints (1 ≤ 𝐿𝑖, 𝑅𝑖 ≤ 𝑁, 𝐿𝑖 ≠ 𝑅𝑖).
𝑡ℎ
𝐶𝑖 = 0 means the 𝑖 node is colored black and 𝐶𝑖 = 1 denotes the node is colored white.

After building the trees, there will be 𝑄 instructions. Each of the instructions can be any of the two types
below.
● 1𝑋𝑌
Constraints: 𝑋 and 𝑌 are integers. (1 ≤ 𝑋, 𝑌 ≤ 𝑁, 𝑋 ≠ 𝑌)
● 2𝑋
Constraints: 𝑋 is an integer. (1 ≤ 𝑋 ≤ 𝑁)
5
Note that, the sum of 𝑁 across all test cases is at most 5×10 , and the sum of 𝑄 across all test cases is at
5
most 5×10 . It is guaranteed that there will be at least one query of type 2 in each test case.

Output
For each test case, first print “Case T:” on a separate line, where T is the test case number. Then, for each
query of type 2, print the corresponding answer on a new line.

Sample Input Output for Sample Input


2 Case 1:
9 7 2
2 3 0 2
-1 -1 1 1
4 -1 1 1
-1 -1 1 2
6 7 0 Case 2:
-1 -1 1 0
8 -1 1
-1 -1 1
-1 -1 1
2 1
2 5
2 9
1 9 1
2 1
1 5 1
2 5
1 1
-1 -1 0
2 1
It is recommended to use fast input/output methods due to the large input size.

9
ICPC Asia Dhaka Regional Contest, 2024
Hosted by: Daffodil International University

Problem G
Library Function vs Keyword

In C there is a keyword 𝑠𝑖𝑧𝑒𝑜𝑓 which can be used to find how much memory space (In bytes) a string
variable occupies. There is another function 𝑠𝑡𝑟𝑙𝑒𝑛() which finds the length of a string. But there is a
difference between how these two work. 𝑠𝑖𝑧𝑒𝑜𝑓() adds a NULL character at the end of any string and
calculates memory requirement using that, on the other hand 𝑠𝑡𝑟𝑙𝑒𝑛() calculates the length up to the first
null character but excludes null characters from string length. The output of the program below will make
the difference clear.
Code:
#include<stdio.h>
#include<string.h>
char line[]="abracadabra\0abraka";
int main(void)
{
printf("%d %d\n",sizeof(line),strlen(line));
return 0;
}
Output Console:

The assigned string here is abracadabra\0abraka, 𝑠𝑡𝑟𝑙𝑒𝑛() shows the length of the boldfaced part and
𝑠𝑖𝑧𝑒𝑜𝑓() shows the memory required by the whole string and an additional 𝑛𝑢𝑙𝑙 character.

Given the value of the assigned string to variable 𝑙𝑖𝑛𝑒[], you will have to print the value of 𝑠𝑖𝑧𝑒𝑜𝑓(𝑙𝑖𝑛𝑒) and
𝑠𝑡𝑟𝑙𝑒𝑛(𝑙𝑖𝑛𝑒).

Input
The first line of the input file contains a positive integer 𝑁(𝑁 < 1000) which denotes the total number of
input lines. Each of the next lines contains a non-empty string S which is the value of the assigned variable
𝑙𝑖𝑛𝑒[]. This string only contains alphabets ( ‘A’- ‘Z’, ‘a’- ‘z’) and 𝑛𝑢𝑙𝑙 (Denoted with ‘\0’) characters. There are
a maximum of 100 characters in this string assuming ‘\’ and ‘0’ are counted separately.

Output
For each line of input produce one line of output which denotes the values of 𝑠𝑖𝑧𝑒𝑜𝑓(𝑆) and 𝑠𝑡𝑟𝑙𝑒𝑛(𝑆)
respectively.

Sample Input Output for Sample Input


1 19 11
abracadabra\0abraka

10
ICPC Asia Dhaka Regional Contest, 2024
Hosted by: Daffodil International University

Problem H
Hand Cricket

Alice and Bob play a game on an integer array 𝐴 of length 𝑁. Alice chooses a secret index 𝑖, and Bob
chooses a secret index 𝑗. If 𝑖 ≠ 𝑗 then Alice gains 𝐴𝑖 points, else she gains 0 points. Then the game ends.
Alice wants to maximize the point. Bob wants to minimize it. A strategy for a player is a probability
distribution 𝑃1, 𝑃2, ..., 𝑃𝑁 (𝑃1 + 𝑃2 + ... + 𝑃𝑁 = 1, 0 ≤ 𝑃𝑖 ≤ 1) which implies that the player will choose index
𝑖 with probability 𝑃𝑖. Both of them will choose their own strategy in such a way that their strategy cannot be
exploited, even if it is leaked to the other person.

Answer 𝑄 queries, each with a given tuple [𝐿, 𝑅, 𝐾]:


For each query:

● The game will be played within the subarray 𝐴𝐿, 𝐴𝐿+1, ..., 𝐴𝑅.
● Before the game starts, Alice can apply at most 𝐾 increment moves. An increment move is to do
𝐴𝑖 = 𝐴𝑖 + 1 for some 𝑖 ∈ [𝐿, 𝑅]. The move can be applied multiple times on the same 𝑖. The
increment moves only affect the current query and will not persist to subsequent queries.

Print the expected number of points gained by Alice. The answer can be expressed as an irreducible
𝑋 −1
fraction 𝑌
, 𝑌 ≠ 0. You need to print the value of (𝑋 · 𝑌 ) 𝑚𝑜𝑑𝑢𝑙𝑜 998244353. It is guaranteed that for
−1
each of the queries an answer can be calculated (i.e 𝑌 exists modulo 998244353).

Input 5
The first line contains an integer 𝑁(1 ≤ 𝑁 ≤ 2 × 10 ). The second line has 𝑁 space-separated integers
8 5
𝐴1, 𝐴2,..., 𝐴𝑁 (1 ≤ 𝐴𝑖 ≤ 10 ). The third line contains an integer 𝑄 (1 ≤ 𝑄 ≤ 1 × 10 ), the number of queries.
8
The following 𝑄 lines contain 3 integers each, 𝐿𝑖, 𝑅𝑖, 𝐾𝑖 (1 ≤ 𝐿𝑖 ≤ 𝑅𝑖 ≤ 𝑁 , 0 ≤ 𝐾 ≤ 10 ) representing the ith

query.

Output
Print the answer of each query in a separate line.

Sample Input Output for Sample Input


3 2
1 2 3 0
3 598946613
1 3 3
1 1 6
1 2 2

11
ICPC Asia Dhaka Regional Contest, 2024
Hosted by: Daffodil International University

Problem I
In Search of a Kind Person

There was a long queue of people waiting to enter into the Victory Day Street Fair. The main show had
already begun, and everyone in the queue was trying to take a peek inside. While some were anxious to
get in quick; there were a few, considerate enough to think about others even in this rush. They found
perfect positions for themselves, without blocking the view to anyone standing behind them. We want to
meet such a person and say, ‘Thank you!’

So your job is to find the person who is strictly taller than everyone standing in front of him, and strictly
shorter than everyone behind.

Input
5
The first line tells the number of test cases with a single integer 𝑇(1 ≤ 𝑇 ≤ 10 ).
5
Each test starts with an integer 𝑁(1 ≤ 𝑁 ≤ 10 ), in a line, denoting the length of the queue. The following
9
line contains a list of 𝑁 integers 𝐴1, 𝐴2, ... , 𝐴𝑁 (1 ≤ 𝐴𝑖 ≤ 10 , 𝑖 = 1.. 𝑁), describing the height of each person
in the queue. 𝐴1 is the height of the person standing at the front of the queue, and 𝐴𝑁 describes the person
at the very back.

6
It is guaranteed that Σ𝑁 ≤ 10 over all test cases.

Output
For each case, print a single line containing the case number, and an integer i, the position of the person
we are looking for. If there are multiple, find the frontmost one. If there is no such person, print “Humanity
is doomed!” without quotes.

Check the format below.

Sample Input Output for Sample Input


4 Case 1: 3
5 Case 2: 6
2 1 3 5 4 Case 3: Humanity is doomed!
8 Case 4: 1
2 1 2 5 5 7 8 9
2
2 1
5
1 2 3 4 5
It is recommended to use fast input/output methods due to the large input size.

12
ICPC Asia Dhaka Regional Contest, 2024
Hosted by: Daffodil International University

Problem J
The Taxman

You are the Royal Taxman of the prosperous kingdom of Luxandra, tasked by King Alexander IV to design
a progressive tax system for its citizens. The kingdom relies on your mathematical precision to ensure a
just and fair taxation process that supports the royal treasury without burdening its hard working citizens.
King Alexander IV has decreed that the tax system will be divided into several bands, with wealthier citizens
contributing more to the kingdom’s prosperity. The people of Luxandra earn their income in Luxans (LX),
the official currency of the kingdom.
The Kingdom's Tax System: The tax system for the year 1424 is outlined as follows:

Tax Band Income Range (LX) Tax Rate (%)


Personal allowance 0 to 12,500 0%

Basic rate Over 12,500 up to 50,000 20%

Higher rate Over 50,000 up to 150,000 40%

Additional rate Over 150,000 45%

Royal Decrees:
1. Personal allowance: Every citizen enjoys a tax-free personal allowance of first 12,500 Luxans (LX).
No tax is paid on this portion of their income.
2. Basic rate (20%): The next portion of the income over 12,500 up to 50,000 LX is taxed at 20%.
3. Higher rate (40%): The next portion of the income over 50,000 up to 150,000 LX is taxed at 40%.
4. Additional rate (45%): The next portion of the income above 150,000 LX is taxed at 45%.
5. Reduction of personal allowance: For any amount earned above 100,000 LX, the personal
allowance is reduced by half of that amount, but the personal allowance can’t go below zero (e.g.,
earning 100,001 LX reduces the allowance by 0.5 LX).
6. Taxing the reduced personal allowance at the higher rate: Once a citizen's salary exceeds 100,000
LX, and their personal allowance is reduced, the reduced portion of the allowance will be taxed at
40% (the higher rate). For example, earning 100,002 LX reduces the allowance by 1 LX, and this 1
LX is taxed at 40%.

After designing and implementing the tax system, you calculated the total tax owed by each citizen.
Unfortunately, the kingdom has since lost all records of citizen incomes for the year 1424. However, the tax
amounts collected from each citizen were securely stored.

The king has now given you the task of reconstructing the income records for each citizen based on their
tax amounts. You must write a program that calculates the yearly income of a citizen from the tax amount
provided.

13
ICPC Asia Dhaka Regional Contest, 2024
Hosted by: Daffodil International University

Input
The first line contains an integer 𝑇, the number of test cases. Each of the next 𝑇 lines contains a
floating-point number 𝑋, denoting the tax amount collected from a citizen in Luxans (LX), formatted to two
decimal places.

Constraints
4
● 1 ≤ 𝑇 ≤ 10
9
● 0 ≤ 𝑋 ≤ 10

Output
For each test case, output a non-negative real number representing the calculated yearly income of the
citizen. If there are multiple solutions, you can output any of them.

Note that this problem uses a special judge. Your output will be considered correct if the absolute or relative
−6
error between the actual tax and the tax calculated from your output income does not exceed 10 .
Formally, if the tax calculated from your output income is 𝐴 and the actual tax provided in the input is 𝐵,
|𝐴 − 𝐵| −6
your answer will be accepted if and only if 𝑚𝑎𝑥(1, 𝐵)
≤ 10 .

Sample Input Output for Sample Input


4 15002.50
500.50 51321
8028.40 110007.00
33504.20 200000.0000
75000.00

Explanation
Example 1: The yearly income is 15,002.50 LX. Here the first 12,500 LX is tax-free personal allowance.
And the rest of the income, 2,502.5 LX is taxed at basic rate (20%).
Example 2: The tax calculation for income amount 51,321 LX is explained below -
- The first 12,500 is tax free personal allowance.
- For income between above 12,500 and 50,000, it falls in the basic rate and is taxed at 20%. So the
citizen paid 7,500 LX in tax for this range.
- The remaining 1,321 LX falls in the additional rate and is taxed at 40%. So this citizen paid 528.4 LX
for this range. So the total tax is 7,500 + 528.4 = 8,028.40 LX.
Example 3: Since this citizen earned 10,007 LX ​over 100,000, their personal allowance is reduced by half
of 10,007 and taxed at 40%. So the extra tax here is 2,001.40 LX.

14
ICPC Asia Dhaka Regional Contest, 2024
Hosted by: Daffodil International University

Problem K
Packet Transmission
You are given a connected network tree representing routers and channels. Each node represents a router,
and each edge represents a channel connecting two routers. These channels are used to transmit packets
from one router to one of its adjacent routers, and the transmission follows the TCP/IP protocol. The edges
are labeled with 𝑡𝑖 indicating the time (in arbitrary units) it takes to transmit a packet from 𝑢𝑖 to 𝑣𝑖 or vice
versa.

Additionally, each router has enough storage capacity to store any number of packets, they can store
packets there indefinitely and they can transmit multiple packets simultaneously but via different channels.
This means that you can't send a packet via a channel that is currently occupied by another transmission.

Your task is to send two packets concurrently, one from 𝑠1 router to 𝑑1 router and another from 𝑠2 router to
𝑑2 router. Determine the optimal transmission strategy to minimize the maximum time for delivering both of
these packets from source to destination.

Input
Input starts with an integer 𝑇(1 ≤ 𝑇 ≤ 1000) denoting the number of test cases. Each of the test cases
starts with two integers N and Q (1 ≤ 𝑁, 𝑄 ≤ 100000) . Then there will be 𝑁 − 1 lines of input consisting of
9
three integers 𝑢, 𝑣, 𝑡 (1 ≤ 𝑢, 𝑣 ≤ 𝑛, 𝑢 ≠ 𝑣, 1 ≤ 𝑡 ≤ 10 ) representing edges of the tree.

Then, There will be Q lines each with four integers 𝑠1, 𝑑1, 𝑠2, 𝑑2(1 ≤ 𝑠1, 𝑑1, 𝑠2, 𝑑2 ≤ 𝑁) representing the
source and destination routers for two packets. Σ𝑁 ≤ 500000, Σ𝑄 ≤ 500000 holds across all test cases.

Output
For each test case print the test case number in the format of “Case T:” in one line where 𝑇 is the test case
number. Then for each query use the optimal transmission strategy to minimize the maximum time to
deliver both packets and print the minimum time in a separate line.

Sample Input Output for Sample Input


1 Case 1:
8 3 7
1 2 3 15
2 3 5 24
2 6 7
3 4 4
4 5 3
6 7 2
1 8 6
1 8 2 6
1 5 2 3
5 8 8 5
It is recommended to use fast input/output methods due to the large input size.

15
ICPC Asia Dhaka Regional Contest, 2024
Hosted by: Daffodil International University

Problem L
Unhappy Team

You are managing a team of 𝑁 people numbered from 1 to 𝑁. In the team everyone perceives everyone
else as stronger or weaker than them in work performance. For the year end bonus you need to stack rank
the team in some way. A stack rank is a permutation of the numbers from 1 to 𝑁. After the stack ranking is
done, it is visible to everyone in the team. Everyone has an unhappiness score which is equal to the
number of people ahead of them in the stack rank that they deemed weaker than them. If we find the
unhappiness score of everyone and sum up the largest or worst 𝐾 unhappiness score then we find the
score of that stack ranking. For example if the ascendingly sorted unhappiness score of a stack ranking is
[0, 1, 2, 2, 3] then for 𝐾 = 2 the score is 5(3 + 2) and for 𝐾 = 3 the score is 7(3 + 2 + 2).

Given 𝑁, 𝐾 and everyone’s perception of who is stronger or weaker than them, find the expected
𝑃
unhappiness score of a randomly chosen stack ranking. The answer can be expressed as 𝑄
, 𝑄 ≠ 0, then
−1
answer the value of (𝑃 * 𝑄 ) 𝑚𝑜𝑑𝑢𝑙𝑜 998244353.

Input
The first line of the input contains an integer 𝑇(1 ≤ 𝑇 ≤ 50), denoting the number of test cases. For each
test scenario, the first line contains two integers 𝑁 and 𝐾 (1 ≤ 𝐾 ≤ 𝑁 ≤ 16). The next 𝑁 lines each contain
𝑁 uppercase characters. The character 𝑗 in line 𝑖 represents what person 𝑖 thinks of person 𝑗. If the
character is '𝑆' then 𝑖 thinks 𝑗 is stronger. If it is '𝑊' then 𝑖 thinks 𝑗 is weaker. It will be '𝑋' if 𝑖 = 𝑗. It is
guaranteed that the number of test cases where 𝑁 > 12 is at most 3.

Output
For each test scenario print one line, the expected score of a randomly chosen stack ranking modulo
998244353.

Sample Input Output for Sample Input


3 499122178
3 2 499122179
XSW 0
SXW
WSX
4 3
XSWS
WXSW
SSXS
SWWX
1 1
X

16

You might also like