brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1101B - Accordion

We are given a string containing letters and a few special characters: [, ], :, and The constraints tell us that the string can be up to 500,000 characters long.

codeforcescompetitive-programminggreedyimplementation
CF 1102F - Elongated Matrix

We have a rectangular grid of numbers with $n$ rows and $m$ columns. We are allowed to reorder the rows however we like, but the order of numbers within each row is fixed.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcedpgraphs
CF 1102A - Integer Sequence Dividing

We are given the sequence of integers from 1 to $n$. The task is to divide this sequence into two disjoint sets $A$ and $B$ so that the absolute difference between their sums, $ Since $n$ can be as large as $2 cdot 10^9$, explicitly constructing the sequence or trying all…

codeforcescompetitive-programmingmath
CF 1105C - Ayoub and Lost Array

We are asked to count how many arrays of length $n$ can be formed such that every element lies within a fixed interval $[l, r]$, and the total sum of all elements is divisible by 3.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1106C - Lunar New Year and Number Division

We are given an even-length list of positive integers, and we must partition these numbers into groups. Each group must contain at least two elements, and every number must belong to exactly one group.

codeforcescompetitive-programminggreedyimplementationmathsortings
CF 1107C - Brutality

We are given a fixed sequence of hits, where each hit has a damage value and is associated with a specific button (a lowercase letter). We are allowed to delete any hits from the sequence while keeping the remaining ones in their original order.

codeforcescompetitive-programminggreedysortingstwo-pointers
CF 1107F - Vasya and Endless Credits

Vasya starts with zero burles and wants to buy a car. The bank offers n credit deals, each giving him an initial sum ai immediately and requiring monthly payments of bi for ki months. Vasya can take at most one credit per month, but multiple credits can overlap.

codeforcescompetitive-programmingdpflowsgraph-matchingsgraphssortings
CF 1107G - Vasya and Maximum Profit

Vasya wants to assemble a contest from a sequence of problems, each with a difficulty and a cost. He gains a fixed reward for including any problem, but he also pays two types of costs: the direct payment to each problem’s author and a “gap penalty” based on the largest…

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresdpdsu
CF 1107E - Vasya and Binary String

We are given a binary string that we are allowed to repeatedly compress until nothing remains. A single move consists of picking a contiguous block of identical characters, either all 0s or all 1s, removing that block from the string, and concatenating the remaining parts.

codeforcescompetitive-programmingdp
CF 1107D - Compression

We are given a square matrix of size $n times n$, but instead of being explicitly written as bits, each row is packed into hexadecimal characters. Each hex digit represents four binary cells, so the input is just a compact encoding of a binary matrix.

codeforcescompetitive-programmingdpimplementationmathnumber-theory
CF 1107A - Digits Sequence Dividing

We are given a string of digits, each between 1 and 9. The task is to split this string into at least two consecutive segments so that when we interpret each segment as an integer, the resulting sequence is strictly increasing.

codeforcescompetitive-programminggreedystrings
CF 1107B - Digital root

We are asked to answer multiple independent queries. Each query gives two numbers, a position $k$ and a digit $x$ between 1 and 9. For each query, we need to output the $k$-th positive integer whose digital root equals $x$.

codeforcescompetitive-programmingmathnumber-theory
CF 1108C - Nice Garland

We are given a line of lamps, each painted in one of three colors: R, G, or B. We are allowed to repaint any lamp to any other color.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1108F - MST Unification

We are given a connected undirected graph with n vertices and m edges, each with a positive weight. The goal is to adjust some edge weights by incrementing them, so that the graph's minimum spanning tree (MST) remains the same cost as initially but becomes unique.

codeforcescompetitive-programmingbinary-searchdsugraphsgreedy
CF 1108E2 - Array and Segments (Hard version)

We are given an array of integers and a collection of segments, each defined by a start and end index. Each segment can be applied at most once to decrease all values in that segment by one.

codeforcescompetitive-programmingdata-structuresimplementation
CF 1108E1 - Array and Segments (Easy version)

We are given an integer array and a collection of intervals over its indices. Each interval represents an operation: if we select it, every position inside that range is decreased by exactly one.

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 1108D - Diverse Garland

We are given a linear sequence of lamps, each painted either red, green, or blue. The task is to change as few of them as possible so that no two consecutive lamps have the same color.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedy
CF 1108A - Two distinct points

