0% found this document useful (0 votes)
61 views13 pages

Statements 231022

Uploaded by

0fakerxfaker0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views13 pages

Statements 231022

Uploaded by

0fakerxfaker0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Azerbaijan Qualification 2023

Azerbaijan, Sunday, October 22, 2023

Problem A. Attacks Number


Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 1024 megabytes

In the pre-season NBA game, the referees decided to stop the game as little as possible, and the teams
treat each other very politely: the game has only training value, so each attack can result in either 0
points, or 2 points, or 3 points — the teams do not receive any one-point free throws. After one team
finishes their attack, the other team starts their attack.
We will call an attack successful if the team scores a non-zero number of points. You are given the current
score of the game. Find the minimum total number of successful attacks required to equalize the score
in the game.

Input
The input file contains the score — one line consisting of the number of points scored by the home team
and the number of points scored by the away team, separated by a space. The number of points for each
team is a positive integer from 1 to 120.

Output
Output a single integer — the minimum number of successful attacks required to equalize the score in the
game.

Examples
standard input standard output
108 100 3
10 10 0
90 94 2

Page 1 of 13
Azerbaijan Qualification 2023
Azerbaijan, Sunday, October 22, 2023

Problem B. Brands
Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 1024 megabytes

One big company decided to change one of their brands. The brand shall be similar to existing one, but it
shall be readable. The word is considered readable if it does not contains two vowels nor two consonants
in the row. The management of the company considers the letters aeiouy as vowels, and other English
letters as the consonants.
Given the current name of the brand, insert the minimal possible number of letters to make the name
readable. If there are multiple solutions, find one that gives the lexicorgraphically minimal name.

Input
The first line of the input contains the current name of the team — the non-empty string of length no
greater than 104 lowercase English letters.

Output
Print one line — the new name of the brand after the transformation.

Examples
standard input standard output
ct cat
rat rat

Page 2 of 13
Azerbaijan Qualification 2023
Azerbaijan, Sunday, October 22, 2023

Problem C. Classify the Roman Numerals


Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 1024 megabytes

Your task is to determine the number of symmetry axis of the given Roman Numeral.
The following table from Wikipedia displays how the Roman Numerals are written:

Individual decimal places Thousands Hundreds Tens Units


1 M C X I
2 MM CC XX II
3 MMM CCC XXX III
4 CD XL IV
5 D L V
6 DC LX VI
7 DCC LXX VII
8 DCCC LXXX VIII
9 CM XC IX

Note that:
• The numerals for 4, 9, 40, 90, 400 and 900 are written using “subtractive notation” where the first
symbol is subtracted from the larger one (for example, for 40 (“XL”) ‘X’ (10) is subtracted from ‘L’
(50)). These are the only subtractive forms in standard use.
• A number containing several decimal digits is built by appending the Roman numeral equivalent
for each, from highest to lowest.
• Any missing place (represented by a zero in the place-value equivalent) is omitted.
• The largest number that can be represented in the Roman notation is 3 999 (MMMCMXCIX).
• The letters I, V, X, M, and only those, are vertically symmetric, the letters I, X, C, D, and only those,
are horizontally symmetric.
For example, 200 have the horizontal symmetry only (because CC have the vertical axis, but does not
have horizontal one), 2000 have the vertical symmetry only(MM have the vertical axis of symmetry, placed
between the letters, but does not have horizontal one), the number 1001 (MI) have no axis of symmetry at
all, and the number 30 (XXX) have both axis (vertical one is placed in the middle of the second X letter).

Input
The first line of the input file contains a single integer T - the number of Roman numbers in the test
(1 ≤ T < 4000).
Each of the following T lines contains a single integer: the decimal representation of the Roman Numeral.
The integers are between 1 and 3999, inclusively.

Output
For each numeral, output - if the Roman numeral on it has horizontal symmetry, | if it has vertical
symmetry, + if it has both, and ? if it has neither.

Example
standard input standard output
4 -
200 |
2000 ?
1001 +
30

Page 3 of 13
Azerbaijan Qualification 2023
Azerbaijan, Sunday, October 22, 2023

