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. Misha and Applestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSchoolboy Misha got tired of doing sports programming, so he decided to quit everything and go to the magical forest to sell magic apples.His friend Danya came to the magical forest to visit Misha. Wh...
43 42 1 22 4 12 1 24 42 1 22 3 401 12 5005 303 1 2 32 3 101 3
2 1 5 3
1 second
256 megabytes
['brute force', 'data structures', 'dp', 'two pointers', '*2800']
C. The Fox and the Complete Tree Traversaltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe fox Yae climbed the tree of the Sacred Sakura. A tree is a connected undirected graph that does not contain cycles.The fox uses her magical powers to move around the tree. Y...
5 1 2 1 3 3 4 3 5
Yes 4 5 1 2 3
1 second
256 megabytes
['constructive algorithms', 'dp', 'implementation', 'math', 'trees', '*2400']
B. The Butchertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnton plays his favorite game "Defense of The Ancients 2" for his favorite hero — The Butcher. Now he wants to make his own dinner. To do this he will take a rectangle of height h and width w, then make a...
431 23 51 331 11 11 1110 1043 25 52 28 7
1 4 5 2 1 3 3 1 1 10 10 1 13 7
2 seconds
256 megabytes
['geometry', 'greedy', 'implementation', 'sortings', 'two pointers', '*1900']
A. Constructive Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs you know, any problem that does not require the use of complex data structures is considered constructive. You are offered to solve one of such problems.You are given an array a of n non-negati...
431 2 140 2 2 043 2 0 210
Yes Yes No No
1 second
256 megabytes
['brute force', 'greedy', '*1300']
B. Indivisibletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given a positive integer n.Find a permutation a_1, a_2, \dots, a_n such that for any 1 \leq l < r \leq n, the sum a_l + a_{l+1} + \dots + a_r is not divisible by r-l+1.A permutation of length n is a...
3 1 2 3
1 1 2 -1
1 second
256 megabytes
['constructive algorithms', '*900']
A. Politicstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a debate club with n members, including yourself (member 1), there are k opinions to be discussed in sequence. During each discussion, members express their agreement or disagreement with the opinion. Let'...
52 2+++-1 3+-+4 1+--+5 4+++++--+++-++-++++++4 2++-----+
1 1 2 2 1
1 second
256 megabytes
['greedy', 'implementation', '*800']
F. Entangled Substringstime limit per test2 secondsmemory limit per test256 mebibytesinputstandard inputoutputstandard outputQuantum entanglement is when two particles link together in a certain way no matter how far apart they are in space.You are given a string s. A pair of its non-empty substrings (a, b) is called e...
abba
1
2 seconds
256 mebibytes
['string suffix structures', 'strings', '*3500']
E. Half-sumtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given a multiset of non-negative integers \{a_1, a_2, \dots, a_n\}.In one step you take two elements x and y of the multiset, remove them and insert their mean value \frac{x + y}{2} back into the mult...
527 341 2 10 1131 2 3664 32 64 16 64 041 1 1 1
4 9 500000005 59 0
4 seconds
256 megabytes
['brute force', 'divide and conquer', 'greedy', '*3400']
D. Toy Machinetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a toy machine with toys arranged in two rows of n cells each (n is odd). Initial state for n=9. Initially, n-2 toys are placed in the non-corner cells of the top row. The bottom row is initially ...
5 1
RDL
1 second
256 megabytes
['constructive algorithms', 'games', 'implementation', '*2700']
C. Similar Polynomialstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA polynomial A(x) of degree d is an expression of the form A(x) = a_0 + a_1 x + a_2 x^2 + \dots + a_d x^d, where a_i are integers, and a_d \neq 0. Two polynomials A(x) and B(x) are called similar ...
1 1000000006 0 2 3
3
4 seconds
256 megabytes
['combinatorics', 'math', '*2400']
B. Fish Graphtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a simple undirected graph with n nodes and m edges. Note that the graph is not necessarily connected. The nodes are labeled from 1 to n.We define a graph to be a Fish Graph if it contains a si...
37 81 22 33 44 14 54 64 26 77 76 71 22 33 44 11 33 54 41 33 44 11 2
YES 6 5 4 6 4 4 3 1 4 2 1 3 2 YES 5 5 3 2 3 3 1 4 3 1 4 NO
1 second
256 megabytes
['brute force', 'constructive algorithms', 'dfs and similar', 'graphs', '*1900']
A. Almost Increasing Subsequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA sequence is almost-increasing if it does not contain three consecutive elements x, y, z such that x\ge y\ge z.You are given an array a_1, a_2, \dots, a_n and q queries.Each query consi...
9 8 1 2 4 3 3 5 6 2 1 1 3 1 4 2 5 6 6 3 7 7 8 1 8 8 8
3 4 3 1 4 2 7 1
2 seconds
256 megabytes
['binary search', 'data structures', 'greedy', '*1500']
B. Grid Reconstructiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider a 2 \times n grid, where n is an even integer. You may place the integers 1, 2, \ldots, 2n on the grid, using each integer exactly once.A path is a sequence of cells achieved by starting a...
3246
3 2 1 4 8 2 6 4 1 5 3 7 11 5 9 1 7 3 6 10 2 8 4 12
1 second
256 megabytes
['constructive algorithms', 'greedy', '*1000']
A. Ian Visits Marytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIan and Mary are frogs living on lattice points of the Cartesian coordinate plane, with Ian living on (0,0) and Mary living on (a,b). Ian would like to visit Mary by jumping around the Cartesian coordi...
83 44 43 62 21 17 32022 20231000000000 1000000000
1 3 4 2 3 2 4 4 2 5 3 3 6 2 1 0 2 2 1 1 1 1 7 3 1 2022 2023 2 69420420 469696969 1000000000 1000000000
1 second
256 megabytes
['constructive algorithms', 'geometry', 'number theory', '*800']
F. OH NO1 (-2-3-4)time limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an undirected graph with n vertices and 3m edges. The graph may contain multi-edges, but does not contain self-loops. The graph satisfies the following property: the given edges can be d...
44 10 0 0 01 2 35 20 0 0 0 01 2 31 4 54 43 4 5 61 2 31 2 41 3 42 3 45 40 1000000 412 412 4121 2 31 4 52 4 53 4 5
2 1 3 2 3 3 4 3 3 3 1 2 2 2 3 2 3 4 3 1 1 2 3 4 1 2 4 4 4 3 4 1 1
4 seconds
512 megabytes
['constructive algorithms', 'graphs', 'math', '*3500']
E. Bosco and Particletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBosco is studying the behaviour of particles. He decided to investigate on the peculiar behaviour of the so-called "four-one-two" particle. He does the following:There is a line of length n+1, wher...
1 00
4
2 seconds
256 megabytes
['dp', 'math', 'number theory', 'strings', '*3100']
D. XOR Countingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven two positive integers n and m. Find the sum of all possible values of a_1\bigoplus a_2\bigoplus\ldots\bigoplus a_m, where a_1,a_2,\ldots,a_m are non-negative integers such that a_1+a_2+\ldots+a_m=n...
769 15 20 10420 6912 2673 341000000000000000000 10
69 6 0 44310 42 1369 216734648
2 seconds
256 megabytes
['bitmasks', 'combinatorics', 'dp', 'math', '*2600']
C. Betweentime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer n, as well as m pairs of integers (a_i,b_i), where 1\leq a_i , b_i \leq n, a_i \ne b_i.You want to construct a sequence satisfying the following requirements: All elements in the seq...
53 23 12 11 02 02 21 22 15 52 13 14 24 55 1
FINITE 5 2 3 1 2 3 FINITE 1 1 INFINITE FINITE 3 2 1 2 FINITE 10 4 2 3 5 4 1 3 2 5 4
2 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'graphs', 'greedy', '*2200']
B. Sum Graphtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.There is a hidden permutation p_1, p_2, \dots, p_n. Consider an undirected graph with n nodes only with no edges. You can make two types of queries: Specify an integer x sati...
2 6 1 1 1 1 1 2 -1 1 2 1
+ 12 + 2 + 3 ? 1 3 + 5 ? 1 5 ? 4 5 ! 1 4 2 5 3 6 1 2 3 4 5 6 ! 1 2 2 1
3 seconds
256 megabytes
['brute force', 'constructive algorithms', 'graphs', 'implementation', 'interactive', 'shortest paths', 'trees', '*2000']
A. Ian and Array Sortingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTo thank Ian, Mary gifted an array a of length n to Ian. To make himself look smart, he wants to make the array in non-decreasing order by doing the following finitely many times: he chooses two ...
531 3 222 141 3 5 742 1 4 355 4 3 2 1
YES NO YES NO YES
1 second
256 megabytes
['greedy', 'math', '*1300']
F. Communication Towerstime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are n communication towers, numbered from 1 to n, and m bidirectional wires between them. Each tower has a certain set of frequencies that it accepts, the i-th of them accepts frequencies f...
6 5 3 5 1 2 2 4 2 3 3 3 4 6 1 3 6 1 3 5 3 6 2 3
1 3 5 6
4 seconds
512 megabytes
['brute force', 'divide and conquer', 'dsu', '*2700']
E. Chain Chipstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an undirected graph consisting of n vertices and n-1 edges. The i-th edge has weight a_i; it connects the vertices i and i+1.Initially, each vertex contains a chip. Each chip has an integer ...
10 12 6 12 15 20 8 17 12 15 8 4 10 7 3 6 14 9 9 2 10 3 5 4 11 7 11
126 108 120 108 112 98 98 114
3 seconds
512 megabytes
['data structures', 'dp', 'matrices', '*2300']
D. Balancing Weaponstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got a job in a game studio that developed an online shooter, and your first big task is to help to balance weapons. The game has n weapons: the i-th gun has an integer fire rate f_i and an in...
54 26 3 13 71 2 1 23 2100 101 102100 99 985 01 12 4 4 312 1 3 3 42 501000 101000000000 13 51 19 1149 4 72
2 3 0 1 2
3 seconds
256 megabytes
['binary search', 'brute force', 'data structures', 'math', 'two pointers', '*2500']
C. Search in Paralleltime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputSuppose you have n boxes. The i-th box contains infinitely many balls of color i. Sometimes you need to get a ball with some specific color; but you're too lazy to do it yourself.You have bought tw...
37 3 18 6 4 4 4 1 75 1 101 1 1 1 18 1 14 5 6 8 1 7 3 2
2 5 6 5 1 7 2 4 3 5 4 3 5 2 1 0 4 4 2 7 5 4 6 3 1 8
2 seconds
512 megabytes
['constructive algorithms', 'greedy', 'sortings', '*1500']
B. Long Legstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA robot is placed in a cell (0, 0) of an infinite grid. This robot has adjustable length legs. Initially, its legs have length 1.Let the robot currently be in the cell (x, y) and have legs of length m. In o...
31 11 68 4
2 5 6
2 seconds
256 megabytes
['brute force', 'math', '*1700']
A. Coinstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Berland, there are two types of coins, having denominations of 2 and k burles.Your task is to determine whether it is possible to represent n burles in coins, i. e. whether there exist non-negative integers ...
45 36 17 48 8
YES YES NO YES
2 seconds
256 megabytes
['implementation', 'math', '*800']
J. Unmysterious Languagetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is an unmysterious language. You should make a submission in this language, and the judge will read your submission to determine whether it is accepted.You can only submit in the Mysterious...
1 second
256 megabytes
['*special problem', 'constructive algorithms', 'strings']
I. Mountain Climbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInputThe first line of input contains t (1 \leq t \leq 25) — the number of test cases.The only line of each test case contains a single string s (1 \leq |s| \leq 100) consisting only of lowercase Engl...
23bigflashingclumpiunderpasspassundertranquilizingpoleandrejdumplingbocchiryonijikakitasingingsongsalperentoxicpiearibucketpotatoflamestormscarletsmaisakurajimamisakamikotoninfiasylveonpikachumewheniseearulhiiarul
YES NO YES YES YES NO YES NO YES YES YES YES YES YES NO NO NO YES NO NO NO NO NO
1 second
256 megabytes
['*special problem']
H. Expected Twisttime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.There is an array a_1, a_2, \dots, a_n of n integers hidden from you. Your task is to find the smallest element of the array.To do this, you can ask several queries. In e...
3 1295320727 984617979 1295320727 167316954
? 1 3 ? 1 1 ? 2 2 ? 3 3 ! 167316954
3 seconds
256 megabytes
['*special problem', 'interactive']
G. Colour Visiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output ExampleInput 11RROutput YES
11RR
YES
1 second
256 megabytes
['*special problem', 'implementation']
E. Not a Geometry Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInputThe only line of input contains three integers x, y, z (-1000 \le x, y, z \le 1000).OutputOutput one real number — the answer.Your answer is considered correct if its absolute or relative e...
1 1 1
1.7320508075688772
1 second
256 megabytes
['*special problem', '*special problem', 'constructive algorithms', 'geometry', 'math']
D. Trivial Conjecturetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputf(n) = \left\{ \begin{array}{ll} \frac{n}{2} & n \equiv 0 \pmod{2}\\ 3n+1 & n \equiv 1 \pmod{2}\\ \end{array} \right.Find an integer n so that none of the first k terms of the sequence n, f(n), f(f(...
1
5
1 second
256 megabytes
['*special problem', 'constructive algorithms', 'math', 'number theory']
C. Digitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInputThe first line contains a single integer t (1 \le t \le 32) — the number of test cases.Each test case contains n lines. The i-th line contains an integer a_i (1 \le a_i \le 9).The sum of n over all test ca...
3 2 1 4 7 1 2 3 5
8 7 30
1 second
256 megabytes
['*special problem']
B. Was it Rated?time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInputThe only line of the input contains a single integer n (1 \leq n \leq 25).ExamplesInput 1 Output YES Input 15 Output NO
1
YES
1 second
256 megabytes
['*special problem', '*special problem', '*special problem', 'brute force', 'implementation']
G2. Vlad and the Nice Paths (hard version)time limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThis is hard version of the problem, it differs from the easy one only by constraints on n and k.Vlad found a row of n tiles and the integer k. The tiles are indexed from left ...
55 21 2 3 4 57 21 3 1 3 3 1 311 41 1 1 1 1 1 1 1 1 1 15 21 1 2 2 25 11 2 3 4 5
1 4 165 3 1
3 seconds
512 megabytes
['binary search', 'combinatorics', 'data structures', 'dp', 'math', 'two pointers', '*2200']
G1. Vlad and the Nice Paths (easy version)time limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an easy version of the problem, it differs from the hard one only by constraints on n and k.Vlad found a row of n tiles and the integer k. The tiles are indexed from le...
55 21 2 3 4 57 21 3 1 3 3 1 311 41 1 1 1 1 1 1 1 1 1 15 21 1 2 2 25 11 2 3 4 5
1 4 165 3 1
5 seconds
256 megabytes
['combinatorics', 'dp', 'math', '*2100']
F. Is It Flower?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVlad found a flowerbed with graphs in his yard and decided to take one for himself. Later he found out that in addition to the usual graphs, k-flowers also grew on that flowerbed. A graph is called a k-...
59 121 23 12 31 64 16 43 83 55 89 72 97 28 121 23 12 31 64 16 43 83 55 88 72 87 24 31 24 23 16 86 36 45 35 23 23 12 12 45 72 42 53 43 54 14 51 5
YES NO NO NO NO
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'implementation', '*2100']
E. Living Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Japan, the number 4 reads like death, so Bob decided to build a live sequence. Living sequence a contains all natural numbers that do not contain the digit 4. a = [1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12...
735221010012345827264634912
3 6 25 11 121 18937 2932285320890
1 second
256 megabytes
['binary search', 'dp', 'math', 'number theory', '*1500']
D. Umka and a Long Flighttime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe girl Umka loves to travel and participate in math olympiads. One day she was flying by plane to the next olympiad and out of boredom explored a huge checkered sheet of paper.Denote the n-th...
121 1 12 1 23 1 43 3 24 4 64 3 35 6 55 4 125 2 124 2 11 1 244 758465880 1277583853
YES NO YES YES YES NO YES NO NO YES YES NO
3 seconds
256 megabytes
['constructive algorithms', 'implementation', 'math', '*1600']
C. Restore the Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKristina had an array a of length n consisting of non-negative integers.She built a new array b of length n-1, such that b_i = \max(a_i, a_{i+1}) (1 \le i \le n-1).For example, suppose Kristina had a...
1153 4 4 542 2 150 0 0 060 3 4 4 321043 3 354 2 5 543 3 342 1 034 468 1 3 5 10
3 0 4 0 5 2 2 1 1 0 0 0 0 0 0 0 3 4 3 3 10 10 3 3 3 1 4 2 2 5 5 3 3 3 3 2 1 0 0 2 4 4 8 1 1 3 5 10
1 second
256 megabytes
['constructive algorithms', 'greedy', '*1100']
B. Conveyor Beltstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConveyor matrix m_n is matrix of size n \times n, where n is an even number. The matrix consists of concentric ribbons moving clockwise.In other words, the conveyor matrix for n = 2 is simply a matrix ...
52 1 1 2 24 1 4 3 38 1 3 4 6100 10 20 50 1001000000000 123456789 987654321 998244353 500000004
0 1 2 9 10590032
3 seconds
256 megabytes
['implementation', 'math', '*1000']
A. Insert Digittime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a positive number of length n and one additional digit.You can insert this digit anywhere in the number, including at the beginning or at the end.Your task is to make the result as large as poss...
115 4765431 012 5443 66665 6135795 89753119 498765432101234567895 7737378 1200000007 0705895912 1828127127732
765443 10 544 6666 613579 987531 98765443210123456789 773737 210000000 70589590 8281271277321
2 seconds
256 megabytes
['greedy', 'math', 'strings', '*800']
H. Last Numbertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a multiset S. Initially, S = \{1,2,3, \ldots, n\}.You will perform the following operation n-1 times. Choose the largest number S_{\text{max}} in S and the smallest number S_{\text{min}} in...
524715177567
1 2 2 4 33914
2 seconds
256 megabytes
['combinatorics', 'math', '*2900']
G. The Maximum Prefixtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're going to generate an array a with a length of at most n, where each a_{i} equals either 1 or -1.You generate this array in the following way. First, you choose some integer k (1\le k \le n)...
421 21 21 2 331 31 45 51 1 1 132 54 60 24 3 2 155 65 71 61 34 79 0 4 5 2 4
500000005 750000007 1 1 1 200000005 333333339 333333339 500000005 880952391 801587311 781746041 789304620
1 second
256 megabytes
['dp', '*3200']
F. M-treetime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA rooted tree is called good if every vertex of the tree either is a leaf (a vertex with no children) or has exactly m children.For a good tree, each leaf u has a positive integer c_{u} written on it, and we...
35 3 33 3 4 4 51 42 43 55 2 43 3 4 4 51 42 53 54 57 3 41 2 2 3 3 3 41 42 15 56 6
6 6 6 7 7 7 8 6 6 6 7
2.5 seconds
256 megabytes
['data structures', 'math', 'sortings', 'trees', '*2800']
E. Monsterstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is an undirected graph with n vertices and m edges. Initially, for each vertex i, there is a monster with danger a_{i} on that vertex. For a monster with danger a_{i}, you can defeat it if and only if ...
54 32 1 0 31 22 33 46 60 1 2 3 0 11 22 33 44 54 65 64 30 1 2 01 22 31 34 61 1 1 01 23 24 32 44 11 35 50 1 3 2 01 22 33 44 53 5
YES YES NO YES NO
2 seconds
256 megabytes
['brute force', 'data structures', 'dfs and similar', 'dsu', 'graphs', 'greedy', '*2100']
D. Climbing the Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe snails are climbing a tree. The tree height is h meters, and snails start at position 0.Each snail has two attributes a and b (a > b). Starting from the 1-st day, one snail climbs the tree like ...
531 3 2 52 4 12 3 231 6 5 12 3 12 6 231 4 2 21 2 1 32 10 291 7 3 61 2 1 82 5 11 10 9 71 8 1 21 10 5 81 10 7 72 7 41 9 4 291 2 1 61 8 5 61 4 2 72 9 11 5 1 41 5 2 71 7 1 91 9 1 42 10 8
1 2 5 1 -1 1 1 0 1 1 0 -1 0 0 0 1 8 0 1 0 0 1 0 0 0 0 1
2 seconds
256 megabytes
['binary search', 'math', '*1700']
C. Make It Permutationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have an integer array a of length n. There are two kinds of operations you can make. Remove an integer from a. This operation costs c. Insert an arbitrary positive integer x to any position of...
83 3 31 2 35 1 51 2 3 5 65 2 31 1 1 3 35 1 102 4 6 8 106 2 87 3 5 4 4 84 10 11 2 6 74 3 32 5 8 72 1000000000 11000000000 1
0 2 8 14 20 3 12 999999998
1 second
256 megabytes
['brute force', 'greedy', 'sortings', '*1300']
B. Candiestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is about candy. Initially, you only have 1 candy, and you want to have exactly n candies.You can use the two following spells in any order at most 40 times in total. Assume you have x candies now...
423717
-1 1 2 2 2 2 4 2 1 1 1
1 second
256 megabytes
['constructive algorithms', 'math', 'number theory', '*800']
A. Beautiful Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA sequence of m integers a_{1}, a_{2}, \ldots, a_{m} is good, if and only if there exists at least one i (1 \le i \le m) such that a_{i} = i. For example, [3,2,3] is a good sequence, since a_{2} = 2...
733 2 142 4 3 552 3 5 5 623 152 4 5 2 345 6 7 866 5 4 3 2 1
YES YES NO YES YES NO YES
1 second
256 megabytes
['brute force', 'greedy', '*800']
G. Predictiontime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputConsider a tournament with n participants. The rating of the i-th participant is a_i.The tournament will be organized as follows. First of all, organizers will assign each participant an index from 1 to n....
4 3 7 12 17 21
24
4 seconds
512 megabytes
['combinatorics', 'dp', 'math', '*2800']
F. Traveling in Berlandtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities in Berland, arranged in a circle and numbered from 1 to n in clockwise order.You want to travel all over Berland, starting in some city, visiting all the other cities and retur...
43 53 4 41 2 25 71 3 2 5 12 1 1 1 24 31 2 1 32 2 2 23 22 2 21 2 1
17 19 17 13 12 12 12 14 14 14 14 14 8 8 8
2 seconds
256 megabytes
['binary search', 'data structures', 'graphs', 'greedy', 'implementation', '*2500']
E. Two Tankstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are two water tanks, the first one fits a liters of water, the second one fits b liters of water. The first tank has c (0 \le c \le a) liters of water initially, the second tank has d (0 \le d \le b) ...
3 4 4 -2 1 2
0 0 0 0 0 0 0 0 0 1 0 0 1 1 2 0 1 1 2 3 1 1 2 3 4
2 seconds
256 megabytes
['binary search', 'dp', 'implementation', 'math', '*2400']
D. Binary String Sortingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a binary string s consisting of only characters 0 and/or 1.You can perform several operations on this string (possibly zero). There are two types of operations: choose two consec...
61000010100101101100110111111
1000000000001 0 1000000000000 2000000000001 2000000000002 0
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*1800']
C. Sum on Subarraystime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputFor an array a = [a_1, a_2, \dots, a_n], let's denote its subarray a[l, r] as the array [a_l, a_{l+1}, \dots, a_r].For example, the array a = [1, -3, 1] has 6 non-empty subarrays: a[1,1] = [1]; a[1...
43 22 02 24 6
1 -3 1 -13 -42 -13 42 -3 -4 10 -2
2 seconds
512 megabytes
['constructive algorithms', 'greedy', 'math', '*1500']
B. Points on Planetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a two-dimensional plane, and you need to place n chips on it. You can place a chip only at a point with integer coordinates. The cost of placing a chip at the point (x, y) is equal to |x...
4135975461057789971042
0 1 2 987654321
2 seconds
256 megabytes
['binary search', 'greedy', 'math', '*1000']
A. Garlandtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a garland consisting of 4 colored light bulbs, the color of the i-th light bulb is s_i.Initially, all the light bulbs are turned off. Your task is to turn all the light bulbs on. You can perform the ...
3954600003313
4 -1 6
2 seconds
256 megabytes
['implementation', '*800']
E3. Minibuses on Venus (hard version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the hard version of the problem. The only difference between the three versions is the constraints on n and k. You can make hacks only if all versions of the problem are sol...
3 2 1000000007
4
3 seconds
256 megabytes
['brute force', 'combinatorics', 'dp', 'math', '*2800']
E2. Minibuses on Venus (medium version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the medium version of the problem. The only difference between the three versions is the constraints on n and k. You can make hacks only if all versions of the problem are...
3 2 1000000007
4
3 seconds
256 megabytes
['combinatorics', 'divide and conquer', 'dp', 'matrices', '*2500']
E1. Minibuses on Venus (easy version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the easy version of the problem. The only difference between the three versions is the constraints on n and k. You can make hacks only if all versions of the problem are sol...
3 2 1000000007
4
3 seconds
256 megabytes
['combinatorics', 'divide and conquer', 'dp', '*2200']
D. Petya, Petya, Petr, and Palindromestime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya and his friend, the robot Petya++, have a common friend — the cyborg Petr#. Sometimes Petr# comes to the friends for a cup of tea and tells them interesting problems.Today,...
8 5 1 2 8 2 5 2 8 6
4
1.5 seconds
256 megabytes
['binary search', 'brute force', 'data structures', 'two pointers', '*2100']
C. Unlucky Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this problem, unlike problem A, you need to look for unluckiest number, not the luckiest one.Note that the constraints of this problem differ from such in problem A.Olympus City recently launched t...
559 6342 4948 5390 901 100
63 44 53 90 1
2 seconds
256 megabytes
['brute force', 'dp', 'greedy', 'implementation', '*1900']
B. Playing in a Casinotime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output Galaxy Luck, a well-known casino in the entire solar system, introduces a new card game.In this game, there is a deck that consists of n cards. Each card has m numbers written on it. Each of the...
33 51 4 2 8 57 9 2 1 43 8 5 3 11 44 15 1 104 31 2 33 2 11 2 14 2 7
50 0 31
2 seconds
256 megabytes
['math', 'sortings', '*1200']
A. Lucky Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOlympus City recently launched the production of personal starships. Now everyone on Mars can buy one and fly to other planets inexpensively.Each starship has a number —some positive integer x. Let's def...
559 6342 4915 1553 571 100
60 49 15 57 90
1 second
256 megabytes
['brute force', 'implementation', '*900']
G2. Subsequence Addition (Hard Version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between the two versions is that in this version, the constraints are higher.Initially, array a contains just the number 1. You can perform several operations ...
6111255 1 3 2 157 1 5 2 131 1 151 1 4 2 1
YES NO YES NO YES YES
2 seconds
256 megabytes
['bitmasks', 'dp', 'greedy', 'implementation', 'sortings', '*1100']
G1. Subsequence Addition (Easy Version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between the two versions is that in this version, the constraints are lower.Initially, array a contains just the number 1. You can perform several operations i...
6111255 1 3 2 157 1 5 2 131 1 151 1 4 2 1
YES NO YES NO YES YES
2 seconds
256 megabytes
['brute force', 'data structures', 'dp', 'greedy', 'implementation', 'sortings', '*1100']
F. Bouncy Balltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a room that can be represented by a n \times m grid. There is a ball at position (i_1, j_1) (the intersection of row i_1 and column j_1), and it starts going diagonally in one of the four dir...
65 7 1 7 2 4 DL5 7 1 7 3 2 DL3 3 1 3 2 2 UR2 4 2 1 2 2 DR4 3 1 1 1 3 UL6 4 1 2 3 4 DR
3 -1 1 -1 4 0
1 second
256 megabytes
['brute force', 'dfs and similar', 'implementation', '*1700']
E. Interviewtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem. If you are unsure how interactive problems work, then it is recommended to read the guide for participants.Before the last stage of the exam, the director conducted an interv...
2 5 1 2 3 4 5 11 6 3 7 1 2 3 5 3 4 2 12 6
? 4 1 2 3 4 ? 2 2 3 ? 1 2 ! 2 ? 4 2 3 5 6 ? 2 1 4 ! 7
2 seconds
256 megabytes
['binary search', 'implementation', 'interactive', '*1300']
D. Odd Queriestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have an array a_1, a_2, \dots, a_n. Answer q queries of the following form: If we change all elements in the range a_l, a_{l+1}, \dots, a_r of the array to k, will the sum of the entire array be odd...
25 52 2 1 3 22 3 32 3 41 5 51 4 92 4 310 51 1 1 1 1 1 1 1 1 13 8 132 5 103 8 101 10 21 9 100
YES YES YES NO YES NO NO NO NO YES
2 seconds
256 megabytes
['data structures', 'implementation', '*900']
C. Find and Replacetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s consisting of lowercase Latin characters. In an operation, you can take a character and replace all occurrences of this character with \texttt{0} or replace all occurrences of...
87abacaba2aa1y4bkpt6ninfia6banana10codeforces8testcase
YES NO YES YES NO YES NO NO
1 second
256 megabytes
['greedy', 'implementation', 'strings', '*800']
B. Grab the Candiestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMihai and Bianca are playing with bags of candies. They have a row a of n bags of candies. The i-th bag has a_i candies. The bags are given to the players in the order from the first bag to the n-th b...
341 2 3 441 1 1 231 4 3
YES NO NO
1 second
256 megabytes
['greedy', '*800']
A. Plus or Minustime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given three integers a, b, and c such that exactly one of these two equations is true: a+b=c a-b=c Output + if the first equation is true, and - otherwise.InputThe first line contains a singl...
111 2 33 2 12 9 -73 4 71 1 21 1 03 3 69 9 189 9 01 9 -81 9 10
+ - - + + - + + - - +
1 second
256 megabytes
['implementation', '*800']
F2. GCD Master (hard version)time limit per test3 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputThis is the hard version of the problem. The only difference between the two versions is the constraint on m. You can make hacks only if both versions of the problem are solved.You are giv...
43 8 14 7 85 114514 27 2 4 1 63 1919810 22 3 33 9000000000000000000 19000000000000000000 9000000000000000000 9000000000000000000
11 14 1 18000000000000000000
3 seconds
1024 megabytes
['greedy', 'math', 'sortings', '*2900']
F1. GCD Master (easy version)time limit per test3 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputThis is the easy version of the problem. The only difference between the two versions is the constraint on m. You can make hacks only if both versions of the problem are solved.You are giv...
33 8 14 7 85 114 27 2 4 1 63 514 22 3 3
11 14 1
3 seconds
1024 megabytes
['greedy', 'math', 'number theory', 'sortings', '*2900']
E. Tree Mastertime limit per test3 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYou are given a tree with n weighted vertices labeled from 1 to n rooted at vertex 1. The parent of vertex i is p_i and the weight of vertex i is a_i. For convenience, define p_1=0.For two vertices x and...
6 2 1 5 2 3 1 1 1 2 3 3 2 4 5 6 6
33 27
3 seconds
1024 megabytes
['brute force', 'data structures', 'dfs and similar', 'trees', '*2200']
D. DSU Mastertime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYou are given an integer n and an array a of length n-1 whose elements are either 0 or 1.Let us define the value of a permutation^\dagger p of length m-1 (m \leq n) by the following process.Let G be a gra...
230 090 1 0 0 0 1 0 0
1 3 1 2 7 31 167 1002 7314 60612
2 seconds
1024 megabytes
['combinatorics', 'dp', 'dsu', 'math', '*2500']
C. Sequence Mastertime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard outputFor some positive integer m, YunQian considers an array q of 2m (possibly negative) integers good, if and only if for every possible subsequence of q that has length m, the product of the m elements i...
416 921 2 2 12-2 -2 2 24-3 -2 -1 0 1 2 3 4
3 2 5 13
1 second
1024 megabytes
['brute force', 'constructive algorithms', 'math', '*1600']
B. Mex Mastertime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYou are given an array a of length n. The score of a is the MEX^{\dagger} of [a_1+a_2,a_2+a_3,\ldots,a_{n-1}+a_n]. Find the minimum score of a if you are allowed to rearrange elements of a in any order. No...
320 030 0 181 0 0 0 2 0 3 0
1 0 1
1 second
1024 megabytes
['constructive algorithms', 'greedy', '*900']
A. Walking Mastertime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYunQian is standing on an infinite plane with the Cartesian coordinate system on it. In one move, she can move to the diagonally adjacent point on the top right or the adjacent point on the left.That i...
6-1 0 -1 20 0 4 5-2 -1 1 1-3 2 -3 22 -1 -1 -11 1 0 2
4 6 -1 0 3 3
1 second
1024 megabytes
['geometry', 'greedy', 'math', '*800']
F2. Survival of the Weakest (hard version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the hard version of the problem. It differs from the easy one only in constraints on n. You can make hacks only if you lock both versions.Let a_1, a_2, \ldots, a_n be a...
5 1 2 4 5 6
34
3 seconds
256 megabytes
['greedy', 'math', 'sortings', 'two pointers', '*3100']
F1. Survival of the Weakest (easy version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the easy version of the problem. It differs from the hard one only in constraints on n. You can make hacks only if you lock both versions.Let a_1, a_2, \ldots, a_n be a...
5 1 2 4 5 6
34
3 seconds
256 megabytes
['binary search', 'brute force', 'implementation', 'math', 'sortings', '*2600']
E. There Should Be a Lot of Maximumstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree (a connected graph without cycles). Each vertex of the tree contains an integer. Let's define the \mathrm{MAD} (maximum double) parameter of the tree as the maxim...
5 1 2 2 3 2 4 1 5 2 1 3 2 1
0 2 1 2
1 second
256 megabytes
['brute force', 'data structures', 'dfs and similar', 'dp', 'trees', 'two pointers', '*2300']
D. A Wide, Wide Graphtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree (a connected graph without cycles) with n vertices. Consider a fixed integer k. Then, the graph G_k is an undirected graph with n vertices, where an edge between vertices u and ...
6 1 2 1 3 2 4 2 5 3 6
1 1 2 4 6 6
1 second
256 megabytes
['dfs and similar', 'dp', 'graphs', 'greedy', 'trees', '*1800']
C. Place for a Selfietime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe universe is a coordinate plane. There are n space highways, each of which is a straight line y=kx passing through the origin (0, 0). Also, there are m asteroid belts on the plane, which we repr...
51 211 -1 21 -1 32 2141 2 12 5 11 101 0 01 1100000000100000000 100000000 1000000002 3022 2 11 -2 11 -2 -1
YES 1 YES 1 YES 1 YES 4 NO YES 100000000 YES 0 NO NO
2 seconds
256 megabytes
['binary search', 'data structures', 'geometry', 'math', '*1400']
B. The String Has a Targettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s. You can apply this operation to the string exactly once: choose index i and move character s_i to the beginning of the string (removing it at the old position). For ex...
43cba4acac5abbcb4aaba
acb aacc abbcb aaab
1 second
256 megabytes
['greedy', 'strings', '*800']
A. We Need the Zerotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is an array a consisting of non-negative integers. You can choose an integer x and denote b_i=a_i \oplus x for all 1 \le i \le n, where \oplus denotes the bitwise XOR operation. Is it possible t...
531 2 531 2 340 1 2 341 2 2 311
6 0 3 -1 1
1 second
256 megabytes
['bitmasks', 'brute force', '*800']
H. Code Locktime limit per test7 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLara has a safe that is locked with a circle-shaped code lock that consists of a rotating arrow, a static circumference around the arrow, an input screen, and an input button.The circumference of the lock i...
3 10 abcabcabca
19 2
7 seconds
512 megabytes
['bitmasks', 'dp', '*3300']
G. Flow Controltime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputRaj has a single physical network line that connects his office to the Internet. This line bandwidth is b bytes per millisecond.There are n users who would like to use this network line to transmit some ...
1 3 1 5 2
10
6 seconds
512 megabytes
['data structures', 'dsu', 'implementation', '*3500']
F. Approximate Diametertime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputJack has a graph of n vertices and m edges. All edges are bidirectional and of unit length. The graph is connected, i. e. there exists a path between any two of its vertices. There can be more th...
9 10 8 1 2 2 3 2 4 3 5 4 5 5 6 5 7 6 8 7 8 8 9 3 4 6 7 2 8 1 9 1 6 4 9 3 9 7 1
10 6 5 6 2 4 2 2 1
2 seconds
512 megabytes
['binary search', 'divide and conquer', 'graphs', 'shortest paths', '*2700']
E. Routingtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAda operates a network that consists of n servers and m direct connections between them. Each direct connection between a pair of distinct servers allows bidirectional transmission of information between thes...
6 7 1 2 2 3 3 1 4 5 5 6 4 6 2 5
Yes 2 5 2 5 2 5
2 seconds
512 megabytes
['bitmasks', 'brute force', 'dfs and similar', 'dp', 'graphs', '*2400']
D. Accommodationtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAnnie is an amateur photographer. She likes to take pictures of giant residential buildings at night. She just took a picture of a huge rectangular building that can be seen as a table of n \times m win...
5 4 0100 1100 0110 1010 1011
7 10
2 seconds
512 megabytes
['brute force', 'dp', 'greedy', 'implementation', '*2000']
C. Pull Your Lucktime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputWhile James is gone on business, Vesper takes her time and explores what the legendary Casino Royale has to offer to people who are fond of competitive programming.Her attention was grabbed by the very ...
75 2 15 2 210 0 10011 7 1003 1 100031 0 10100 49 7
No Yes Yes Yes No No No
1 second
512 megabytes
['brute force', 'greedy', 'math', 'number theory', '*1500']
B. Vaccinationtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputEthan runs a vaccination station to help people combat the seasonal flu. He analyses the historical data in order to develop an optimal strategy for vaccine usage.Consider there are n patients coming to t...
56 3 5 31 2 3 10 11 186 4 0 03 3 3 3 3 49 10 2 20 1 2 3 4 5 6 7 83 10 3 610 20 305 5 4 40 2 4 6 8
2 3 2 3 1
2 seconds
512 megabytes
['greedy', 'implementation', '*1000']
A. Lame Kingtime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a checkerboard of size 201 \times 201, i. e. it has 201 rows and 201 columns. The rows of this checkerboard are numbered from -100 to 100 from bottom to top. The columns of this checkerboard ar...
5-4 14 40 -6-5 -47 -8
7 8 11 9 15
1 second
512 megabytes
['greedy', 'math', '*800']
B. Settlement of Guinea Pigstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDasha loves guinea pigs very much. In this regard, she decided to settle as many guinea pigs at home as possible and developed a plan for the next n days. Every day, she will either buy a new...
631 1 132 2 251 1 1 2 1101 2 1 2 1 2 1 2 1 2201 2 1 1 1 1 1 2 1 2 1 2 2 1 1 1 1 1 1 1202 1 1 2 1 1 2 1 2 2 1 1 1 2 2 1 1 1 1 2
3 0 3 4 12 9
1 second
256 megabytes
['greedy', 'implementation', 'math', '*1000']
A. Likestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNikita recently held a very controversial round, after which his contribution changed very quickly.The announcement hung on the main page for n seconds. In the ith second |a_i|th person either liked or removed t...
531 2 -221 -164 3 -1 2 1 -254 2 -2 1 37-1 6 -4 3 2 4 1
1 2 1 1 0 1 1 0 1 0 1 2 3 4 3 2 1 0 1 0 1 2 1 2 3 4 3 1 0 1 2 3 1 2 3 4 5 4 3 1 0 1 0 1 2 3
1 second
256 megabytes
['greedy', 'implementation', '*800']
G. A task for substringstime limit per test4 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard output Philip is very fond of tasks on the lines. He had already solved all the problems known to him, but this was not enough for him. Therefore, Philip decided to come up with his own task.To do th...
3 5 abacaba aba a ac 1 7 1 3 2 7 2 5 4 5
7 3 5 3 1
4 seconds
1024 megabytes
['data structures', 'string suffix structures', 'strings', '*3400']
F. Another n-dimensional chocolate bartime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output Mom bought the boy Vasya a n-dimensional chocolate bar, which is a n-dimensional cube with the length of each side equal to 1. The chocolate is planned to be divided into slices. ...
1 2 5
0.8
2 seconds
512 megabytes
['dp', 'math', 'meet-in-the-middle', 'number theory', '*2700']
E. Gasoline pricestime limit per test3.5 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard output Berland — is a huge country consisting of n cities. The road network of Berland can be represented as a root tree, that is, there is only n - 1 road in the country, and you can get from any city t...
5 1 1 2 2 2 4 1 3 1 3 2 4 4 4 4 1 1 2 2 1 2 2 1 3 4 4 3 3 4 3 5
18 18 4 0
3.5 seconds
1024 megabytes
['data structures', 'divide and conquer', 'dsu', 'hashing', 'trees', '*3000']
D. The way hometime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output The famous magician Borya Budini traveled through the country X, which consists of n cities. However, an accident happened, and he was robbed in the city number 1. Now Budini will have a hard way home t...
44 4 27 4 3 11 2 213 2 61 3 82 4 114 4 101 2 10 11 2 202 4 301 3 253 4 894 4 75 1 6 21 2 52 3 103 4 503 4 704 1 21 1 1 11 3 2
4 24 10 -1
3 seconds
512 megabytes
['binary search', 'data structures', 'dp', 'graphs', 'greedy', 'shortest paths', 'sortings', '*2100']