brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1697F - Too Many Constraints

We are asked to construct a sequence of integers of length n, where each element lies between 1 and k, and the sequence must be non-decreasing. On top of that, the problem provides additional constraints of three types.

codeforcescompetitive-programming2-satconstructive-algorithmsgraphsimplementation
CF 1697E - Coloring

We are given a set of points on a 2D plane with unique coordinates. Each point must be assigned a color represented by an integer from 1 to $n$, and the coloring must satisfy two distance-based constraints.

codeforcescompetitive-programmingbrute-forcecombinatoricsconstructive-algorithmsdpgeometrygraphsgreedyimplementationmath
CF 1697D - Guess The String

We are trying to reconstruct an unknown string of length $n$, where each position contains a lowercase letter. The only way to interact with this hidden string is through two operations: we can directly reveal the character at a chosen position, or we can query a segment and…

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsinteractive
CF 1697A - Parkway Walk

We are given a linear sequence of benches, numbered from one to $n+1$, separated by distances $a1, a2, dots, an$. You start at the first bench with a fixed amount of energy $m$. Walking a distance of one meter consumes exactly one unit of energy.

codeforcescompetitive-programminggreedyimplementation
CF 1697B - Promo

We have a store with n items, each with a specific price. The store runs a promotion where, if a customer buys at least x items, the y cheapest among those items are free. For each query (x, y), we want to determine the maximum total value of items a customer can get for free.

codeforcescompetitive-programminggreedysortings
CF 1698C - 3SUM Closure

We are asked to determine if an array of integers is 3SUM-closed, which means that for every triple of distinct elements in the array, the sum of those three elements is itself present somewhere in the array.

codeforcescompetitive-programmingbrute-forcedata-structures
CF 1698G - Long Binary String

We are given a small binary string s of length up to 35, and we need to manipulate a conceptual binary string t of length $10^{100}$, which is initially all zeros. The operation allowed is selecting a contiguous substring of t of the same length as s and XOR-ing it with s.

codeforcescompetitive-programmingbitmasksmathmatricesmeet-in-the-middlenumber-theory
CF 1698F - Equal Reversal

We are given two arrays, a and b, each of length n. The array b is a permutation of a, so they contain the same multiset of values but possibly in a different order.

codeforcescompetitive-programmingconstructive-algorithmsgraphsimplementationmath
CF 1698E - PermutationForces II

We start with a permutation a, which represents the initial ordering of 1..n. Over n steps, we are allowed to repeatedly swap elements, but the swap range grows in a constrained way: at step i, we can only operate on positions from i to min(i+s, n).

codeforcescompetitive-programmingbrute-forcecombinatoricsgreedysortingstreestwo-pointers
CF 1698D - Fixed Point Guessing

We start with a permutation of numbers from 1 to n, but the permutation is not arbitrary. It is created from the identity arrangement by choosing disjoint pairs of positions and swapping the values inside each pair.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsinteractive
CF 1698A - XOR Mixup

We are given an array of length n that was generated by taking an original array of length n-1, computing the XOR of all its elements, appending that XOR to the array, and then shuffling the result.

codeforcescompetitive-programmingbitmasksbrute-force
CF 1698B - Rising Sand

We are given a row of sand piles, each with some initial height. We are allowed to perform an operation that picks a contiguous segment of fixed length k and increases every pile in that segment by one unit. We can repeat this operation any number of times and on any segments.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1699B - Almost Ternary Matrix

We are asked to construct a binary matrix of size $n times m$ where $n$ and $m$ are guaranteed to be even. The constraint is that each cell must have exactly two neighbors with a value different from its own. Neighbors are defined as the four cells directly adjacent by side.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsmatrices
CF 1699E - Three Days Grace

The problem gives us a multiset of integers, all bounded by a maximum value m, and allows us to repeatedly replace any number x 3 with two integers p and q such that pq = x and both p and q are greater than 1. After each operation, the multiset grows by one element.

codeforcescompetitive-programmingdata-structuresdpgreedymathnumber-theorytwo-pointers
CF 1699D - Almost Triple Deletions