We are given two line segments on the number line, each defined by its endpoints. For each query, we need to pick one integer point from the first segment and one integer point from the second segment such that the points are different.

codeforcescompetitive-programmingimplementation
CF 1108B - Divisors of Two Integers

We are given a shuffled list of integers, each representing a divisor of one of two unknown positive integers, which we can call x and y. If a number divides both x and y, it appears twice in the list. Our task is to reconstruct any pair (x, y) that could have produced this list.

codeforcescompetitive-programmingbrute-forcegreedymathnumber-theory
CF 1109C - Sasha and a Patient Friend

The problem models a “patience bowl” which has an initial amount of patience that can grow or shrink over time depending on the tap’s speed. The tap’s speed can be changed at discrete times by events.

codeforcescompetitive-programmingbinary-searchdata-structuresimplementation
CF 1109F - Sasha and Algorithm of Silence's Sounds

We are given an $n times m$ grid where every cell contains a unique value from $1$ to $nm$. These values impose a global order on the cells, and we should think of the grid as being revealed gradually: first the cell with value 1 appears, then 2, and so on.

codeforcescompetitive-programmingdata-structurestrees
CF 1109D - Sasha and Interesting Fact from Graph Theory

We are asked to count how many different weighted trees can be built on $n$ labeled vertices when every edge weight is an integer between $1$ and $m$, under a single global constraint involving two distinguished vertices $a$ and $b$.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpmathtrees
CF 1109E - Sasha and a Very Easy Test

We are maintaining an array of integers that is repeatedly modified and queried. The array starts fixed, but over time we apply operations that either scale a contiguous segment, shrink a single element by dividing it, or ask for the sum over a segment.

codeforcescompetitive-programmingdata-structuresnumber-theory
CF 1109B - Sasha and One More Name

We are given a string that is already a palindrome, and our goal is to transform it into a different palindrome by cutting it into some number of contiguous pieces and then reordering these pieces. The task is to find the minimum number of cuts required to achieve this.

codeforcescompetitive-programmingconstructive-algorithmshashingstrings
CF 1109A - Sasha and a Bit of Relax

We are asked to find "funny pairs" in an array of integers. A pair of indices $(l, r)$ is funny if the subarray from $l$ to $r$ has even length and the XOR of the first half equals the XOR of the second half.

codeforcescompetitive-programmingdpimplementation
CF 1110H - Modest Substrings

We are asked to construct a digit string of fixed length n. Every substring of this string is interpreted as a number (ignoring leading zeros), and we get a score of 1 for a substring if that number lies in the inclusive interval [l, r].

codeforcescompetitive-programmingdpstrings
CF 1110A - Parity

The problem gives a number $n$ not in decimal form, but in some arbitrary base $b$. The digits of $n$ are listed from the most significant to the least significant, and the task is to decide whether $n$ is even or odd in decimal.

codeforcescompetitive-programmingmath
CF 1110G - Tree-Tac-Toe

We are asked to analyze a game of tic-tac-toe played on a tree. Each vertex is either uncolored or already white. Two players alternate coloring vertices, starting with white. The first player to complete a path of three vertices in their color wins.

codeforcescompetitive-programmingconstructive-algorithmsgamestrees
CF 1110F - Nearest Leaf

We are given a rooted tree where the parent of each node is fixed by input order: node i connects to some earlier node pi, forming a rooted structure at node 1.

codeforcescompetitive-programmingdata-structurestrees
CF 1110D - Jongmah

We are given a multiset of tiles, where each tile carries an integer value between 1 and m. The goal is to repeatedly pick disjoint groups of exactly three tiles and form as many such groups as possible.

codeforcescompetitive-programmingdp
CF 1110E - Magic Stones

We are given an array of integers representing charges on a line of stones. A single operation picks any interior position and replaces its value using its two neighbors: the new value becomes the sum of the left and right neighbors minus its old value.

codeforcescompetitive-programmingconstructive-algorithmsmathsortings
CF 1110C - Meaningless Operations

We are given a number $a$. For this number we are allowed to pick any $b$ such that $1 le b < a$. For each choice of $b$, we compute two values derived from bitwise operations: one is $a oplus b$, the other is $a & b$. We then take the gcd of these two results.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 1110B - Tape

We are given a sorted list of positions on a long line segment where damage has occurred. Each damaged position must be covered by tape, but the tape does not need to avoid healthy positions, it can freely cover anything in between.

codeforcescompetitive-programminggreedysortings
CF 1111A - Superhero Transformation