Problem D. Decimal-Friendly Numbers


Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 1024 megabytes

Let’s consider the set SN consisting of all positive integers whose decimal representation consists of exactly
N digits and does not contain leading zeros. We call a number “decimal-friendly” if all its digits have a
common divisor with 10, greater than 1.
Suppose we randomly and uniformly select K numbers from SN . What is the minimum value of K such
that the probability of having at least one decimal-friendly number among the selected numbers is greater
than 0.999 999 999?

Input
The input contains a single integer N (1 ≤ N ≤ 50).

Output
Output a single integer K — the minimum amount of numbers that need to be selected in order to
have a probability of having a decimal-friendly number among selected ones greater than or equal to
0.999 999 999. If the relative error of the answer does not exceed 10−6 , the answer is considered correct.

Examples
standard input standard output
1 26
9 2211

Page 4 of 13
Azerbaijan Qualification 2023
Azerbaijan, Sunday, October 22, 2023

Problem E. Elements of Triangle


Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 1024 megabytes

This is an interactive problem


Jury came up with a triangle of non-zero area and integer side lengths a, b, c, each not greater than 104 .
You can ask questions of the form «what is the length of median/bisector/altitude of a triangle that is
drawn through the point, opposite to side x».
Your task is to guess the lengths of sides of the triangle in the correct order, asking not more than three
questions.

Interaction Protocol
Your program starts interaction. Each query has the following format: “? t s”, where t — character, defining
type of the query: ‘h’ for altitude, ‘m’ for median and ‘b’ for bisector, s — side, opposite point of which
crosses given segment. In response, Jury’s program outputs one real number with 14 decimal places —
the length of the asked element of a triangle.
To print the answer, use the format “! a b c”, where a, b and c — lengths of sides. Note that you must
print the sides in the correct order. That is, the answer a c b with b 6= c would be considered incorrect.
Outputing the answer is not considered as a query.

Example
standard input standard output
? h a
4.00000000000000
? m b
3.60555127546399
? b c
2.42436610692531
! 3 4 5

Page 5 of 13
Azerbaijan Qualification 2023
Azerbaijan, Sunday, October 22, 2023

Problem F. Fence Painting


Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 1024 megabytes

The fence consists of N vertical boards. You have K different colors of paint, numbered consecutively
from 1 to K. Some boards are already painted, while the rest are unpainted. You want to paint the fence
in such a way that no two adjacent boards are painted the same color, without repainting the already
painted boards. How many ways can this be done?
Since the answer can be very large, output the remainder when divided by 998 244 353.

Input
The first line of the input contains two integers N and K: the number of boards in the fence and the
number of colors, respectively (1 ≤ N ≤ 500 000, 3 ≤ K ≤ 109 ).
Next, there are N integers from 0 to K — the boards in the fence, listed from left to right. If the
corresponding number is 0, the board is unpainted, if it is positive — the board is painted in the
corresponding color. It is guaranteed that if two painted boards are adjacent, they are painted in different
colors.

Output
Output a single integer — the number of different ways to paint the boards according to the problem
statement modulo 998 244 353.

Examples
standard input standard output
4 3 2
1 0 2 0
3 5 4
3 0 3
10 123 1800964
2 0 2 3 1 0 2 1 15 0

Page 6 of 13
Azerbaijan Qualification 2023
Azerbaijan, Sunday, October 22, 2023

Problem G. Generic Strings


Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 1024 megabytes

A string S is given, as well as x of its substrings (specified by the indices of their first and last elements;
the letters in the string are numbered starting from 1).
The StringGPT string recognition system defines a string as generic if there are no two identical letters
among the letters present in each of the selected substrings.
Over time, the letters from the string fall off in a certain order, leaving spaces behind. According to the
StringGPT definition, spaces are not recognized as letters, so when determining if the string is generic,
StringGPT only considers the letters that remain (in particular, after all the letters have fallen off,
StringGPT will consider the resulting empty space as a generic string).
Given the string S, a set of x control substrings, and the order in which the letters disappear, determine
after which disappearance StringGPT will consider the string as generic for the first time.