We are given an array of integers, and we can repeatedly remove adjacent pairs that are different. After each removal, the array shrinks and its remaining elements shift left.

codeforcescompetitive-programmingdata-structuresdpgreedy
CF 1699C - The Third Problem

We are given a permutation of integers from 0 to $n-1$, which is simply a rearrangement of these numbers with no repeats. The task is to count how many other permutations are "similar" to the given one, where similarity is defined through the MEX function.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsmath
CF 1699A - The Third Three Number Problem

We are asked to construct three integers $a$, $b$, and $c$, each lying in a large range up to $10^9$, such that a specific expression involving pairwise XOR values matches a given target number $n$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1700E - Serega the Pirate

The puzzle is represented as an $n times m$ grid containing each integer from $1$ to $n cdot m$ exactly once. A sequence solves the puzzle if, when following a path of adjacent cells, the first time each number is visited respects the natural order $1, 2, dots, n cdot m$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithms
CF 1700D - River Locks

The system is a chain of containers, each with a fixed capacity. Water enters a selected subset of these containers at a constant rate of one unit per second per opened pipe.

codeforcescompetitive-programmingbinary-searchdpgreedymath
CF 1700F - Puzzle

We are given two binary grids, each with exactly two rows and $n$ columns. Every cell contains either a zero or a one. The grid starts in an initial configuration and must be transformed into a target configuration.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedy
CF 1700A - Optimal Path

We are asked to find the minimal cost for a turtle to travel from the top-left corner of a table to the bottom-right corner. The table has (n) rows and (m) columns, and each cell contains the number ((i-1) cdot m + j), where (i) and (j) are the row and column indices.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1700B - Palindromic Numbers

The proposed solution is for a Codeforces problem about counting “beautiful triples” in a dynamic set of points. However, the exercise cited, 3.4.1.

codeforcescompetitive-programmingconstructive-algorithmsimplementationmath
CF 1700C - Helping the Nature

We have an array of integers representing soil moisture levels along a path of trees. Each value can be positive, negative, or zero, and our goal is to reduce all values to zero using three operations: decrease a prefix by one, decrease a suffix by one, or increase the entire…

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 1701F - Points

We are given a dynamic set of points on a number line and a fixed parameter $d$. A triple $(i,j,k)$ is called beautiful if the points satisfy $i < j < k$ and the distance between the endpoints $k - i$ is at most $d$. Initially the set of points is empty.

codeforcescompetitive-programmingcombinatoricsdata-structuresimplementationmathmatrices
CF 1701E - Text Editor

We are given two strings, s and t, representing the text we actually wrote and the text we want to have, respectively.

codeforcescompetitive-programmingbrute-forcedpgreedystrings
CF 1701A - Grass Field

We are given a tiny grass field of size $2 times 2$, where each cell either has grass (1) or is empty (0). The goal is to remove all grass using the fewest moves possible.

codeforcescompetitive-programmingimplementation
CF 1701C - Schedule Management

We are given a collection of tasks, where each task has a designated “preferred” worker. If a worker processes a task they are assigned to prefer, it takes one unit of time; otherwise it takes two.

codeforcescompetitive-programmingbinary-searchgreedyimplementationtwo-pointers
CF 1701B - Permutation

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programminggreedy
CF 1702G1 - Passable Paths (easy version)

We are given a tree and several queries. Each query specifies a set of vertices. For every query, we must determine whether all selected vertices can lie on a single simple path of the tree. A tree contains exactly one simple path between any two vertices.

codeforcescompetitive-programmingdfs-and-similartrees
CF 1702G2 - Passable Paths (hard version)

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingdata-structuresdfs-and-similartrees
CF 1702F - Equate Multisets

We are given two collections of integers of the same size. Think of them as two bags of tokens, where the order does not matter but multiplicity does.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedymathnumber-theory
CF 1702D - Not a Cheap String

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programminggreedy
CF 1702E - Split Into Two Sets

We are given a collection of dominoes, each domino represented as a pair of integers between 1 and n, and the total number of dominoes n is even. The task is to split these dominoes into two groups so that within each group no number appears on more than one domino.

