[Solution] Kirill and Company solution codeforces

Kirill and Company solution codeforces Kirill and Company solution codeforces – Kirill lives on a connected undirected graph of 𝑛n vertices and 𝑚m edges at vertex 11. One fine evening he gathered 𝑓f friends, the 𝑖i-th friend lives at the vertex ℎ𝑖hi. So all friends are now in the vertex 11, the 𝑖i-th friend must get to his home to the vertex ℎ𝑖hi. The evening is … Read more

[Solution] Multi-Colored Segments solution codeforces

Multi-Colored Segments solution codeforces Multi-Colored Segments solution codeforces – Dmitry has 𝑛n segments of different colors on the coordinate axis 𝑂𝑥Ox. Each segment is characterized by three integers 𝑙𝑖li, 𝑟𝑖ri and 𝑐𝑖ci (1≤𝑙𝑖≤𝑟𝑖≤109,1≤𝑐𝑖≤𝑛1≤li≤ri≤109,1≤ci≤n), where 𝑙𝑖li and 𝑟𝑖ri are are the coordinates of the ends of the 𝑖i-th segment, and 𝑐𝑖ci is its color. Dmitry likes to find the minimum distances between segments. However, he considers pairs of segments of … Read more

[Solution] Sending a Sequence Over the Network solution codeforces

Sending a Sequence Over the Network solution codeforces Sending a Sequence Over the Network solution codeforces – The sequence 𝑎a is sent over the network as follows: sequence 𝑎a is split into segments (each element of the sequence belongs to exactly one segment, each segment is a group of consecutive elements of sequence); for each segment, its length … Read more

[Solution] Masha and a Beautiful Tree solution codeforces

Masha and a Beautiful Tree solution codeforces Masha and a Beautiful Tree solution codeforces – The girl named Masha was walking in the forest and found a complete binary tree of height 𝑛n and a permutation 𝑝p of length 𝑚=2𝑛m=2n. A complete binary tree of height 𝑛n is a rooted tree such that every vertex except the leaves has exactly two … Read more

[Solution] Minimize the Thickness solution codeforces

Minimize the Thickness solution codeforces Minimize the Thickness solution codeforces – You are given a sequence 𝑎=[𝑎1,𝑎2,…,𝑎𝑛]a=[a1,a2,…,an] consisting of 𝑛n positive integers. Let’s call a group of consecutive elements a segment. Each segment is characterized by two indices: the index of its left end and the index of its right end. Denote by 𝑎[𝑙,𝑟]a[l,r] a segment of the sequence 𝑎a with the left end in 𝑙l and the right end … Read more

[Solution] Funny Permutation solution codeforces

Funny Permutation solution codeforces Funny Permutation solution codeforces – A sequence of 𝑛n numbers is called permutation if it contains all numbers from 11 to 𝑛n exactly once. For example, the sequences [3,1,4,2][3,1,4,2], [11] and [2,1][2,1] are permutations, but [1,2,1][1,2,1], [0,1][0,1] and [1,3,4][1,3,4] are not. For a given number 𝑛n you need to make a permutation 𝑝p such that two requirements are satisfied at the same time: For each element 𝑝𝑖pi, at least one of … Read more

[Solution] Compare T-Shirt Sizes solution codeforces

Compare T-Shirt Sizes solution codeforces Compare T-Shirt Sizes solution codeforces – Two T-shirt sizes are given: 𝑎a and 𝑏b. The T-shirt size is either a string M or a string consisting of several (possibly zero) characters X and one of the characters S or L. For example, strings M, XXL, S, XXXXXXXS could be the size of some T-shirts. And the strings XM, LL, SX are not sizes. The letter M stands for medium, S for small, L for … Read more

[Solution] Swap and Take solution codeforces

Swap and Take solution codeforces – You’re given an array consisting of 𝑛n integers. You have to perform 𝑛n turns. [Solution] Swap and Take solution codeforces Initially your score is 00. On the 𝑖i-th turn, you are allowed to leave the array as it is or swap any one pair of 22 adjacent elements in the array and change exactly one of … Read more

[Solution] Equal Binary Subsequences solution codeforces

Equal Binary Subsequences solution codeforces – Everool has a binary string 𝑠s of length 2𝑛2n. Note that a binary string is a string consisting of only characters 00 and 11. He wants to partition 𝑠s into two disjoint equal subsequences. He needs your help to do it. [Solution] Equal Binary Subsequences solution codeforces You are allowed to do the following operation exactly once. You can choose … Read more

[Solution] Good Subarrays (Hard Version) solution codeforces

Good Subarrays (Hard Version) solution codeforces – An array 𝑏b of length 𝑚m is good if for all 𝑖i the 𝑖i-th element is greater than or equal to 𝑖i. In other words, 𝑏b is good if and only if 𝑏𝑖≥𝑖bi≥i for all 𝑖i (1≤𝑖≤𝑚1≤i≤m). [Solution] Good Subarrays (Hard Version) solution codeforces You are given an array 𝑎a consisting of 𝑛n positive integers, and you are asked 𝑞q queries. In each query, you are given two integers 𝑝p and 𝑥x (1≤𝑝,𝑥≤𝑛1≤p,x≤n). You have … Read more