Input
The first line of the input contains a string S, composed of lowercase English letters (1 ≤ |S| ≤ 105 ).
The second line of the input contains a single integer x (1 ≤ x ≤ 105 ) - the number of control substrings.
Each of the following Q lines contains two integers ai and bi (1 ≤ ai ≤ bi ≤ |S|) - the indices of the first
and last characters of the current substring.
The last line contains |S| pairwise distinct integers di (1 ≤ di ≤ |S|) - the indices of the disappearing
letters, listed in the order of their disappearance.

Output
Output a single integer — the number of letter disappearances before StringGPT considers the string as
generic for the first time.

Examples
standard input standard output
qqqqq 2
2
1 2
4 5
2 4 1 5 3
pbbpbppb 5
3
1 3
4 7
3 5
6 3 5 1 4 2 7 8
nerc 0
1
1 4
1 2 3 4

Page 7 of 13
Azerbaijan Qualification 2023
Azerbaijan, Sunday, October 22, 2023

Problem H. How Many Representations?


Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 1024 megabytes

In the monetary system of Byteland, the denominations of all coins are elements of the sequence Ci ,
defined as follows:C1 = 1, C2 = 2, Ci = Ci−1 + Ci−2 for all i > 2. Coins with the same denominations are
considered identical, while coins with different denominations are considered distinct.
You need to find the number of ways to pay the sum of N using distinct coins. Two ways are considered
different if a coin is present in one partition and absent in the other.

Input
The input contains a single integer N (1 ≤ N ≤ 1018 ) - the amount of money to be paid.

Output
Output a single integer — the answer to the problem.

Examples
standard input standard output
21 4
116 8

Note
For the first example (N = 21), possible exchanges: 21, 13+8, 13+5+3, 13+5+2+1.

Page 8 of 13
Azerbaijan Qualification 2023
Azerbaijan, Sunday, October 22, 2023

Problem I. Interactive Permutations Strike Back


Input file: standard input
Output file: standard output
Time limit: 5 seconds
Memory limit: 1024 megabytes

This is an interactive problem


The jury has chosen a permutation of length N . You are given the number N and the number of inversions
in the permutation. A pair of numbers forms an inversion if the larger number appears to the right of the
smaller number. For example, in the permutation (2, 1, 5, 3, 4), there are three pairs of numbers that form
inversions: (2,1), (5,3), and (5,4). Therefore, the number of inversions in this permutation is 3.
You can ask the jury’s program to swap the numbers at certain positions in the permutation. In response,
the permutation will change, and you will receive the number of inversions in the new permutation. Your
task is to guess the initial permutation in no more than 2 · 105 queries.

Interaction Protocol
The interaction starts with the jury’s program printing two integers 1 ≤ N ≤ 105 — the length of the
permutation and 0 ≤ I ≤ 5 000 050 000 - the number of inversions in the initial permutation.
Then, your program can ask questions. Each question has the form ? i j, where 1 ≤ i, j ≤ N . After that,
the jury’s program swaps the i-th and j-th elements of the current permutation and outputs the number
of inversions in the new permutation (the next query will be applied to the new permutation). You are
allowed to ask no more than 2 · 105 questions in total.
If your program is ready to guess the permutation, output !, followed by a single line containing N
integers from 1 to N : the initial permutation chosen by the jury’s program. This action does not count
as a question.
Please do not forget to print end-of-line character at the end of each question and answer printing, and
flush the output after it using the flush function of your programming language. Otherwise you may
receive the Idleness Limit Exceed (or Wall-Time-Limit Exceed) error.

Example
standard input standard output
5 6
? 1 2
5
? 1 2
6
? 3 2
5
? 3 2
6
! 4 3 1 5 2

Page 9 of 13
Azerbaijan Qualification 2023
Azerbaijan, Sunday, October 22, 2023

Problem J. Jungle And Trees


Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 1024 megabytes