codeforcescompetitive-programmingdfs-and-similardsugraphs
CF 1702C - Train and Queries

We are given a train route along stations with very large indices, from 1 to $10^9$. The train travels in the exact order of a list $u1, u2, dots, un$ and can revisit stations multiple times.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1702A - Round Down the Price

Each test case gives the current price of an item. A "round" price is any power of ten: 1, 10, 100, 1000, and so on. We want to reduce the item's price until it becomes the largest round number that does not exceed the original price.

codeforcescompetitive-programmingconstructive-algorithms
CF 1702B - Polycarp Writes a String from Memory

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programminggreedy
CF 1703G - Good Key, Bad Key

We are asked to open a sequence of chests, each containing some number of coins, using either “good” or “bad” keys.

codeforcescompetitive-programmingbitmasksbrute-forcedpgreedymath
CF 1703F - Yet Another Problem About Pairs Satisfying an Inequality

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedysortings
CF 1703E - Mirror Grid

We are given an $n times n$ grid whose cells contain only 0 or 1. We may flip any cell, changing 0 to 1 or 1 to 0, and each flip costs one operation. The goal is to make the grid look identical after rotating it by $90^circ$, $180^circ$, or $270^circ$.

codeforcescompetitive-programmingimplementation
CF 1703D - Double Strings

We are given a collection of short lowercase strings, each with length at most 8. For every string in the list, we need to decide whether it can be formed by taking two strings from the same list and concatenating them in order.

codeforcescompetitive-programmingbrute-forcedata-structuresstrings
CF 1703C - Cypher

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingbrute-forceimplementationstrings
CF 1703A - YES or YES?

We are asked to check whether a three-character string represents the word "YES", ignoring letter case. Each test case provides a single string, and we must output a uniform "YES" or "NO" for each one.

codeforcescompetitive-programmingbrute-forceimplementationstrings
CF 1703B - ICPC Balloons

The contest system processes a sequence of problem solves in time order. Each character in the input string represents a problem label from A to Z, and each occurrence means some team solved that problem at that moment.

codeforcescompetitive-programmingdata-structuresimplementation
CF 1704G - Mio and Lucky Array

We are given an integer array a and we are allowed to modify it using a very specific family of operations. Each operation chooses a starting index i, and then adds a fixed alternating linear pattern to the suffix starting at i: the first element increases by 1, the next…

codeforcescompetitive-programmingconstructive-algorithmsfftmathstrings
CF 1704H1 - Game of AI (easy version)

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsdpfftmath
CF 1704H2 - Game of AI (hard version)

I can't reliably write a correct editorial for Codeforces 1704H2 from the statement alone. This problem is a 3500-rated combinatorics/FFT problem, and the crucial part of a useful editorial is the exact combinatorial characterization, recurrence, generating-function derivation…

codeforcescompetitive-programmingcombinatoricsfftmath
CF 1704F - Colouring Game

We are given a row of cells, each painted either red or blue. Alice and Bob take turns, starting with Alice. On her turn, Alice selects any two neighboring cells such that at least one of them is red and paints them both white.

codeforcescompetitive-programmingconstructive-algorithmsdpgames
CF 1704E - Count Seconds

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdpgraphsimplementationmath
CF 1704D - Magical Array

We are given several arrays of equal length. All of them originate from the same hidden base array. From that base, multiple copies were created, and then each copy was modified using one of two transformation rules.

codeforcescompetitive-programmingconstructive-algorithmshashingimplementationmath
CF 1704A - Two 0-1 Sequences

We are given two sequences of zeros and ones: sequence a of length n and sequence b of length m. We want to transform a into b using two operations that can only modify the first two elements of a and then remove the first element.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1704B - Luke is a Foodie

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 1704C - Virus

We are given a circular arrangement of houses where some positions are initially infected. Each day consists of two phases: first, we permanently protect exactly one currently safe house, and then the infection spreads from every infected house to all adjacent unprotected and…

codeforcescompetitive-programminggreedyimplementationsortings
CF 1705F - Mark and the Online Exam