We are given two lowercase strings representing superhero names. A transformation is allowed if every vowel can be changed into any other vowel, and every consonant can be changed into any other consonant. The actual letters do not matter.

codeforcescompetitive-programmingimplementationstrings
CF 1111D - Destroy the Colony

We are given a row of holes, each containing exactly one villain, and each villain has a type represented by a character. The string representing the colony is of even length, so it can naturally be divided into two halves.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1111E - Tree

We are given a tree with n nodes and multiple queries. Each query provides a subset of k nodes, a maximum number of groups m, and a root r.

codeforcescompetitive-programmingdata-structuresdfs-and-similardpgraphstrees
CF 1111B - Average Superhero Gang Power

We are given a group of superheroes, each with an initial power value. We are allowed to modify this group using two types of operations: we can either remove a superhero from the group (as long as at least two remain), or we can increase the power of a chosen superhero by one.

codeforcescompetitive-programmingbrute-forceimplementationmath
CF 1111C - Creative Snap

We are given a linear base of length $2^n$, where some positions contain avengers. Thanos wants to destroy the entire base using minimum power.

codeforcescompetitive-programmingbinary-searchbrute-forcedivide-and-conquermath
CF 1113B - Sasha and Magnetic Machines

We are given an array of integers representing the power of n magnetic machines. Each machine contributes positively to the total power of the farm.

codeforcescompetitive-programminggreedynumber-theory
CF 1113A - Sasha and His Trip

Sasha wants to drive from city 1 to city n along a straight line of cities. Each city is exactly one kilometer apart, and all roads go forward, so he cannot move backward. His car consumes one liter of fuel per kilometer and starts with an empty tank.

codeforcescompetitive-programmingdpgreedymath
CF 1114A - Got Any Grapes?

We have three people with different grape preferences and three piles of grapes. Andrew wants exactly the first type of grape, green grapes. If he needs x grapes, all of them must come from the green pile. Dmitry dislikes black grapes. He can eat green or purple grapes.

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 1114F - Please, another Queries on Array?

We have an array of integers, each between 1 and 300, and we need to process two types of queries. The first query multiplies a contiguous segment of the array by a given number.

codeforcescompetitive-programmingbitmasksdata-structuresdivide-and-conquermathnumber-theory
CF 1114E - Arithmetic Progression

We are given a hidden array of size $n$, but the array is not directly accessible and is permuted arbitrarily. The only structural guarantee is that if we sort its elements, they form a perfect arithmetic progression with a strictly positive common difference.

codeforcescompetitive-programmingbinary-searchinteractivenumber-theoryprobabilities
CF 1114D - Flood Fill

We are given a row of n colored squares, each labeled with an integer representing its color. The goal is to recolor the entire row into a single color using a series of "flood fill" operations.

codeforcescompetitive-programmingdp
CF 1114B - Yet Another Array Partitioning Task

