Problems - Codeforces 1013 Div 3
Problems - Codeforces 1013 Div 3
3)
The first line of each test case contains two integers n and x (
A. Olympiad Date 5
,1
9
1 ≤ n ≤ 2 ⋅ 10 ) — the number of students in training
≤ x ≤ 10
1 second, 256 megabytes and the minimum strength of a team to be considered strong.
The final of the first Olympiad by IT Campus "NEIMARK" is scheduled for The second line of each test case contains n integers ai (
March 1, 2025. A nameless intern was tasked with forming the date of the 1 ≤ ai ≤ 10
9
) — the skill of each student.
Olympiad using digits — 01.03.2025.
It is guaranteed that the sum of n over all test cases does not exceed
To accomplish this, the intern took a large bag of digits and began
2 ⋅ 10
5
.
drawing them one by one. In total, he drew n digits — the digit ai was
Output
drawn in the i-th turn.
For each test case, output the maximum possible number of teams with
You suspect that the intern did extra work. Determine at which step the strength at least x .
intern could have first assembled the digits to form the date of the
Olympiad (the separating dots can be ignored), or report that it is input
impossible to form this date from the drawn digits. Note that leading 5
zeros must be displayed. 6 4
4 5 3 3 2 6
Input 4 10
Each test contains multiple test cases. The first line contains the number 4 2 1 3
4
5 3
of test cases t (1 ≤ t ≤ 10 ). The description of the test cases follows. 5 3 2 3 2
3 6
The first line of each test case contains a single integer n (1 ≤ n ≤ 20 ). 9 1 7
6 10
The second line of each test case contains n integers ai (0 ≤ ai ≤ 9 )—
6 1 3 6 3 2
the numbers that the intern pulled out in chronological order.
output
Output
4
For each test case, output the minimum number of digits that the intern 0
could pull out. If all the digits cannot be used to make a date, output the 4
number 0. 2
1
input
4
10
C. Combination Lock
2 0 1 2 3 2 5 0 0 1 2 seconds, 256 megabytes
8
2 0 1 2 3 2 5 0 At the IT Campus "NEIMARK", there are several top-secret rooms where
8
2 0 1 0 3 2 5 0
problems for major programming competitions are developed. To enter
16 one of these rooms, you must unlock a circular lock by selecting the
2 3 1 2 3 0 1 9 2 1 0 3 5 4 0 3 correct code. This code is updated every day.
Each test contains multiple test cases. The first line contains the number
4
of test cases t (1 ≤ t ≤ 10 ). The description of the test cases follows.
input A single line of each test case contains three positive integers — n, m, k (
9
1 ≤ n, m, k ≤ 10 ,k ≤ n ⋅ m ).
3
4 Output
5 For each test case, output a single number — the minimum possible
3 length of the longest bench.
output
-1
input
4 1 3 5 2 5
1 3 2 3 4 7
5 5 5
In the second example, there is a permutation such that in each cyclic 1 13 2
2 4 7
shift there is a fixed point (highlighted in dark red): 1 5 4
output
2
The first line contains the element numbers, and the second line contains all 1
the shifts of the desired permutation. 1
4
2
D. Place of the Olympiad
1 second, 256 megabytes E. Interesting Ratio
For the final of the first Olympiad by IT Campus "NEIMARK", a rectangular 2 seconds, 256 megabytes
venue was prepared. You may assume that the venue is divided into n
Recently, Misha at the IT Campus "NEIMARK" camp learned a new topic —
rows, each containing m spots for participants' desks. A total of k
participants have registered for the final, and each participant will sit at an the Euclidean algorithm.
individual desk. Now, the organizing committee must choose the locations He was somewhat surprised when he realized that
for the desks in the venue. a ⋅ b = lcm(a, b) ⋅ gcd(a, b), where gcd(a, b) — is the greatest
Each desk occupies one of the m spots in a row. Moreover, if several common divisor (GCD) of the numbers a and b and lcm(a, b) — is the
desks occupy consecutive spots in the same row, we call such a group of least common multiple (LCM). Misha thought that since the product of
desks a bench, and the number of desks in the group is the bench's length. LCM and GCD exists, it might be interesting to consider their quotient:
lcm(a,b)
For example, seating 7 participants on a 3 × 4 venue (with F (a, b) = .
gcd(a,b)
n = 3, m = 4 ) can be arranged as follows:
4
For example, he took a = 2 and b = 4, computed F (2, 4) = 2 = 2 and
obtained a prime number (a number is prime if it has exactly two divisors)!
Now he considers F (a, b) to be an interesting ratio if a < b and F (a, b)
is a prime number.
Since Misha has just started studying number theory, he needs your help
to calculate — how many different pairs of numbers a and b are there
such that F (a, b) is an interesting ratio and 1 ≤ a < b ≤ n ?
Input
Each test contains multiple test cases. The first line contains the number
of test cases t (1 ≤ t ≤ 103 ). The description of the test cases follows.
In the figure above, the first row has one bench of length 3, the second
7
row has one bench of length 2, and the third row has two benches of A single line of each test case contains a single integer n (2 ≤ n ≤ 10 ).
length 1.
It is guaranteed that the sum of n over all test cases does not exceed
The organizing committee wants to choose the locations so that the 10
7
.
length of the longest bench is as small as possible. In particular, the same
7 desks can be arranged in a more optimal way, so that the lengths of all
Output
benches do not exceed 2: For each test case, output the number of interesting ratios F (a, b) for
pairs satisfying 1 ≤ a < b ≤ n .
input
4
5
10
34
10007
output
4
11
49
Given the integers n, m, and k, determine the minimum possible length of
24317
the longest bench.
Input
Each test contains multiple test cases. The first line contains the number F. Igor and Mountain
of test cases t (1 ≤ t ≤ 10
4
). The description of the test cases follows. 5 seconds, 512 megabytes
The visitors of the IT Campus "NEIMARK" are not only strong output
programmers but also physically robust individuals! Some practice
2
swimming, some rowing, and some rock climbing! 60
0
Master Igor is a prominent figure in the local rock climbing community.
One day, he went on a mountain hike to ascend one of the peaks. As an Possible routes in the first case:
experienced climber, Igor decided not to follow the established trails but
to use his skills to climb strictly vertically.
Being an experienced programmer, Igor decided to count the number of In the second example, Igor's arm span has become larger, so new routes
valid routes. A route is defined as a sequence of distinct holds. A route is are available to him, for example this one:
considered valid if the following conditions are satisfied:
The first hold in the route is located on the very bottom level (row n);
The last hold in the route is located on the very top level (row 1);
Each subsequent hold is not lower than the previous one;
At least one hold is used on each level (i.e., in every row of the
rectangle);
At most two holds are used on each level (since Igor has only two
hands);
Igor must be able to traverse the route, meaning that the Euclidean
distance between the centers of any two holds in the route does not
In the third example, there are no holds on the lower level, so there are no
exceed his arm span.
correct routes.
Igor's arm span is d, which means he can move from one hold to another
if the Euclidean distance between the centers of the corresponding G. Gleb and Boating
segments does not exceed d. The distance between sections (i1 , j1 ) and
−−−−−−−−−−−−−−−− − 3 seconds, 256 megabytes
(i2 , j2 ) is given by √(i1 2
− i2 ) + (j1 − j2 )
2
.
Calculate the number of different valid routes. Two routes are considered Programmer Gleb frequently visits the IT Campus "NEIMARK" to
different if they differ in the list of holds used or in the order in which these participate in programming training sessions.
holds are visited. Not only is Gleb a programmer, but he is also a renowned rower, so he
covers part of his journey from home to the campus by kayaking along a
Input
Each test contains multiple test cases. The first line contains the number river. Assume that Gleb starts at point 0 and must reach point s (i.e., travel
s meters along a straight line). To make the challenge tougher, Gleb has
of test cases t (1
3
≤ t ≤ 10 ). The description of the test cases follows.
decided not to go outside the segment [0, s]. The dimensions of the
The first line of each test case contains three integers n, m, d ( kayak can be neglected.
2 ≤ n ≤ 2000 , 1 ≤ m, d ≤ 2000 ).
Gleb is a strong programmer! Initially, his power is k. Gleb's power directly
Each of the following n lines contains m characters — the description of affects the movement of his kayak. If his current power is x , then with one
the corresponding level of the mountain. The symbol '#' represents an paddle stroke the kayak moves x meters in the current direction. Gleb can
empty section, and the symbol 'X' represents a section with a hold. The turn around and continue moving in the opposite direction, but such a
levels are described from top to bottom. maneuver is quite challenging, and after each turn, his power decreases
by 1. The power can never become 0 — if his current power is 1, then even
It is guaranteed that the sum of n ⋅ m over all test cases does not exceed
after turning it remains 1. Moreover, Gleb cannot make two turns in a row
4 ⋅ 10
6
.
— after each turn, he must move at least once before making another turn.
Output Similarly, Gleb cannot make a turn immediately after the start — he must
For each test case, output the number of different routes modulo first perform a paddle stroke.
998244353.
Gleb wants to reach point s from point 0 without leaving the segment
[0, s] and while preserving as much power as possible. Help him — given
input the value s and his initial power k, determine the maximum possible
3 power he can have upon reaching point s.
3 4 1
XX#X Input
#XX# Each test contains multiple test cases. The first line contains the number
#X#X
3 4 2
of test cases t (1 ≤ t ≤ 100). The description of the test cases follows.
XX#X
A single line of each test case contains two integers s and k (
#XX#
#X#X 1 ≤ s ≤ 10
9
,1 ,
≤ k ≤ 1000 k ≤ s ).
3 1 3
X It is guaranteed that the sum of k over all test cases does not exceed
X 2000.
#
Output
For each test case, output the maximum possible power Gleb can have at
the end of his journey.
input One of the variants of Gleb's movement in the first example:
8
9 6
10 7
24 2
123456 777
6 4
99 6
10 4
99 4
output
4
1
2
775
1
4
2
2