We are asked to recover the answer key for an online true/false exam with $n$ questions. Each question has exactly one correct answer, either 'T' for true or 'F' for false.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsinteractiveprobabilities
CF 1705E - Mark and Professor Koro

We are given a multiset of positive integers that changes over time. At any moment, we are allowed to take two equal values, remove both, and replace them with a single value that is one larger.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcecombinatoricsdata-structuresgreedy
CF 1705D - Mark and Lightbulbs

We are given a row of lightbulbs, each either on or off, represented as a binary string s. Mark wants to transform this initial configuration into a target configuration t by repeatedly toggling bulbs under a restricted operation: he can choose any bulb i that is not the first…

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsgreedymathsortings
CF 1705B - Mark the Dust Sweeper

We are given a row of rooms, each with some amount of dust. Mark wants to clean all rooms except the last one, using a special operation that moves one unit of dust from an earlier room to a later one, but only if all rooms in between are nonzero.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1705C - Mark and His Unfinished Essay

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1705A - Mark the Photographer

We have a total of $2n$ people with known heights. Mark wants to arrange them into two rows of $n$ people each: a front row and a back row.

codeforcescompetitive-programminggreedysortings
CF 1706E - Qpwoeirut and Vertices

We are given a connected undirected graph with $n$ vertices and $m$ edges. Each edge is numbered from 1 to $m$, and we are asked to process $q$ queries.

codeforcescompetitive-programmingbinary-searchdata-structuresdfs-and-similardivide-and-conquerdsugreedytrees
CF 1706D1 - Chopping Carrots (Easy Version)

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsgreedynumber-theory
CF 1706D2 - Chopping Carrots (Hard Version)

We are given a sorted array of integers representing carrot sizes and a limit k. Our goal is to assign to each carrot a number of cuts, represented by integers pi between 1 and k. Cutting a carrot ai into pi pieces produces a piece size of floor(ai / pi).

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdata-structuresdpgreedymathnumber-theorytwo-pointers
CF 1706B - Making Towers

We are given a sequence of n blocks, each with a color from 1 to n. We need to place them one by one on a 2D grid. The first block always starts at (0, 0).

codeforcescompetitive-programmingdpgreedymath
CF 1706A - Another String Minimization Problem

We are asked to construct a string of length m, initially filled with the letter 'B', by performing n operations defined by a sequence a1, a2, ..., an.

codeforcescompetitive-programming2-satconstructive-algorithmsgreedystring-suffix-structuresstrings
CF 1706C - Qpwoeirut And The City

We are given a row of buildings, each with a certain number of floors. A building is considered "cool" if it is strictly taller than both its immediate neighbors. The first and last buildings cannot be cool because they do not have two neighbors.

codeforcescompetitive-programmingdpflowsgreedyimplementation
CF 1707E - Replace

We are given an array of integers a of length n, where each element is between 1 and n. Conceptually, imagine these as labeled tiles laid out in a row.

codeforcescompetitive-programmingbinary-searchdata-structures
CF 1707D - Partial Virtual Trees

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardpmathtrees
CF 1707F - Bugaboo

I can't responsibly produce a complete editorial and reference solution for Codeforces 1707F from the information I have available.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdpnumber-theory
CF 1707A - Doremy's IQ

We have a sequence of contests, each tied to a specific day, and each contest has a difficulty level. Doremy starts with an initial IQ q, which represents her capacity to handle contests. On each day, she can choose to attempt the contest or skip it.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedyimplementation
CF 1707B - Difference Array

We are given an array of non-negative integers that is already sorted in non-decreasing order. The process described is iterative: at each step, we generate a new array by taking the differences between consecutive elements, sort that array, and repeat until only a single…

codeforcescompetitive-programmingbrute-forcedata-structuresimplementationsortings
CF 1707C - DFS Trees

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingdfs-and-similardsugraphsgreedysortingstrees
CF 1708B - Difference of GCDs

We are given: - $n = 7$, $q = 6$ - array: - queries: So: - queries are 1-indexed - queries may be reversed (we see (7,1), (4,2)), so we must normalize - each query produces a single integer The incorrect output: is a strong sign of this failure mode: The code computed a single…

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1708A - Difference Operations