We are given a sequence of integers a of length n, and two parameters: m, the number of largest elements we consider when computing the "beauty" of a subarray, and k, the number of contiguous subarrays we must partition a into.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 1114C - Trailing Loves (or L'oeufs?)

We are asked to compute the number of trailing zeros in the factorial of a number when represented in an arbitrary base. More precisely, given integers $n$ and $b$, we want the number of digits equal to zero at the end of the base-$b$ representation of $n!$.

codeforcescompetitive-programmingbrute-forceimplementationmathnumber-theory
CF 1115U1 - Anti-diagonal unitary

We are asked to implement a quantum operation on an array of qubits. The operation must correspond to a unitary matrix whose only non-zero entries lie on the anti-diagonal. For a system of $N$ qubits, the state space has dimension $2^N$.

codeforcescompetitive-programming*special
CF 1115U3 - Block unitary

We are asked to implement a quantum unitary operation on $N$ qubits, where $N$ is small, between 2 and 5. The operation is represented by a $2^N times 2^N$ matrix with a specific block structure. The matrix can be visualized as four quarters: 1.

codeforcescompetitive-programming*special
CF 1115U2 - Chessboard unitary

We are asked to implement a unitary operation on $N$ qubits, where $2 le N le 5$. The operation is represented by a $2^N times 2^N$ matrix with a chessboard-like pattern of zeros and non-zero elements.

codeforcescompetitive-programming*special
CF 1115G2 - OR oracle

We are given a small quantum register of at most eight qubits that encode an input bitstring $x0, x1, dots, x{N-1}$, along with one extra qubit $y$ that acts as an output wire.

codeforcescompetitive-programming*special
CF 1115G3 - Palindrome checker oracle

We are asked to implement a quantum oracle acting on a small register of qubits. The oracle receives an input string encoded in quantum form, represented by an array of up to eight qubits, plus one additional qubit that serves as the output bit.

codeforcescompetitive-programming*special
CF 1115G1 - AND oracle

We are asked to implement a quantum operation that computes the logical AND of an array of qubits. Concretely, we have a set of $N$ qubits, each representing a binary value (0 or 1, though they can be in superposition), and a single output qubit.

codeforcescompetitive-programming*special
CF 1116D6 - Hessenberg matrix

We are asked to implement a quantum operation on a small number of qubits (2 to 4) such that the unitary matrix representing it has an upper Hessenberg form.

codeforcescompetitive-programming*special
CF 1116D5 - Creeper

We are given a very specific 8×8 pattern describing where a 3-qubit unitary matrix has non-negligible entries. The matrix is not arbitrary, it is extremely sparse and structured, and the task is to implement any quantum circuit on 3 qubits whose unitary matches this sparsity…

codeforcescompetitive-programming*special
CF 1116D4 - TIE fighter

We are asked to implement a quantum operation on an array of $N$ qubits, where $N$ ranges from 2 to 5. The core requirement is that the operation's unitary matrix has a very particular pattern: a central 2x2 submatrix filled with non-zero values, anti-diagonals in the top-left…

codeforcescompetitive-programming*special
CF 1116D3 - X-wing fighter

We are asked to implement a unitary operation on a quantum register consisting of $N$ qubits, where $2 le N le 5$. The unitary is represented as a $2^N times 2^N$ matrix, and it must have non-zero entries only on the main diagonal and the anti-diagonal.

codeforcescompetitive-programming*special
CF 1116D2 - Pattern of increasing blocks

We are asked to construct a quantum operation on $N$ qubits whose matrix, in the computational basis, has a very rigid block structure. The full unitary is a $2^N times 2^N$ matrix, and we are not required to compute or print it explicitly.

codeforcescompetitive-programming*special
CF 1116D1 - Block diagonal matrix

We are asked to implement a unitary operation on an array of $N$ qubits, where $2 le N le 5$, such that the matrix representing the operation has a very specific block-diagonal structure.

codeforcescompetitive-programming*special
CF 1116C3 - ``Is the number of ones divisible by 3?'' oracle

We are given a small register of qubits that encode a bitstring and an additional single qubit that acts as an output accumulator.

codeforcescompetitive-programming*special
CF 1116C2 - ``Is the bit string periodic?'' oracle

We are asked to implement a quantum oracle that checks whether a given bit string is periodic. In practical terms, imagine we have an array of $N$ qubits, each representing a bit, and a separate output qubit.

codeforcescompetitive-programming*special
CF 1116B2 - Not A, not B or not C?

We are asked to work with a single qubit that is guaranteed to be in one of three specific quantum states: $ Our goal is not to identify which state the qubit is in, but to return a number corresponding to a state we are sure the qubit is not in.

codeforcescompetitive-programming*special
CF 1116C1 - Alternating bits oracle

We are asked to implement a "quantum oracle" that checks whether a binary vector alternates. That means for an input array of bits x[0..N-1], we need to determine if no two consecutive bits are the same.

codeforcescompetitive-programming*special
CF 1116B1 - Distinguish three-qubit states

We are given three qubits in one of two specific entangled states, each a superposition of three computational basis states with complex coefficients derived from the cube roots of unity. The two states differ only in the phase factors applied to the second and third qubits.

codeforcescompetitive-programming*special
CF 1117A - Best Subsegment

We are given an array of integers and may choose any contiguous subarray. For every chosen subarray, we can compute its arithmetic mean, which is the sum of its elements divided by its length. The task is to find the maximum possible mean among all subarrays.

codeforcescompetitive-programmingimplementationmath
CF 1117F - Crisp String

We are given a string consisting of the first p letters of the lowercase English alphabet, and a symmetric adjacency matrix A that specifies which letters can appear next to each other. A string is crisp if every consecutive pair of letters in it is allowed by this matrix.

codeforcescompetitive-programmingbitmasksdp
CF 1117G - Recursive Queries

We are given a permutation of the numbers from 1 to n. Each query asks for a recursively defined function over a subarray. Specifically, for a range [l, r], we first find the position of the maximum element in that range.

codeforcescompetitive-programmingdata-structures
CF 1117E - Decypher the String

We are given a string t of length n which is the result of applying an unknown sequence of swaps to an original string s. Each swap exchanges two characters at positions ai and bi in s.

codeforcescompetitive-programmingbitmaskschinese-remainder-theoremconstructive-algorithmsinteractivemath
CF 1117D - Magic Gems

We are counting ways to build a final sequence of unit-sized positions whose total length is exactly $N$. Each position can be either a normal gem or the result of splitting a magic gem.

codeforcescompetitive-programmingdpmathmatrices
CF 1117B - Emotes

We are given a set of emotes, each with a positive happiness value. We are allowed to use emotes a fixed number of times, but no single emote can be repeated more than a given number of times consecutively.

codeforcescompetitive-programminggreedymathsortings
CF 1117C - Magic Ship

We are given a starting point on an infinite grid and a target point. Each day, the environment produces a wind direction from a fixed periodic string. That wind shifts the ship by one unit in one of the four cardinal directions.

codeforcescompetitive-programmingbinary-search
CF 1118A - Water Buying

Polycarp needs to buy exactly $n$ liters of water using bottles of two fixed sizes: 1-liter bottles at cost $a$ and 2-liter bottles at cost $b$. For each query, we are asked to determine the minimum total cost to acquire exactly $n$ liters.

codeforcescompetitive-programmingmath
CF 1118F2 - Tree Cutting (Hard Version)

We are given a tree with $n$ vertices. Each vertex is either colored with one of $k$ colors or left uncolored. The tree is connected, so there are $n-1$ edges. We are asked to select exactly $k-1$ edges and remove them, splitting the tree into $k$ components.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardptrees
CF 1118E - Yet Another Ball Problem

We are tasked with assigning colors to dancers at a ball. There are n pairs, each consisting of a man and a woman, and k available colors.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1118F1 - Tree Cutting (Easy Version)

We are given a tree with n vertices, where each vertex may be colored red, blue, or left uncolored. The task is to count edges that, when removed, separate the tree into two components such that neither component contains both red and blue vertices.

codeforcescompetitive-programmingdfs-and-similartrees
CF 1118D2 - Coffee and Coursework (Hard Version)

Polycarp must write a coursework of m pages, but he cannot work indefinitely without caffeine. He has n cups of coffee, each with a caffeine dosage ai.

codeforcescompetitive-programmingbinary-searchgreedy
CF 1118D1 - Coffee and Coursework (Easy version)

We are given a collection of coffee cups, each with a fixed caffeine value. Polycarp can choose some of these cups and distribute them across several days.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1118C - Palindromic Matrix

We are asked to arrange n^2 integers into an n x n square matrix so that the matrix is palindromic along both axes. A palindromic matrix does not change when we reverse the order of rows or reverse the order of columns.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1118B - Tanya and Candies

We are given an array of weights where each index represents a candy. Tanya will remove exactly one candy and then consume the remaining candies strictly in index order, one per day starting from day 1.

codeforcescompetitive-programmingimplementation
CF 1119H - Triple

For every triple $(ai,bi,ci)$, we build an array that contains $ai$ exactly $x$ times, $bi$ exactly $y$ times, and $ci$ exactly $z$ times. From each of the $n$ arrays we choose one value. The XOR of all chosen values is some number $t$.

codeforcescompetitive-programmingfftmath
CF 1119G - Get Ready for the Battle

We are given a situation where Evlampy has n identical soldiers and must fight an enemy army composed of m groups, each with a certain health hpi.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1119F - Niyaz and Small Degrees

We are given a weighted tree. For every degree limit $x$, we may delete any set of edges. Deleting an edge pays its weight. After all deletions, every vertex must have degree at most $x$. For each $x$, we need the minimum total deleted weight.

codeforcescompetitive-programmingdata-structuresdptrees
CF 1119E - Pavel and Triangles

We are given many sticks whose lengths are powers of two. For each exponent i, there are ai sticks of length 2^i. Each stick can be used at most once, and we want to form as many non-degenerate triangles as possible, where each triangle uses exactly three sticks.

codeforcescompetitive-programmingbrute-forcedpfftgreedyternary-search
CF 1119B - Alyona and a Narrow Fridge

The fridge has height h and exactly two columns. Shelves can be inserted at any heights, which means we are free to divide the fridge into horizontal compartments of arbitrary heights. Each bottle occupies one column and has height a[i].

codeforcescompetitive-programmingbinary-searchflowsgreedysortings
CF 1119C - Ramesses and Corner Inversion

We are given two matrices, A and B, of size n × m filled with 0s and 1s. We can modify A by repeatedly selecting any submatrix of size at least 2 × 2 and flipping its four corner values.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 1119A - Ilya and a Colorful Walk

We are given a street with n houses in a row, numbered from 1 to n, where each house has a color represented by an integer. Ilya wants to pick two houses of different colors and walk between them, measuring the distance simply as the difference in their indices (j - i) for i < j.

codeforcescompetitive-programminggreedyimplementation
CF 1120F - Secret Letters

I can't responsibly write a complete editorial and solution for Codeforces 1120F from the problem statement alone.

codeforcescompetitive-programmingdata-structuresdpgreedy
CF 1120D - Power Tree

We are given a rooted tree with n vertices, where each vertex has a non-negative price. The root is vertex 1. Leaves are non-root vertices with degree one.

codeforcescompetitive-programmingdfs-and-similardpdsugraphsgreedytrees
CF 1120E - The very same Munchhausen

We are asked to determine whether a positive integer $n$ exists for a given integer $a ge 2$ such that multiplying $n$ by $a$ reduces its digit sum by a factor of $a$. Formally, we want $S(an) = S(n)/a$, where $S(x)$ is the sum of digits of $x$.

codeforcescompetitive-programmingbrute-force
CF 1120C - Compress String

We are given a string and two costs. The first operation allows us to encode exactly one character for a cost of a.

codeforcescompetitive-programmingdpstrings
CF 1120A - Diana and Liana

The town of Shortriver has a single, very long liana of flowers. Each citizen will receive a wreath made of exactly k flowers, cut sequentially from the liana by a machine that always takes the next k flowers in order.

codeforcescompetitive-programminggreedyimplementationtwo-pointers
CF 1120B - Once in a casino

We are given two equal-length decimal strings, representing numbers written digit by digit. The task is to transform the first number into the second one using a very specific operation applied to adjacent digit pairs.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 1121C - System Testing

We have a situation that models parallel system testing in a contest setting. There are n solutions submitted to a contest. Each solution i requires a[i] tests to be fully verified.

codeforcescompetitive-programmingimplementation
CF 1121B - Mike and Children

We are given a collection of distinct positive integers representing candy sizes. Each child must receive exactly two different candies, and the “happiness level” of a child is defined as the sum of the two candies they receive.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1121A - Technogoblet of Fire

We are given a set of students, each belonging to a school, and each with a power rating. The tournament rule is simple: only the strongest student from each school gets selected. Arkady wants to ensure that a chosen set of k students are selected.

codeforcescompetitive-programmingimplementationsortings
CF 1129E - Legendary Tree

We are asked to reconstruct an unknown tree of $n$ vertices by asking a limited type of query. The query is interactive: for any two disjoint, non-empty sets of vertices $S$ and $T$, and a chosen vertex $v$, we receive the number of pairs $(s, t) in S times T$ such that the…

codeforcescompetitive-programmingbinary-searchinteractivetrees
CF 1129D - Isolation

We are asked to count how many ways we can split a given array of integers into contiguous, non-empty segments such that, in each segment, the number of integers that appear exactly once does not exceed a given threshold $k$.

codeforcescompetitive-programmingdata-structuresdp
CF 1129B - Wrong Answer

We are asked to construct an array of integers such that a particular greedy algorithm gives a wrong answer by an exact amount.

codeforcescompetitive-programmingconstructive-algorithms
CF 1129C - Morse Code

We are asked to track sequences of English letters encoded in Morse code as we build a string incrementally, one character at a time. The string S starts empty and grows by adding either a dot (0) or a dash (1) at each step.

codeforcescompetitive-programmingbinary-searchdata-structuresdphashingsortingsstring-suffix-structuresstrings
CF 1129A1 - Toy Train (Simplified)

We have n stations arranged on a directed cycle. From station i, the train always moves to i + 1, and from station n it wraps back to station 1. Every move between neighboring stations costs exactly one second.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1129A2 - Toy Train

We have a circular train network with n stations, numbered from 1 to n. A single train moves from one station to the next in order, looping back to station 1 after station n, taking exactly 1 second per move.

codeforcescompetitive-programmingbrute-forcegreedy