The jungle can be represented as the square with coordinates of vertices (1, 1), (1, N ), (N, N ) and (N, 1).
At each of N 2 integer points the tree is planted.
We consider the set of trees controlling, if the following property is held: for each tree in the set there are
no other trees in the set that belongs to the straight line, connecting this tree with the point (0, 0).
Given the N , find the maximal number of the trees in the controlling set.

Input
The input contains an integer N (1 ≤ N ≤ 106 ).

Output
Output a single integer — the maximum number of the trees in the controlling set.

Examples
standard input standard output
6 23
42 1083

Page 10 of 13
Azerbaijan Qualification 2023
Azerbaijan, Sunday, October 22, 2023

Problem K. Keeping The Data Integrity


Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 1024 megabytes

This is a double-run problem


During the coverage of athletic competitions taking place in the other hemisphere, you needed to transmit
an array of N 32-bit numbers (in fact, these are real numbers representing the athletes’ results, but it
doesn’t matter in this problem). Unfortunately, due to extraordinary activity of the sun, transmission
errors are possible today: let’s say you transmit K numbers mi , then one of these numbers mx is randomly
chosen at the transmitting station, and each of the K numbers is replaced with the number mi ⊕ mx ,
where ⊕ is the exclusive or operation, after which the modified data is received by the recipient.
Your company has already paid for the some amount of transmitted information. Through multi-level
negotiations, you have been allowed to transmit one more number. You need to transmit the information
and receive it after the failure.
Your solution will be run twice on each test case — first for encoding, then for decoding.

Input
If you need to transmit data, the first line of the input contains the word “send”, the second line contains
an integer N (1 ≤ N ≤ 105 ) — the number of results, the third line contains N integers in the range from
0 to 232 − 1 — the actual data.
If you need to receive data, the first line of the input contains the word “receive”, the second line contains
an integer K — the number of transmitted data, the third line contains K integers in the range from 0
to 232 − 1 — the distorted data.

Output
When transmitting data, output N + 1 integers in the range from 0 to 232 − 1.
When receiving data, output K − 1 = N integers that should exactly match the numbers you need to
transmit.

Examples
standard input standard output
send 1 2 3 4
3
10 20 30
receive 10 20 30
4
3 0 1 6

Page 11 of 13
Azerbaijan Qualification 2023
Azerbaijan, Sunday, October 22, 2023

Problem L. Loyality Program


Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 1024 megabytes

The race administration plans to open the loyality program ticket sales for the upcoming Formula-1 Race!
The prices need to be set. According to the recommendations, the prices for seats should end with .99,
while the allowed price range is defined by two numbers l and r (where 10 ≤ l ≤ r ≤ 100, l and r are
given exactly with two decimal places). What is the maximum number of different ticket prices that the
administration can set to comply with the FIA recommendations?

Input
The first line of the input contains two numbers l and r: the minimum and maximum allowable ticket
prices (10 ≤ l ≤ r ≤ 100, a and b are given exactly with two decimal places).

Output
Output a single integer: the maximum number of ticket prices that the administration can set, ending
with .99 and within the required range.

Examples
standard input standard output
20.23 21.07 1
20.23 20.24 0
10.00 40.01 30

Page 12 of 13
Azerbaijan Qualification 2023
Azerbaijan, Sunday, October 22, 2023

Problem M. Major Leagues


Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 1024 megabytes

In the major soccer leagues like The Champions League teams play the group stage. Let the group have
N teams. Then each team plays two games with any other team (one host game and one guest game).
Each game outcome can be or win of one team (then winning team receives 3 points, and losing team
receives 0 point), or the draw (then both teams receive 1 point).
At the end of the group stage the teams are sorted by decreasing the points scored. If several teams scored
equal number of points, the additional parameters are used to determine the places of the teams. Team
from the first place is recognized as the winner of the group.
Given N , find the maximum and the minimum amount of points of the winner of the group.

Input
Input contains one integer N (2 ≤ N ≤ 100) — the number of the teams in the group.

Output
Print two integers — the maximum and the minimum amount of points of the winner of the group.

Example
standard input standard output
4 18 6

Page 13 of 13

You might also like