We are given an array of positive integers. The only allowed operation chooses some position i 1 and replaces a[i] with a[i] - a[i-1]. The operation affects only one element, and it always subtracts the current value immediately to its left.

codeforcescompetitive-programminggreedymath
CF 1709B - Also Try Minecraft

We are asked to count, for every interval $[l, r]$, how many triples of distinct integers $i < j < k$ inside this interval satisfy a structural inequality involving their least common multiple: the LCM of the three numbers must be at least as large as their sum.

codeforcescompetitive-programmingdata-structuresdpimplementation
CF 1709F - Multiset of Strings

Think of all binary strings of length at most n as the nodes of a complete binary trie of depth n. Every node except the root receives a capacity cs between 0 and k. A multiset of binary strings of length exactly n assigns some multiplicity to every leaf.

codeforcescompetitive-programmingbitmasksbrute-forcedpfftflowsgraphsmathmeet-in-the-middletrees
CF 1709E - XOR Tree

We are given a tree with n nodes, each labeled with an integer. The key property of interest is the XOR of numbers along any simple path (a path that does not revisit nodes). A tree is "good" if every simple path has a nonzero XOR.

codeforcescompetitive-programmingbitmasksdata-structuresdfs-and-similardsugreedytrees
CF 1709D - Rorororobot

We are given a grid with $n$ rows and $m$ columns. Each column has some blocked cells at the bottom, specified by an array $a$ where $a[i]$ tells us how many cells at the bottom of column $i$ are blocked. The remaining cells are free.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedymath
CF 1709C - Recover an RBS

We are given strings consisting of three types of characters: opening brackets '(', closing brackets ')', and question marks '?'. The original string was a correct bracket sequence, also called a regular bracket sequence (RBS), but some brackets were replaced by question marks.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationstrings
CF 1709A - Three Doors

We are given three doors, each with a unique lock number from 1 to 3. We also hold a key in our hand, and behind each door there may be another key or nothing. Two keys are hidden behind doors, and one key is in our hand.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmath
CF 1710C - XOR Triangle

We are asked to count triples of integers taken from a segment $[l, r]$ such that the indices are strictly increasing and the value of the least common multiple of the three numbers is at least as large as their sum. The input describes several independent ranges.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsdpgreedymath
CF 1710D - Recover the Tree

