problem_statement stringlengths 147 8.53k | input stringlengths 1 771 | output stringlengths 1 592 ⌀ | time_limit stringclasses 32
values | memory_limit stringclasses 21
values | tags stringlengths 6 168 |
|---|---|---|---|---|---|
D. Martial Arts Tournamenttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMonocarp is planning to host a martial arts tournament. There will be three divisions based on weight: lightweight, middleweight and heavyweight. The winner of each division will be determined... | 443 1 2 11162 2 2 1 1 186 3 6 3 6 3 6 6 | 0 2 3 2 | 2 seconds | 256 megabytes | ['binary search', 'brute force', 'greedy', 'math', '*2100'] |
C. Monsters And Spellstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMonocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters.The level he's currently on contains n monster... | 316424 52 235 7 92 1 2 | 10 6 7 | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'dp', 'greedy', 'implementation', 'math', 'two pointers', '*1700'] |
B. Minor Reductiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a decimal representation of an integer x without leading zeros.You have to perform the following reduction on it exactly once: take two neighboring digits in x and replace them with thei... | 2
10057
90
| 10012 9 | 2 seconds | 256 megabytes | ['greedy', 'strings', '*1100'] |
A. Equidistant Letterstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s, consisting of lowercase Latin letters. Every letter appears in it no more than twice.Your task is to rearrange the letters in the string in such a way that for each pair ... | 3
oelhl
abcdcba
ac
| hello ababcdc ac | 2 seconds | 256 megabytes | ['constructive algorithms', 'sortings', '*800'] |
E2. Cats on the Upgrade (hard version)time limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the hard version of the problem. The only difference between the easy and the hard versions are removal queries, they are present only in the hard version."Interplanetary S... | 9 8
)(()())()
2 3 6
2 2 7
1 3 4
2 2 7
2 2 9
1 5 6
1 2 7
2 8 9
| 3 4 2 4 1 | 6 seconds | 256 megabytes | ['binary search', 'data structures', 'dfs and similar', 'graphs', 'trees', '*2800'] |
E1. Cats on the Upgrade (easy version)time limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the easy version of the problem. The only difference between the easy and the hard versions are removal queries, they are present only in the hard version."Interplanetary S... | 9 4
)(()())()
2 3 6
2 2 7
2 8 9
2 2 9
| 3 4 1 6 | 6 seconds | 256 megabytes | ['brute force', 'data structures', 'dfs and similar', 'divide and conquer', 'dp', 'graphs', 'trees', '*2500'] |
D. Binary Spiderstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBinary Spiders are species of spiders that live on Mars. These spiders weave their webs to defend themselves from enemies.To weave a web, spiders join in pairs. If the first spider in pair has x legs, ... | 6 8
2 8 4 16 10 14
| 3 1 5 4 | 2 seconds | 256 megabytes | ['bitmasks', 'data structures', 'implementation', 'math', 'sortings', 'trees', '*2300'] |
C. Road Optimizationtime limit per test3 secondsmemory limit per test128 megabytesinputstandard inputoutputstandard outputThe Government of Mars is not only interested in optimizing space flights, but also wants to improve the road system of the planet.One of the most important highways of Mars connects Olymp City and ... | 4 10 0
0 3 4 8
5 8 3 6
| 47 | 3 seconds | 128 megabytes | ['dp', '*1700'] |
B. Elementary Particlestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMartians are actively engaged in interplanetary trade. Olymp City, the Martian city known for its spaceport, has become a place where goods from all the corners of our Galaxy come. To deliver eve... | 473 1 5 2 1 3 461 1 1 1 1 161 4 2 8 5 7215 15 | 4 5 -1 1 | 2 seconds | 256 megabytes | ['brute force', 'greedy', 'sortings', '*1100'] |
A. Ancient Civilizationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMartian scientists explore Ganymede, one of Jupiter's numerous moons. Recently, they have found ruins of an ancient civilization. The scientists brought to Mars some tablets with writings in a lan... | 7
3 5
18 9 21
3 5
18 18 18
1 1
1
5 30
1 2 3 4 5
6 10
99 35 85 46 78 55
2 1
0 1
8 8
5 16 42 15 83 65 78 42
| 17 18 1 1 39 0 2 | 1 second | 256 megabytes | ['bitmasks', 'greedy', 'math', '*800'] |
G. MinOr Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently, Vlad has been carried away by spanning trees, so his friends, without hesitation, gave him a connected weighted undirected graph of n vertices and m edges for his birthday.Vlad defined the ority ... | 3
3 3
1 2 1
2 3 2
1 3 2
5 7
4 2 7
2 5 8
3 4 2
3 2 1
2 4 2
4 1 2
1 2 2
3 4
1 2 1
2 3 2
1 3 3
3 1 4
| 2 10 3 | 2 seconds | 256 megabytes | ['bitmasks', 'dfs and similar', 'dsu', 'graphs', 'greedy', '*1900'] |
F. Interacdive Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is interactive.We decided to play a game with you and guess the number x (1 \le x < n), where you know the number n.You can make queries like this: + c: this command assigns x = x + c ... | 3
1 | + 1 ! 3 | 1 second | 256 megabytes | ['binary search', 'constructive algorithms', 'interactive', '*2000'] |
E. Masha-forgetfultime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMasha meets a new friend and learns his phone number — s. She wants to remember it as soon as possible. The phone number — is a string of length m that consists of digits from 0 to 9. The phone number... | 5
4 8
12340219
20215601
56782022
12300678
12345678
2 3
134
126
123
1 4
1210
1221
4 3
251
064
859
957
054
4 7
7968636
9486033
4614224
5454197
9482268
| 3 1 4 1 5 6 2 3 4 3 -1 2 1 2 1 2 3 1 -1 3 1 3 2 5 6 3 3 4 1 | 3 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'dp', 'hashing', 'implementation', 'strings', '*2000'] |
D. Palindromes Coloringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a string s consisting of lowercase Latin alphabet letters. You can color some letters in colors from 1 to k. It is not necessary to paint all the letters. But for each color, there must ... | 10
8 2
bxyaxzay
6 3
aaaaaa
6 1
abcdef
6 6
abcdef
3 2
dxd
11 2
abcabcabcac
6 6
sipkic
7 2
eatoohd
3 1
llw
6 2
bfvfbv
| 3 2 1 1 1 5 1 1 3 3 | 2 seconds | 256 megabytes | ['binary search', 'greedy', 'sortings', 'strings', '*1400'] |
C. Division by Two and Permutationtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n positive integers. You can perform operations on it.In one operation you can replace any element of the array a_i with \lfloor \frac{a_i}{2} \r... | 6
4
1 8 25 2
2
1 1
9
9 8 3 4 2 7 1 5 6
3
8 2 1
4
24 7 16 7
5
22 6 22 4 22
| YES NO YES NO NO YES | 3 seconds | 256 megabytes | ['constructive algorithms', 'flows', 'graph matchings', 'greedy', 'math', '*1100'] |
B. Make APtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has 3 positive integers a, b and c. He can perform the following operation exactly once. Choose a positive integer m and multiply exactly one of the integers a, b or c by m. Can Polycarp make it so ... | 11
10 5 30
30 5 10
1 2 3
1 6 3
2 6 3
1 1 1
1 1 2
1 1 3
1 100000000 1
2 1 1
1 2 2
| YES YES YES YES NO YES NO YES YES NO YES | 2 seconds | 256 megabytes | ['implementation', 'math', '*900'] |
A. Plus One on the Subsettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp got an array of integers a[1 \dots n] as a gift. Now he wants to perform a certain number of operations (possibly zero) so that all elements of the array become the same (that is, to b... | 3
6
3 4 2 4 1 2
3
1000 1002 998
2
12 11
| 3 4 1 | 2 seconds | 256 megabytes | ['math', '*800'] |
E. Middle Duplicationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA binary tree of n nodes is given. Nodes of the tree are numbered from 1 to n and the root is the node 1. Each node can have no child, only one left child, only one right child, or both children. Fo... | 4 3
abab
2 3
0 0
0 4
0 0
| baaaab | 1 second | 256 megabytes | ['data structures', 'dfs and similar', 'greedy', 'strings', 'trees', '*2500'] |
D. Robot Cleaner Revisittime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe statement of this problem shares a lot with problem A. The differences are that in this problem, the probability is introduced, and the constraint is different.A robot cleaner is placed on t... | 6
2 2 1 1 2 1 25
3 3 1 2 2 2 25
10 10 1 1 10 10 75
10 10 10 10 1 1 75
5 5 1 3 2 2 10
97 98 3 5 41 43 50
| 3 3 15 15 332103349 99224487 | 3 seconds | 256 megabytes | ['implementation', 'math', 'probabilities', '*2300'] |
C. Balanced Stone Heapstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once: You go through the heaps from the 3-rd hea... | 4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
| 7 1 1 3 | 1 second | 256 megabytes | ['binary search', 'greedy', '*1600'] |
B. Game on Rangestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob play the following game. Alice has a set S of disjoint ranges of integers, initially containing only one range [1, n]. In one turn, Alice picks a range [l, r] from the set S and asks Bob t... | 4
1
1 1
3
1 3
2 3
2 2
6
1 1
3 5
4 4
3 6
4 5
1 6
5
1 5
1 2
4 5
2 2
4 4
| 1 1 1 1 3 1 2 2 2 2 3 3 1 1 1 3 5 3 4 4 4 3 6 6 4 5 5 1 6 2 1 5 3 1 2 1 4 5 5 2 2 2 4 4 4 | 1 second | 256 megabytes | ['brute force', 'dfs and similar', 'implementation', 'sortings', '*1100'] |
A. Robot Cleanertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA robot cleaner is placed on the floor of a rectangle room, surrounded by walls. The floor consists of n rows and m columns. The rows of the floor are numbered from 1 to n from top to bottom, and columns... | 5
10 10 6 1 2 8
10 10 9 9 1 1
9 8 5 6 2 1
6 9 2 2 5 8
2 2 1 1 2 1
| 7 10 9 3 0 | 1 second | 256 megabytes | ['brute force', 'implementation', 'math', '*800'] |
F. Quadratic Settime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call a set of positive integers a_1, a_2, \dots, a_k quadratic if the product of the factorials of its elements is a square of an integer, i. e. \prod\limits_{i=1}^{k} a_i! = m^2, for some integer... | 1
| 1 1 | 4 seconds | 256 megabytes | ['constructive algorithms', 'hashing', 'math', 'number theory', '*2900'] |
E. Math Testtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya is a math teacher. n of his students has written a test consisting of m questions. For each student, it is known which questions he has answered correctly and which he has not.If the student answers t... | 3
4 3
5 1 2 2
110
100
101
100
4 4
6 2 0 10
1001
0010
0110
0101
3 6
20 3 15
010110
000101
111111
| 3 1 2 2 3 4 1 3 1 4 5 2 6 | 2 seconds | 256 megabytes | ['bitmasks', 'brute force', 'greedy', '*2200'] |
D. Shuffletime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a binary string (i. e. a string consisting of characters 0 and/or 1) s of length n. You can perform the following operation with the string s at most once: choose a substring (a contiguous subse... | 7 2
1100110
| 16 | 2 seconds | 512 megabytes | ['combinatorics', 'math', 'two pointers', '*2000'] |
C. Set or Decreasetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer array a_1, a_2, \dots, a_n and integer k.In one step you can either choose some index i and decrease a_i by one (make a_i = a_i - 1); or choose two indices i and j and set ... | 4
1 10
20
2 69
6 9
7 8
1 2 1 3 1 2 1
10 1
1 2 3 1 2 6 1 6 8 10
| 10 0 2 7 | 2 seconds | 256 megabytes | ['binary search', 'brute force', 'greedy', 'sortings', '*1600'] |
B. Berland Musictime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland Music is a music streaming service built specifically to support Berland local artist. Its developers are currently working on a song recommendation module.So imagine Monocarp got recommended n ... | 3
2
1 2
10
3
3 1 2
111
8
2 3 1 8 5 4 7 6
01110001
| 2 1 3 1 2 1 6 5 8 3 2 4 7 | 2 seconds | 256 megabytes | ['data structures', 'greedy', 'math', 'sortings', '*1000'] |
A. Construct a Rectangletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are three sticks with integer lengths l_1, l_2 and l_3.You are asked to break exactly one of them into two pieces in such a way that: both pieces have positive (strictly greater than 0) ... | 4
6 1 5
2 5 2
2 4 2
5 5 4
| YES NO YES YES | 2 seconds | 256 megabytes | ['geometry', 'math', '*800'] |
I. Two Sequencestime limit per test8 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider an array of integers C = [c_1, c_2, \ldots, c_n] of length n. Let's build the sequence of arrays D_0, D_1, D_2, \ldots, D_{n} of length n+1 in the following way: The first element of this sequ... | 4
2 1 3 1
4
1 1
1 2
1 3
1 4
| 2 1 1 3 | 8 seconds | 256 megabytes | ['data structures', 'hashing', 'string suffix structures', '*3500'] |
H. Trains and Airplanestime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputRailway network of one city consists of n stations connected by n-1 roads. These stations and roads forms a tree. Station 1 is a city center. For each road you know the time trains spend to pass ... | 8
1 2 7
2 3 4
2 4 3
4 5 1
5 6 6
4 7 10
6 8 6
4
AABABBDB
11 12 10 42
16 15 15 30
4
6
3 2
1 A 10
3 3
2 A 3
3 7
3 6
| 0 10 6 6 | 4 seconds | 512 megabytes | ['dfs and similar', 'graphs', 'shortest paths', 'trees', '*3500'] |
G. Weighted Increasing Subsequencestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given the sequence of integers a_1, a_2, \ldots, a_n of length n. The sequence of indices i_1 < i_2 < \ldots < i_k of length k denotes the subsequence a_{i_1}, a_{i_2}, \ldots,... | 4
5
6 4 8 6 5
4
1 2 3 4
3
3 2 2
4
4 5 6 5
| 4 12 0 6 | 1 second | 256 megabytes | ['data structures', 'dp', 'math', '*3200'] |
F. Strange Instructionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDasha has 10^{100} coins. Recently, she found a binary string s of length n and some operations that allows to change this string (she can do each operation any number of times): Replace substri... | 3
5 2 2 1
01101
6 4 3 5
110001
6 3 2 1
011110
| 3 11 4 | 2 seconds | 256 megabytes | ['data structures', 'greedy', 'implementation', '*2700'] |
E. New Schooltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have decided to open a new school. You have already found n teachers and m groups of students. The i-th group of students consists of k_i \geq 2 students. You know age of each teacher and each student.... | 2
1 1
30
3
25 16 37
4 2
9 12 12 6
2
4 5
3
111 11 11
| 101 00100 | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'dp', 'greedy', 'implementation', 'sortings', '*2300'] |
D. The Winter Hiketime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputCircular land is an 2n \times 2n grid. Rows of this grid are numbered by integers from 1 to 2n from top to bottom and columns of this grid are numbered by integers from 1 to 2n from left to right. The ... | 4
1
0 8
1 99
2
0 0 0 0
0 0 0 0
9 9 2 2
9 9 9 9
2
0 0 4 2
0 0 2 4
4 2 4 2
2 4 2 4
4
0 0 0 0 0 0 0 2
0 0 0 0 0 0 2 0
0 0 0 0 0 2 0 0
0 0 0 0 2 0 0 0
0 0 0 2 2 0 2 2
0 0 2 0 1 6 2 1
0 2 0 0 2 4 7 4
2 0 0 0 2 0 1 6
| 100 22 14 42 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'math', '*2100'] |
C. Hidden Permutationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.The jury has a permutation p of length n and wants you to guess it. For this, the jury created another permutation q of length n. Initially, q is an identity permutat... | 2
4
3
2
1
4
2
4
4 | ? 3 ? 2 ? 4 ! 4 2 1 3 ? 2 ? 3 ? 2 ! 1 3 4 2 | 1 second | 256 megabytes | ['dfs and similar', 'interactive', 'math', '*1700'] |
B. Integers Shoptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe integers shop sells n segments. The i-th of them contains all integers from l_i to r_i and costs c_i coins.Tomorrow Vasya will go to this shop and will buy some segments there. He will get all integ... | 3
2
2 4 20
7 8 22
2
5 11 42
5 11 42
6
1 4 4
5 8 9
7 8 7
2 10 252
1 11 271
1 10 1
| 20 42 42 42 4 13 11 256 271 271 | 2 seconds | 256 megabytes | ['data structures', 'greedy', 'implementation', '*1500'] |
A. Stable Arrangement of Rookstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have an n \times n chessboard and k rooks. Rows of this chessboard are numbered by integers from 1 to n from top to bottom and columns of this chessboard are numbered by integers from 1... | 5
3 2
3 3
1 1
5 2
40 33
| ..R ... R.. -1 R ..... R.... ..... ....R ..... -1 | 1 second | 256 megabytes | ['constructive algorithms', '*800'] |
G. Subsequences Galoretime limit per test10 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputFor a sequence of strings [t_1, t_2, \dots, t_m], let's define the function f([t_1, t_2, \dots, t_m]) as the number of different strings (including the empty string) that are subsequences of at ... | 3
a
b
c
| 92 | 10 seconds | 1024 megabytes | ['bitmasks', 'combinatorics', 'dp', '*2400'] |
F. Bipartite Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a permutation p consisting of n integers 1, 2, \dots, n (a permutation is an array where each element from 1 to n occurs exactly once).Let's call an array a bipartite if the following un... | 4
3
1 2 3
6
1 3 2 6 5 4
4
4 1 3 2
8
3 2 1 6 7 8 5 4
| YES 1 2 3 NO YES -4 -1 -3 -2 YES -3 -2 1 6 7 -8 -5 -4 | 2 seconds | 256 megabytes | ['dp', 'greedy', '*2800'] |
E. Replace the Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have an array of integers (initially empty).You have to perform q queries. Each query is of one of two types: "1 x" — add the element x to the end of the array; "2 x y" — replace all occurr... | 7
1 3
1 1
2 1 2
1 2
1 1
1 2
2 1 3
| 3 2 2 3 2 | 2 seconds | 256 megabytes | ['constructive algorithms', 'data structures', 'dsu', 'implementation', '*1900'] |
D. Exact Changetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day, early in the morning, you decided to buy yourself a bag of chips in the nearby store. The store has chips of n different flavors. A bag of the i-th flavor costs a_i burles.The store may run out ... | 4
1
1337
3
10 8 10
5
1 2 3 4 5
3
7 77 777
| 446 4 3 260 | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'greedy', '*2000'] |
C. BA-Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer k and a string s that consists only of characters 'a' (a lowercase Latin letter) and '*' (an asterisk).Each asterisk should be replaced with several (from 0 to k inclusive) lowercas... | 3
2 4 3
a*
4 1 3
a**a
6 3 20
**a***
| abb abba babbbbbbbbb | 2 seconds | 256 megabytes | ['brute force', 'dp', 'greedy', 'implementation', 'math', '*1800'] |
B. Triangles on a Rectangletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA rectangle with its opposite corners in (0, 0) and (w, h) and sides parallel to the axes is drawn on a plane.You are given a list of lattice points such that each point lies on a side of a r... | 3
5 8
2 1 2
3 2 3 4
3 1 4 6
2 4 5
10 7
2 3 9
2 1 7
3 1 3 4
3 4 5 6
11 5
3 1 6 8
3 3 6 8
3 1 3 4
2 2 4
| 25 42 35 | 2 seconds | 256 megabytes | ['geometry', 'greedy', 'math', '*1000'] |
A. Equal or Not Equaltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou had n positive integers a_1, a_2, \dots, a_n arranged in a circle. For each pair of neighboring numbers (a_1 and a_2, a_2 and a_3, ..., a_{n - 1} and a_n, and a_n and a_1), you wrote down: are ... | 4
EEE
EN
ENNEENE
NENN
| YES NO YES YES | 2 seconds | 256 megabytes | ['constructive algorithms', 'dsu', 'implementation', '*800'] |
H. Permutation and Queriestime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a permutation p of n elements. A permutation of n elements is an array of length n containing each integer from 1 to n exactly once. For example, [1, 2, 3] and [4, 3, 5, 1, 2] ar... | 5 4
5 3 4 2 1
2 3 1
2 1 2
1 1 3
2 1 2
| 4 1 2 | 4 seconds | 256 megabytes | ['brute force', 'data structures', 'divide and conquer', 'two pointers', '*2400'] |
G. Unusual Minesweepertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is very fond of playing the game Minesweeper. Recently he found a similar game and there are such rules.There are mines on the field, for each the coordinates of its location are known (x... | 3
5 0
0 0 1
0 1 4
1 0 2
1 1 3
2 2 9
5 2
0 0 1
0 1 4
1 0 2
1 1 3
2 2 9
6 1
1 -1 3
0 -1 9
0 1 7
-1 0 1
-1 1 9
-1 -1 7
| 2 1 0 | 2 seconds | 256 megabytes | ['binary search', 'dfs and similar', 'dsu', 'greedy', 'sortings', '*2000'] |
F. Let's Play the Hat?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Hat is a game of speedy explanation/guessing words (similar to Alias). It's fun. Try it! In this problem, we are talking about a variant of the game when the players are sitting at the table a... | 3
5 2 2
8 3 1
2 1 3
| 3 1 2 3 2 4 5 3 4 5 2 2 1 3 2 6 2 3 3 5 1 3 4 7 8 2 2 1 2 2 1 2 2 1 | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'greedy', 'math', '*2000'] |
E. MEX and Incrementstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDmitry has an array of n non-negative integers a_1, a_2, \dots, a_n.In one operation, Dmitry can choose any index j (1 \le j \le n) and increase the value of the element a_j by 1. He can choose the... | 5
3
0 1 3
7
0 1 2 3 4 3 2
4
3 0 0 0
7
4 6 2 3 5 0 5
5
4 0 1 0 4
| 1 1 0 -1 1 1 2 2 1 0 2 6 3 0 1 4 3 1 0 -1 -1 -1 -1 -1 -1 2 1 0 2 -1 -1 | 2 seconds | 256 megabytes | ['constructive algorithms', 'data structures', 'dp', 'greedy', 'implementation', 'math', 'sortings', '*1700'] |
D. New Year's Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVlad has n friends, for each of whom he wants to buy one gift for the New Year.There are m shops in the city, in each of which he can buy a gift for any of his friends. If the j-th friend (1 \le j ... | 5
2 2
1 2
3 4
4 3
1 3 1
3 1 1
1 2 2
1 1 3
2 3
5 3 4
2 5 1
4 2
7 9
8 1
9 6
10 8
2 4
6 5 2 1
7 9 7 2
| 3 2 4 8 2 | 2 seconds | 256 megabytes | ['binary search', 'greedy', 'sortings', '*1800'] |
C. Wrong Additiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTanya is learning how to add numbers, but so far she is not doing it correctly. She is adding two numbers a and b using the following algorithm: If one of the numbers is shorter than the other, Tanya a... | 6
17236 1106911
1 5
108 112
12345 1023412
1 11
1 20
| 3465 4 -1 90007 10 -1 | 1 second | 256 megabytes | ['implementation', '*1200'] |
B. Squares and Cubestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp likes squares and cubes of positive integers. Here is the beginning of the sequence of numbers he likes: 1, 4, 8, 9, ....For a given number n, count the number of integers from 1 to n that P... | 6
10
1
25
1000000000
999999999
500000000
| 4 1 6 32591 32590 23125 | 1 second | 256 megabytes | ['implementation', 'math', '*800'] |
A. Square String?time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA string is called square if it is some string written twice in a row. For example, the strings "aa", "abcabc", "abab" and "baabaa" are square. But the strings "aaa", "abaaab" and "abcdabc" are not squa... | 10
a
aa
aaa
aaaa
abab
abcabc
abacaba
xxyy
xyyx
xyxy
| NO YES NO YES YES YES NO NO NO YES | 1 second | 256 megabytes | ['implementation', 'strings', '*800'] |
G. Trader Problemtime limit per test4.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMonocarp plays a computer game (yet again!). This game has a unique trading mechanics.To trade with a character, Monocarp has to choose one of the items he possesses and trade it for some item the ot... | 3 4 5
10 30 15
12 31 14 18
0 1 2 3 4
| 55 56 60 64 64 | 4.5 seconds | 512 megabytes | ['data structures', 'dsu', 'greedy', 'sortings', '*2200'] |
F. Reversetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two positive integers x and y. You can perform the following operation with x: write it in its binary form without leading zeros, add 0 or 1 to the right of it, reverse the binary form and turn ... | 3 3
| YES | 2 seconds | 256 megabytes | ['bitmasks', 'constructive algorithms', 'dfs and similar', 'implementation', 'math', 'strings', '*2000'] |
E. Singers' Tourtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputn towns are arranged in a circle sequentially. The towns are numbered from 1 to n in clockwise order. In the i-th town, there lives a singer with a repertoire of a_i minutes for each i \in [1, n].Each s... | 4
3
12 16 14
1
1
3
1 2 3
6
81 75 75 93 93 87
| YES 3 1 3 YES 1 NO YES 5 5 4 1 4 5 | 2 seconds | 256 megabytes | ['constructive algorithms', 'math', '*1700'] |
D. Array and Operationstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an array a of n integers, and another integer k such that 2k \le n.You have to perform exactly k operations with this array. In one operation, you have to choose two elements of the... | 5
7 3
1 1 1 2 1 3 1
5 1
5 5 5 5 5
4 2
1 3 3 7
2 0
4 2
9 2
1 10 10 1 10 2 7 10 3
| 2 16 0 6 16 | 2 seconds | 512 megabytes | ['dp', 'greedy', 'math', '*1300'] |
C. Paint the Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n positive integers. You have to choose a positive integer d and paint all elements into two colors. All elements which are divisible by d will be painted red, a... | 5
5
1 2 3 4 5
3
10 5 15
3
100 10 200
10
9 8 2 6 6 2 8 6 5 4
2
1 3
| 2 0 100 0 3 | 2 seconds | 256 megabytes | ['math', '*1100'] |
B. Missing Bigramtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has come up with a new game to play with you. He calls it "A missing bigram".A bigram of a word is a sequence of two adjacent letters in it.For example, word "abbaaba" contains bigrams "ab", "... | 4
7
ab bb ba aa ba
7
ab ba aa ab ba
3
aa
5
bb ab bb
| abbaaba abaabaa baa bbabb | 2 seconds | 256 megabytes | ['implementation', '*800'] |
A. Polycarp and Sums of Subsequencestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp had an array a of 3 positive integers. He wrote out the sums of all non-empty subsequences of this array, sorted them in non-decreasing order, and got an array b of 7 integer... | 5
1 3 4 4 5 7 8
1 2 3 4 5 6 7
300000000 300000000 300000000 600000000 600000000 600000000 900000000
1 1 2 999999998 999999999 999999999 1000000000
1 2 2 3 3 4 5
| 1 4 3 4 1 2 300000000 300000000 300000000 999999998 1 1 1 2 2 | 1 second | 256 megabytes | ['math', 'sortings', '*800'] |
E. Christmas Chocolatestime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputChristmas is coming, Icy has just received a box of chocolates from her grandparents! The box contains n chocolates. The i-th chocolate has a non-negative integer type a_i.Icy believes that good ... | 5
5 6 7 8 9
| 2 5 5 | 4 seconds | 512 megabytes | ['dfs and similar', 'dp', 'games', 'graphs', 'implementation', 'math', 'number theory', 'shortest paths', 'trees', '*2700'] |
D2. Too Many Impostors (hard version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem. The only difference between the easy and hard version is the limit on number of questions.There are n players labelled from 1 to n. It is guaranteed ... | 2
6
0
1
9
1 | ? 1 2 3 ? 3 4 5 ! 3 4 1 2 ? 7 1 9 ! 4 2 3 6 8 | 3 seconds | 256 megabytes | ['constructive algorithms', 'implementation', 'interactive', 'math', '*2400'] |
D1. Too Many Impostors (easy version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem. The only difference between the easy and hard version is the limit on number of questions.There are n players labelled from 1 to n. It is guaranteed ... | 2
6
0
1
9
1 | ? 1 2 3 ? 3 4 5 ! 3 4 1 2 ? 7 1 9 ! 4 2 3 6 8 | 3 seconds | 256 megabytes | ['constructive algorithms', 'implementation', 'interactive', '*1800'] |
C. Paprika and Permutationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPaprika loves permutations. She has an array a_1, a_2, \dots, a_n. She wants to make the array a permutation of integers 1 to n.In order to achieve this goal, she can perform operations on the ... | 4
2
1 7
3
1 5 4
4
12345678 87654321 20211218 23571113
9
1 2 3 4 18 19 5 6 7
| 1 -1 4 2 | 1 second | 256 megabytes | ['binary search', 'greedy', 'math', 'sortings', '*1300'] |
B. GCD Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven a positive integer n. Find three distinct positive integers a, b, c such that a + b + c = n and \operatorname{gcd}(a, b) = c, where \operatorname{gcd}(x, y) denotes the greatest common divisor (GCD)... | 6
18
63
73
91
438
122690412
| 6 9 3 21 39 3 29 43 1 49 35 7 146 219 73 28622 122661788 2 | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'math', 'number theory', '*900'] |
A. Forbidden Subsequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given strings S and T, consisting of lowercase English letters. It is guaranteed that T is a permutation of the string abc. Find string S', the lexicographically smallest permutation of S... | 7
abacaba
abc
cccba
acb
dbsic
bac
abracadabra
abc
dddddddddddd
cba
bbc
abc
ac
abc
| aaaacbb abccc bcdis aaaaacbbdrr dddddddddddd bbc ac | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'sortings', 'strings', '*800'] |
H. Keep XOR Lowtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a_1, a_2, \ldots, a_n and an integer x.Find the number of non-empty subsets of indices of this array 1 \leq b_1 < b_2 < \ldots < b_k \leq n, such that for all pairs (i, j) where 1 \... | 4 2
0 1 2 3
| 8 | 1 second | 256 megabytes | ['bitmasks', 'combinatorics', 'data structures', 'divide and conquer', 'dp', 'math', '*3000'] |
G. Just Add an Edgetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a directed acyclic graph with n vertices and m edges. For all edges a \to b in the graph, a < b holds.You need to find the number of pairs of vertices x, y, such that x > y and after add... | 3
3 2
1 2
2 3
4 3
1 2
3 4
1 4
4 4
1 3
1 4
2 3
3 4
| 3 1 4 | 1 second | 256 megabytes | ['dfs and similar', 'dp', 'graphs', '*3500'] |
F. Tricolor Trianglestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a simple undirected graph with n vertices and m edges. Edge i is colored in the color c_i, which is either 1, 2, or 3, or left uncolored (in this case, c_i = -1).You need to color all ... | 4
3 3
1 2 1
2 3 2
3 1 -1
3 3
1 2 1
2 3 1
3 1 -1
4 4
1 2 -1
2 3 -1
3 4 -1
4 1 -1
3 3
1 2 1
2 3 1
3 1 2
| 1 2 3 1 1 1 1 2 2 3 -1 | 1 second | 256 megabytes | ['brute force', 'graphs', 'math', 'matrices', '*2900'] |
E. Lexicographically Small Enoughtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two strings s and t of equal length n. In one move, you can swap any two adjacent characters of the string s.You need to find the minimal number of operations you need to m... | 4
1
a
a
3
rll
rrr
3
caa
aca
5
ababa
aabba
| -1 0 2 2 | 1 second | 256 megabytes | ['brute force', 'data structures', 'greedy', 'strings', '*2200'] |
D. Keep the Average Hightime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array of integers a_1, a_2, \ldots, a_n and an integer x.You need to select the maximum number of elements in the array, such that for every subsegment a_l, a_{l + 1}, \ldots,... | 4
5
1 2 3 4 5
2
10
2 4 2 4 2 4 2 4 2 4
3
3
-10 -5 -10
-8
3
9 9 -3
5
| 4 8 2 2 | 1.5 seconds | 256 megabytes | ['dp', 'greedy', 'math', '*2000'] |
C. Representative Edgestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn array a_1, a_2, \ldots, a_n is good if and only if for every subsegment 1 \leq l \leq r \leq n, the following holds: a_l + a_{l + 1} + \ldots + a_r = \frac{1}{2}(a_l + a_r) \cdot (r - l + 1). Y... | 5
4
1 2 3 4
4
1 1 2 2
2
0 -1
6
3 -2 4 -1 -4 0
1
-100
| 0 2 0 3 0 | 1 second | 256 megabytes | ['brute force', 'geometry', 'implementation', 'math', '*1500'] |
B. Mirror in the Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a string s_1 s_2 \ldots s_n and you stand on the left of the string looking right. You want to choose an index k (1 \le k \le n) and place a mirror after the k-th letter, so that what you... | 4
10
codeforces
9
cbacbacba
3
aaa
4
bbaa
| cc cbaabc aa bb | 1 second | 256 megabytes | ['greedy', 'strings', '*1100'] |
A. Integer Diversitytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n integers a_1, a_2, \ldots, a_n. You choose any subset of the given numbers (possibly, none or all numbers) and negate these numbers (i. e. change x \to (-x)). What is the maximum numb... | 3
4
1 1 2 2
3
1 2 3
2
0 0
| 4 3 1 | 1 second | 256 megabytes | ['implementation', '*800'] |
H. Reindeer Gamestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n reindeer at the North Pole, all battling for the highest spot on the "Top Reindeer" leaderboard on the front page of CodeNorses (a popular competitive reindeer gaming website). Interestingl... | 7 6
3 1 4 9 2 5 6
1 2
2 3
3 4
4 5
5 6
6 7
| 1 1 4 4 4 5 6 | 2 seconds | 256 megabytes | ['binary search', 'constructive algorithms', 'data structures', 'divide and conquer', 'flows', 'graphs', 'shortest paths', '*3000'] |
G. Maximum Adjacent Pairstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n non-negative integers.You have to replace each 0 in a with an integer from 1 to n (different elements equal to 0 can be replaced by different integers).... | 4
1 1 0 2
| 1 1 2 2 | 3 seconds | 512 megabytes | ['constructive algorithms', 'graph matchings', '*3300'] |
F. LEGOndary Grandmastertime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAfter getting bored by playing with crayons, you decided to switch to Legos! Today, you're working with a long strip, with height 1 and length n, some positions of which are occupied by 1 by 1 L... | 6
2
00
11
3
???
???
3
??1
0?0
4
??0?
??11
5
?????
0??1?
10
?01??01?1?
??100?1???
| 1 16 1 14 101 1674 | 2 seconds | 512 megabytes | ['combinatorics', 'dp', 'math', '*2800'] |
E. Purple Crayontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo players, Red and Blue, are at it again, and this time they're playing with crayons! The mischievous duo is now vandalizing a rooted tree, by coloring the nodes while playing their favorite game.The ... | 4 2
1 2
1 3
1 4
| 1 | 2 seconds | 256 megabytes | ['data structures', 'dfs and similar', 'games', 'graphs', 'greedy', 'math', 'sortings', 'trees', '*2400'] |
D. X(or)-mas Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output'Twas the night before Christmas, and Santa's frantically setting up his new Christmas tree! There are n nodes in the tree, connected by n-1 edges. On each edge of the tree, there's a set of Christmas ... | 4
6 5
1 2 -1
1 3 1
4 2 7
6 3 0
2 5 -1
2 3 1
2 5 0
5 6 1
6 1 1
4 5 1
5 3
1 2 -1
1 3 -1
1 4 1
4 5 -1
2 4 0
3 4 1
2 3 1
3 3
1 2 -1
1 3 -1
1 2 0
1 3 1
2 3 0
2 1
1 2 1
1 2 0
| YES 1 2 0 1 3 1 2 4 7 3 6 0 2 5 0 YES 1 2 1 1 3 0 1 4 1 4 5 1 NO NO | 2 seconds | 256 megabytes | ['bitmasks', 'dfs and similar', 'dsu', 'graphs', 'trees', '*2200'] |
C. Menorahtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n candles on a Hanukkah menorah, and some of its candles are initially lit. We can describe which candles are lit with a binary string s, where the i-th candle is lit if and only if s_i=1. Initiall... | 5
5
11010
11010
2
01
11
3
000
101
9
100010111
101101100
9
001011011
011010101
| 0 1 -1 3 4 | 2 seconds | 256 megabytes | ['brute force', 'graphs', 'greedy', 'math', '*1600'] |
B. And It's Non-Zerotime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array consisting of all integers from [l, r] inclusive. For example, if l = 2 and r = 5, the array would be [2, 3, 4, 5]. What's the minimum number of elements you can delete to mak... | 5
1 2
2 8
4 5
1 5
100000 200000
| 1 3 0 2 31072 | 2 seconds | 256 megabytes | ['bitmasks', 'greedy', 'math', '*1300'] |
A. Closing The Gaptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n block towers in a row, where tower i has a height of a_i. You're part of a building crew, and you want to make the buildings look as nice as possible. In a single day, you can perform the ... | 3
3
10 10 10
4
3 2 1 2
5
1 2 3 1 5
| 0 0 1 | 2 seconds | 256 megabytes | ['greedy', 'math', '*800'] |
E. Divan and a Cottagetime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputDivan's new cottage is finally complete! However, after a thorough inspection, it turned out that the workers had installed the insulation incorrectly, and now the temperature in the house direct... | 3
50
3
1 2 3
50
3
4 5 6
0
3
7 8 9
| 2 5 9 15 22 30 38 47 53 | 2 seconds | 1024 megabytes | ['binary search', 'data structures', '*2600'] |
D2. Divan and Kostomuksha (hard version)time limit per test4 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputThis is the hard version of the problem. The only difference is maximum value of a_i.Once in Kostomuksha Divan found an array a consisting of positive integers. Now he wants to ... | 6
2 3 1 2 6 2
| 14 | 4 seconds | 1024 megabytes | ['dp', 'number theory', '*2300'] |
D1. Divan and Kostomuksha (easy version)time limit per test4 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputThis is the easy version of the problem. The only difference is maximum value of a_i.Once in Kostomuksha Divan found an array a consisting of positive integers. Now he wants to ... | 6
2 3 1 2 6 2
| 14 | 4 seconds | 1024 megabytes | ['dp', 'number theory', '*2100'] |
C. Divan and bitwise operationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce Divan analyzed a sequence a_1, a_2, \ldots, a_n consisting of n non-negative integers as follows. He considered each non-empty subsequence of the sequence a, computed the bitwise XOR ... | 3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
| 4 20 112 | 1 second | 256 megabytes | ['bitmasks', 'combinatorics', 'constructive algorithms', 'dp', 'math', '*1500'] |
B. Divan and a New Project time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe company "Divan's Sofas" is planning to build n + 1 different buildings on a coordinate line so that: the coordinate of each building is an integer number; no two buildings stand at the ... | 4
3
1 2 3
5
3 8 10 6 1
5
1 1 1 1 1
1
0
| 14 2 4 1 3 78 1 -1 0 2 3 4 18 3 6 1 5 2 4 0 1 2 | 1 second | 256 megabytes | ['constructive algorithms', 'sortings', '*1000'] |
A. Divan and a Storetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBusinessman Divan loves chocolate! Today he came to a store to buy some chocolate. Like all businessmen, Divan knows the value of money, so he will not buy too expensive chocolate. At the same time, ... | 8
3 1 100 100
50 100 50
6 3 5 10
1 2 3 4 5 6
6 3 5 21
1 2 3 4 5 6
10 50 69 100
20 30 40 77 1 1 12 4 70 10000
3 50 80 30
20 60 70
10 2 7 100
2 2 2 2 2 7 7 7 7 7
4 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
1 1 1 1
1
| 2 2 3 0 0 10 1 1 | 1 second | 256 megabytes | ['brute force', 'constructive algorithms', 'greedy', '*800'] |
F. Tree Coloringtime limit per test4.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree consisting of n vertices numbered from 1 to n. The root of the tree is the vertex 1.You have to color all vertices of the tree into n colors (also numbered from 1 to n) so ... | 5
1 2
3 2
4 2
2 5
| 42 | 4.5 seconds | 512 megabytes | ['combinatorics', 'divide and conquer', 'fft', '*2600'] |
E. Crazy Robottime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere is a grid, consisting of n rows and m columns. Each cell of the grid is either free or blocked. One of the free cells contains a lab. All the cells beyond the borders of the grid are also blocked.A ... | 4
3 3
...
.L.
...
4 5
#....
..##L
...#.
.....
1 1
L
1 9
....L..#.
| ... .L. ... #++++ ..##L ...#+ ...++ L ++++L++#. | 2 seconds | 512 megabytes | ['dfs and similar', 'graphs', '*2000'] |
D. MEX Sequencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call a sequence of integers x_1, x_2, \dots, x_k MEX-correct if for all i (1 \le i \le k) |x_i - \operatorname{MEX}(x_1, x_2, \dots, x_i)| \le 1 holds. Where \operatorname{MEX}(x_1, \dots, x_k) is... | 4
3
0 2 1
2
1 0
5
0 0 0 0 0
4
0 1 2 3
| 4 2 31 7 | 2 seconds | 256 megabytes | ['dp', 'math', '*1900'] |
C. Poisoned Daggertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMonocarp is playing yet another computer game. In this game, his character has to kill a dragon. The battle with the dragon lasts 100^{500} seconds, during which Monocarp attacks the dragon with a poi... | 4
2 5
1 5
3 10
2 4 10
5 3
1 2 4 5 7
4 1000
3 25 64 1337
| 3 4 1 470 | 2 seconds | 256 megabytes | ['binary search', '*1200'] |
B. Absent Remaindertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence a_1, a_2, \dots, a_n consisting of n pairwise distinct positive integers.Find \left\lfloor \frac n 2 \right\rfloor different pairs of integers x and y such that: x \neq y; ... | 4
2
1 4
4
2 8 3 4
5
3 8 5 9 7
6
2 7 5 3 4 8
| 4 1 8 2 8 4 9 5 7 5 8 7 4 3 5 2 | 2 seconds | 256 megabytes | ['greedy', 'implementation', 'sortings', '*1000'] |
A. Long Comparisontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMonocarp wrote down two numbers on a whiteboard. Both numbers follow a specific format: a positive integer x with p zeros appended to its end.Now Monocarp asks you to compare these two numbers. Can yo... | 5
2 1
19 0
10 2
100 1
1999 0
2 3
1 0
1 0
99 0
1 2
| > = < = < | 2 seconds | 256 megabytes | ['implementation', 'math', '*900'] |
G. Max Sum Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array c = [c_1, c_2, \dots, c_m]. An array a = [a_1, a_2, \dots, a_n] is constructed in such a way that it consists of integers 1, 2, \dots, m, and for each i \in [1,m], there are exact... | 6
1 1 1 1 1 1
| 0 720 | 2 seconds | 256 megabytes | ['combinatorics', 'constructive algorithms', 'greedy', 'sortings', '*2500'] |
F. Armor and Weaponstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMonocarp plays a computer game. There are n different sets of armor and m different weapons in this game. If a character equips the i-th set of armor and wields the j-th weapon, their power is usual... | 3 4
0
| 3 | 2 seconds | 512 megabytes | ['brute force', 'dp', 'greedy', 'shortest paths', '*2800'] |
E. Messagestime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMonocarp is a tutor of a group of n students. He communicates with them using a conference in a popular messenger.Today was a busy day for Monocarp — he was asked to forward a lot of posts and announcements ... | 3
10 1
10 2
5 2
| 2 5 10 | 3 seconds | 512 megabytes | ['brute force', 'dp', 'greedy', 'probabilities', 'sortings', '*2000'] |
D. X-Magic Pairtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a pair of integers (a, b) and an integer x.You can change the pair in two different ways: set (assign) a := |a - b|; set (assign) b := |a - b|, where |a - b| is the absolute difference ... | 8
6 9 3
15 38 7
18 8 8
30 30 30
40 50 90
24 28 20
365 216 52
537037812705867558 338887693834423551 3199921013340
| YES YES YES YES NO YES YES YES | 2 seconds | 512 megabytes | ['math', 'number theory', '*1600'] |
C. Chat Bantime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are a usual chat user on the most famous streaming platform. Of course, there are some moments when you just want to chill and spam something.More precisely, you want to spam the emote triangle of size k... | 7
4 6
4 7
1 2
3 7
2 5
100 1
1000000000 923456789987654321
| 3 4 1 4 3 1 1608737403 | 2 seconds | 512 megabytes | ['binary search', 'math', '*1300'] |
B. Special Permutationtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA permutation of length n is an array p=[p_1,p_2,\dots, p_n] which contains every integer from 1 to n (inclusive) exactly once. For example, p=[4, 2, 6, 5, 3, 1] is a permutation of length 6.You a... | 7
6 2 5
6 1 3
6 4 3
4 2 4
10 5 3
2 1 2
2 2 1
| 4 2 6 5 3 1 -1 6 4 5 1 3 2 3 2 4 1 -1 1 2 2 1 | 2 seconds | 512 megabytes | ['constructive algorithms', 'greedy', '*900'] |
A. Distancetime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLet's denote the Manhattan distance between two points p_1 (with coordinates (x_1, y_1)) and p_2 (with coordinates (x_2, y_2)) as d(p_1, p_2) = |x_1 - x_2| + |y_1 - y_2|. For example, the distance between tw... | 10
49 3
2 50
13 0
0 41
42 0
0 36
13 37
42 16
42 13
0 0
| 23 3 1 25 -1 -1 -1 -1 21 0 0 18 13 12 25 4 -1 -1 0 0 | 3 seconds | 512 megabytes | ['brute force', 'constructive algorithms', '*800'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.