We are given a tree with n vertices indexed from 1 to n. The problem does not provide the tree explicitly, but it provides information about all possible contiguous segments of vertex indices. A segment [l,r] is called good if the vertices {l, l+1, ...

codeforcescompetitive-programmingconstructive-algorithmstrees
CF 1710E - Two Arrays

The game takes place on a conceptual grid where each position is identified by a row index and a column index. Each row has a fixed value from array a, and each column has a fixed value from array b. If the game ends at a cell (r, c), the score is simply the sum a[r] + b[c].

codeforcescompetitive-programmingbinary-searchgamesgraph-matchings
CF 1710B - Rain

We are asked to model rainfall accumulation along an infinite integer line. Each day brings rain concentrated at a specific position, with intensity that decays linearly with distance.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresgeometrygreedyimplementationmath
CF 1710A - Color the Picture

We are asked to color an $n times m$ grid using $k$ pigments, each of which can color a limited number of cells. A picture is considered beautiful if every cell shares its color with at least three of its four toroidal neighbors.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1711A - Perfect Permutation

The provided solution is not failing because of a small implementation bug. It is failing because the core reduction is incorrect, and the code path that tries to approximate the answer is internally inconsistent.

codeforcescompetitive-programmingconstructive-algorithms
CF 1711B - Party

We are asked to organize a party for a club with $n$ members. Each member has a potential unhappiness value if they are not invited. The club also tracks friendships among members, where each pair of friends eats a cake if both are present.

codeforcescompetitive-programmingbrute-forcegraphs
CF 1712A - Wonderful Permutation

We are given a permutation of integers from 1 to $n$, meaning every number from 1 through $n$ appears exactly once, in some arbitrary order. The task is to minimize the sum of the first $k$ elements in this permutation by performing swaps between any two positions.

codeforcescompetitive-programminggreedyimplementation
CF 1713C - Build Permutation

We are asked to construct a permutation of the numbers from $0$ to $n-1$ such that for each index $i$, the sum of the value at that index and the index itself is a perfect square. In other words, for every $i$, $pi + i = k^2$ for some integer $k$.

codeforcescompetitive-programmingconstructive-algorithmsdpmath
CF 1713F - Lost Array

We are given a hidden array a of length n and a derived matrix b of size (n+1) × (n+1) defined using XOR. The matrix b starts with zeros in the first column and the first row is the array a. Every other cell in b is constructed as b[i][j] = b[i][j-1] XOR b[i-1][j].

codeforcescompetitive-programmingbitmaskscombinatoricsconstructive-algorithmsdpmath
CF 1713E - Cross Swapping

We are given a square matrix of integers, and we are allowed to perform a specific swap operation: for a chosen index k, we swap the k-th row with the k-th column, leaving the diagonal element at (k, k) unchanged.

codeforcescompetitive-programming2-satdata-structuresdsugreedymatrices
CF 1713D - Tournament Countdown

We are dealing with a complete single-elimination tournament of size $2^n$. Players are indexed from 1 to $2^n$. Matches happened in a fixed bracket: adjacent pairs played first, then winners of neighboring matches played again, and so on until one champion remains.

codeforcescompetitive-programmingconstructive-algorithmsgreedyinteractivenumber-theoryprobabilities
CF 1713B - Optimal Reduction

We are given an array of positive integers. We can repeatedly choose a contiguous subarray and decrease all elements in that subarray by one. The goal is to bring all array elements to zero using as few operations as possible.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 1713A - Traveling Salesman Problem

We are working on a grid where movement is allowed in the four cardinal directions, and every move costs one step.

codeforcescompetitive-programminggeometrygreedyimplementation
CF 1714A - Everyone Loves to Sleep

The intended structure of the solution was: 1. Run shortest paths using roads (standard Dijkstra). 2. Repeatedly allow up to k flights. 3. Each flight step computes: $$new[v] = minu (dp[u] + (u - v)^2)$$ 4. Then relax roads again.

codeforcescompetitive-programmingimplementationmath
CF 1714F - Build a Tree and That Is It

We are asked to construct an unrooted tree with a fixed number of vertices and three specific distance constraints between vertices 1, 2, and 3. Each test case provides four integers: the number of nodes $n$ and the pairwise distances $d{12}$, $d{23}$, and $d{31}$.

codeforcescompetitive-programmingconstructive-algorithmsimplementationtrees
CF 1714G - Path Prefixes

We are asked to process a rooted tree with values on each edge. Each edge has two integers, $aj$ and $bj$. For every non-root node $i$, we consider the path from the root to $i$. Let $Ai$ be the sum of all $aj$ along this path.

codeforcescompetitive-programmingbinary-searchdata-structuresdfs-and-similartrees
CF 1714E - Add Modulo 10

We are given an array of integers, and for each element we can repeatedly increase it by its last digit. For instance, if the element is 27, applying the operation gives 27 + 7 = 34, and applying it again gives 34 + 4 = 38.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1714D - Color with Occurrences

We are given a target string t and up to ten pattern strings. A move consists of picking one pattern and choosing one of its occurrences inside t, then marking all characters of that occurrence as colored.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedystrings
CF 1714B - Remove Prefix

We are given a sequence of integers a of length n, where each integer lies between 1 and n. The goal is to make the sequence contain only distinct values by repeatedly removing elements from the beginning.

codeforcescompetitive-programmingdata-structuresgreedyimplementation
CF 1714C - Minimum Varied Number

We are given a target sum for digits, and for each query we need to construct the smallest possible positive integer whose digits are all different and whose digit sum equals that target.

codeforcescompetitive-programminggreedy
CF 1715E - Long Way Home

Stanley wants to travel from city 1 to every other city in a country with two types of transport: roads and flights. The roads are given explicitly as edges with weights, forming an undirected graph.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdpgeometrygraphsgreedyshortest-paths