brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1765G - Guess the String

We are asked to reconstruct a hidden binary string of length $n$, knowing that its first character is always '0'. We cannot read the string directly.

codeforcescompetitive-programmingconstructive-algorithmsinteractiveprobabilities
CF 1765E - Exchange

For input n = 1, k = 1: - Deck: 4 cards, one of each suit. - Sliding window k = 1 means Monocarp looks at the last card drawn (or zero for the first card) and guesses the least frequent suit.

codeforcescompetitive-programmingbrute-forcemath
CF 1765B - Broken Keyboard

We are asked to determine whether a given word could have been typed on a keyboard with a very specific malfunction: every other keystroke produces the letter twice instead of once.

codeforcescompetitive-programminggreedy
CF 1765F - Chemistry Lab

We have a chemistry lab scenario where Monocarp can buy contracts that give him unlimited access to specific solutions of an acid. Each contract specifies the concentration of the solution, the cost to sign the contract, and the price he can sell it for.

codeforcescompetitive-programmingdpgeometryprobabilities
CF 1765D - Watch the Videos

We are given a sequence of videos, each with a download size, and a fixed disk capacity that limits how many megabytes can be stored at once. Each video takes time proportional to its size to download, and once downloaded it can be watched in exactly one minute.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmstwo-pointers
CF 1765C - Card Guessing

We are dealing with a long sequence of independent random experiments: a deck contains exactly four suits, and each suit appears exactly (n) times, so the total length is (4n). The deck is shuffled uniformly at random, so every permutation is equally likely.

codeforcescompetitive-programmingcombinatoricsdpprobabilities
CF 1765A - Access Levels

Each document is described by which developers should be able to open it. So every column of the input matrix is a subset of developers: those rows where the value is one form the “approved set” for that document.

codeforcescompetitive-programmingbitmasksdsuflowsgraph-matchings
CF 1766F - MCF

We are given a directed graph where each edge has a capacity and a cost. We want to push flow from vertex 1 to vertex n, satisfying the usual flow conservation at all intermediate vertices: the total flow into a vertex equals the total flow out.

codeforcescompetitive-programmingflows
CF 1766E - Decomposition

For any array segment, we process its elements from left to right and maintain a list of subsequences. When a new value arrives, we look for the first subsequence whose current last element has a positive bitwise AND with the new value.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdivide-and-conquerdptwo-pointers
CF 1766A - Extremely Round

Input: Expected: Actual: a long list of card distributions So the program is no longer failing with a crash, but producing completely irrelevant output.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1766D - Lucky Chains

We are given a list of pairs of positive integers, and for each pair, we want to explore a sequence of consecutive pairs formed by simultaneously incrementing both numbers.

codeforcescompetitive-programmingmathnumber-theory
CF 1766C - Hamiltonian Wall

We are given a grid with two rows and m columns representing a wall. Each cell is either black (B) or white (W). Monocarp wants to paint all black cells exactly once in a single continuous path that moves only between adjacent cells.

codeforcescompetitive-programmingdpimplementation
CF 1766B - Notepad#

We are asked to type a string s of length n using a text editor that allows two operations: appending a single character or copying a contiguous substring that has already been typed and pasting it at the end.

codeforcescompetitive-programmingimplementation
CF 1767A - Cut the Triangle

The problem gives a triangle in the plane with positive area, specified by three points with integer coordinates.

codeforcescompetitive-programmingimplementation
CF 1767D - Playoff

We are looking at a tournament structured as a perfect binary tree. At the start there are $2^n$ teams, each assigned a distinct skill value from 1 to $2^n$.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsdpgreedymath
CF 1767F - Two Subtrees

We are given a rooted tree where every vertex stores an integer label. For each query, we are given two vertices, and we must look at two subtrees rooted at these vertices.

codeforcescompetitive-programmingdata-structurestrees
CF 1767E - Algebra Flash

We are given a linear sequence of platforms, each with a fixed color, and a cost associated with activating all platforms of each color. Initially, all platforms are deactivated. You can only jump from a platform to the next one or skip one to the platform after that.

codeforcescompetitive-programmingbitmasksbrute-forcedpgraphsmathmeet-in-the-middletrees
CF 1767C - Count Binary Strings

We are given an $n times n$ upper-triangular table of constraints on substrings of a binary string $s$ of length $n$. For every interval $[i, j]$, we are told whether that segment must be constant, must contain both 0 and 1, or is unconstrained.

codeforcescompetitive-programmingdata-structuresdp
CF 1767B - Block Towers

We are given several towers, each containing a certain number of blocks. The goal is to maximize the number of blocks on the first tower by moving blocks from towers that have more blocks than others.

codeforcescompetitive-programmingdata-structuresgreedysortings
CF 1768F - Wonderful Jump

Input: Expected: Two different configurations (two different games), each printed as a pair of 18-card hands. Actual output: Two identical blocks: This means: - Your program does print two cases - But they are not correctly separated as distinct constructions in memory - Or…

codeforcescompetitive-programmingdpgreedy
CF 1768D - Lucky Permutation

We are given a permutation of integers from 1 to $n$, and we can swap any two elements to change the permutation. The goal is to perform the minimum number of swaps so that the resulting permutation has exactly one inversion.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsgreedy
CF 1768E - Partial Sorting

We are given a permutation of size 3n, which is an array containing every integer from 1 to 3n exactly once in some order. We have two allowed operations: we can either sort the first 2n elements or sort the last 2n elements.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 1768B - Quick Sort

We are given a permutation, meaning a rearrangement of numbers from 1 to n. In one move, we pick any k elements, remove them from the array, sort just those chosen elements, and append them back to the end. The rest of the array keeps its relative order.

codeforcescompetitive-programminggreedymath
CF 1768A - Greatest Convex

The problem asks us to find the largest integer x less than a given integer k such that the sum of x! and (x-1)! is divisible by k. In plain language, we want a number just below k where adding its factorial to the factorial of the previous number gives a multiple of k.

codeforcescompetitive-programminggreedymathnumber-theory
CF 1768C - Elemental Decompress

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationsortings
CF 1769D2 - Игра в Девятку II

We are dealing with a deterministic two-player card game played with a fixed 36-card deck. The deck is split between two players, and the game evolves by repeatedly placing cards onto a shared table under strict adjacency rules: a card can only be played if it either is a nine…

codeforcescompetitive-programming*specialbrute-force
CF 1769D3 - Игра в Девятку III

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programming*specialbrute-force
CF 1769D1 - Игра в Девятку I

We have a two-player card game using a 36-card deck, where each player gets 18 cards. The cards are numbered 6 through Ace in four suits. Alice moves first. On their turn, a player can play: - Any 9, at any time.

codeforcescompetitive-programming*specialbrute-forcedp
CF 1769C2 - Подкрутка II

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programming*specialdp
CF 1769A - Узкая дорога

We are given a line of scooters sorted by their initial distance to a destination point. Scooter $1$ starts closest, scooter $n$ farthest. Each scooter has a fixed nominal speed equal to its index, so higher-index scooters try to move faster.

codeforcescompetitive-programming*specialmath
CF 1769C1 - Подкрутка I

We are given a multiset of “events”, where each event originally belongs to a specific day. The array is sorted, and each value tells us on which day a commit happened.

codeforcescompetitive-programming*specialbrute-forcedpgreedy
CF 1769B2 - Копирование файлов II

We are asked to model copying multiple files sequentially from one server to another, tracking progress in two ways: per-file and overall. Each file has a size in bytes, and we simulate copying byte by byte.

codeforcescompetitive-programming*specialbinary-searchbrute-forcemath
CF 1769B1 - Копирование файлов I

We are asked to simulate the progress of copying multiple files from one server to another. Each file has a size in bytes, and copying is sequential, one byte at a time.

codeforcescompetitive-programming*specialbrute-forceimplementationmath
CF 1770H - Koxia, Mahiru and Winter Festival

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingconstructive-algorithms
CF 1770F - Koxia and Sequence

We are asked to work with sequences of non-negative integers of length $n$. Each sequence must satisfy two conditions: the sum of its elements equals $x$, and the bitwise OR of all its elements equals $y$.

codeforcescompetitive-programmingbitmaskscombinatoricsdpmathnumber-theory
CF 1770G - Koxia and Bracket

We are given a string composed entirely of opening and closing parentheses, and we are asked to make it balanced by removing the fewest possible characters.

codeforcescompetitive-programmingdivide-and-conquerfftmath
CF 1770E - Koxia and Tree

We are given a tree with $n$ vertices and $k$ butterflies initially located on distinct vertices. Each edge in the tree will be randomly directed, and butterflies can move along edges if the starting vertex has a butterfly and the target vertex is empty.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardpdsumathprobabilitiestrees
CF 1770D - Koxia and Game

We are given two arrays, a and b, each of length n, with elements between 1 and n. We have to choose a third array c of the same length so that a constructed game is won by Koxia. The game proceeds in n rounds.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdfs-and-similardsuflowsgamesgraph-matchingsgraphsimplementation
CF 1770A - Koxia and Whiteboards

We start with an array of numbers placed on whiteboards. Then we are given a sequence of replacement values. Each replacement operation allows us to pick any one whiteboard and overwrite its current value with the new value from the operation.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1770B - Koxia and Permutation

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingconstructive-algorithms
CF 1770C - Koxia and Number Theory

We are given an array of positive integers and we are allowed to choose a single positive shift value $x$. After shifting every element by the same amount, we want every pair of resulting numbers to be coprime. Equivalently, we transform the array into $bi = ai + x$.

codeforcescompetitive-programmingbrute-forcechinese-remainder-theoremmathnumber-theory
CF 1771D - Hossam and (sub-)palindromic tree

We are given a tree with $n$ vertices, each labeled with a lowercase English letter. For any two vertices $v$ and $u$, define the string $s(v,u)$ as the sequence of letters along the unique path connecting them.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similardpstringstrees
CF 1771F - Hossam and Range Minimum Query

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structureshashingprobabilitiesstringstrees
CF 1771E - Hossam and a Letter

We are given an n × m grid representing Hossam's ground. Each cell has a quality: perfect (.), medium (m), or bad (). Hossam wants to draw the letter 'H' by placing walls on some cells. The letter consists of two vertical lines and one horizontal line connecting them.

codeforcescompetitive-programmingbrute-forcedpimplementationtwo-pointers
CF 1771B - Hossam and Friends

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdptwo-pointers
CF 1771C - Hossam and Trainees

This is a Type C (optimization) problem. The requirements are to establish an upper bound on the boundary length $L$ between horizontal and vertical dominoes and to exhibit a construction that achieves the maximal possible $L$.

codeforcescompetitive-programminggreedymathnumber-theory
CF 1771A - Hossam and Combinatorics

We are given an array for each test case, and we are asked to focus only on pairs of positions in that array. From every ordered pair of distinct indices, we can compute the absolute difference between the two values.

codeforcescompetitive-programmingcombinatoricsmathsortings
CF 1772G - Gaining Rating

Monocarp wants to increase his chess rating from x to y by playing a set of n opponents with fixed ratings. Each game affects only Monocarp's rating: if his current rating is at least the opponent's, he wins and gains 1; otherwise, he loses and drops 1.

codeforcescompetitive-programmingbinary-searchgreedyimplementationmathsortingstwo-pointers
CF 1772E - Permutation Game

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programminggames
CF 1772F - Copy of a Copy of a Copy

We are given a sequence of black-and-white pictures, each represented as an $n times m$ matrix of zeros and ones.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsimplementationsortings
CF 1772D - Absolute Sorting

We are given a sequence of integers. We are allowed to pick a single real number $x$, and then every element $ai$ is transformed into its distance from $x$, namely $ The task is to determine whether there exists such a choice of $x$, and if it exists, output one valid value.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1772C - Different Differences

We are asked to build a strictly increasing sequence of length $k$, where every element lies between $1$ and $n$. Among all such sequences, we are not maximizing the values themselves but a derived quantity based on consecutive differences.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1772A - A+B?

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingimplementation
CF 1772B - Matrix Rotation

We are asked to consider domino tilings of an $8times8$ board. Each domino occupies exactly two adjacent cells and has an orientation, horizontal or vertical.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1773K - King's Puzzle

Thank you for the clarification. Let’s carefully trace why the previous solution produced 2.0 instead of 1.0 for the input: Participant 1 is Genie. The mask of the only question is: So mask = 0b11010 = 26. The initial alive set is all participants: S = 0b11111 = 31.

codeforcescompetitive-programmingconstructive-algorithms
CF 1773G - Game of Questions

Each test case gives a binary matrix with up to 17 columns and up to 2⋅10^5 rows. Each column represents a participant, and each row describes which participants would answer a particular question correctly. The questions are randomly permuted before being asked.

codeforcescompetitive-programmingbitmaskscombinatoricsdpfftmathprobabilities
CF 1773D - Dominoes

Now we finally see a real logical failure rather than a wrapper issue. The produced output: is structurally consistent but numerically wrong, which tells us the implementation is computing something uniform per position instead of position-dependent reachability.

codeforcescompetitive-programmingcombinatoricsflowsgraph-matchingsgreedy
CF 1773C - Cactus Meets Torus

We are given a grid of integers with n rows and m columns. Each row represents a cactus, and each column represents a torus.

codeforcescompetitive-programming
CF 1774H - Maximum Permutation

We are given a deck of cards numbered from 1 to $n$, and we are asked to construct a permutation of these numbers such that a certain value is maximized. The value of a permutation is defined as the minimum sum of any contiguous subarray of length $k$.

codeforcescompetitive-programmingconstructive-algorithms
CF 1774F1 - Magician and Pigs (Easy Version)

We are given a sequence of operations that act on a set of pigs. Each pig has a Health Point value. The operations can either create a new pig with a certain health, reduce the health of all existing pigs by a fixed amount, or repeat all previous operations.

codeforcescompetitive-programmingbrute-forcedata-structuresimplementation
CF 1774F2 - Magician and Pigs (Hard Version)

We are given a sequence of operations a magician performs. The magician has pigs, each with a certain Health Point (HP). The operations can create pigs, reduce the HP of all pigs, or repeat all previous operations.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresimplementation
CF 1774G - Segment Covering

We are given a collection of intervals on a huge number line and many queries, each asking about a fixed target interval $[l, r]$.

codeforcescompetitive-programmingbrute-forcecombinatoricsconstructive-algorithmsdata-structuresdptrees
CF 1774C - Ice and Fire

We have a tournament with players numbered from 1 to $n$, where each player has a "temperature" equal to their number. Battles happen in environments labeled 0 or 1. In environment 0, the lower-temperature player wins, and in environment 1, the higher-temperature player wins.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedy
CF 1774E - Two Chess Pieces

We have a rooted tree with root at node 1. Two chess pieces start at the root. Piece A must visit every node from a given set A, piece B must visit every node from another set B. The order is arbitrary. After all required visits are completed, both pieces must return to the root.

codeforcescompetitive-programmingdfs-and-similardpgreedytrees
CF 1774D - Same Count One

We have n binary rows, each of length m. A single operation chooses two rows and one column, then swaps the values in that column between those two rows. Because the swap happens inside the same column, the total number of 1s in the whole matrix never changes.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedyimplementationtwo-pointers
CF 1774B - Coloring

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1774A - Add Plus Minus Sign

We are given a binary string, a sequence of 0 and 1, and we want to insert either + or - between each pair of consecutive digits so that the absolute value of the resulting arithmetic expression is minimized.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1775E - The Human Equation

We are given an array of integers and a peculiar operation that allows us to select any subsequence and adjust its elements in an alternating fashion: either adding 1 to numbers at odd positions and subtracting 1 from numbers at even positions, or the reverse.

codeforcescompetitive-programminggreedyimplementation
CF 1775C - Interesting Sequence

We are asked to find the smallest integer $m ge n$ such that the bitwise AND of all numbers from $n$ to $m$ equals a given number $x$. Formally, we want $n & (n+1) & dots & m = x$.

codeforcescompetitive-programmingbitmasksmath
CF 1775F - Laboratory on Pluto

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedymath
CF 1775D - Friendly Spiders

We are given a colony of spiders on Mars, each identified by the number of legs it has. Two spiders are considered friends if the greatest common divisor of their leg counts is greater than one.

codeforcescompetitive-programmingdfs-and-similargraphsmathnumber-theoryshortest-paths
CF 1775A1 - Gardener and the Capybaras (easy version)

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsimplementation
CF 1775B - Gardener and the Array

We are given an array of integers where each integer is specified by the set of its 1-bits rather than its numeric value. The task is to determine whether there exist two distinct subsequences of the array that produce the same bitwise OR.

codeforcescompetitive-programmingbitmasksconstructive-algorithms
CF 1775A2 - Gardener and the Capybaras (hard version)

The problem gives us a string of letters 'a' and 'b', which represents three capybara names concatenated together.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1776M - Parmigiana With Seafood

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingbinary-searchdpgreedytrees
CF 1776L - Controllers

We are asked to determine whether a player can reach exactly zero score after a sequence of game rounds, given a controller with two buttons labeled with arbitrary positive integers.

codeforcescompetitive-programmingbinary-searchmath
CF 1776N - Count Permutations

We are asked to count the number of permutations of the numbers from 1 to $n$ that satisfy a chain of inequalities described by a string of length $n-1$. Each character of the string is either < or .

codeforcescompetitive-programmingmath
CF 1776K - Uniform Chemistry

Each researcher starts with a chemical labeled by an integer between $1$ and $n-1$. Every year they upgrade their current chemical: if someone currently holds value $a$, they replace it with a uniformly random integer from the interval $(a, n]$.

codeforcescompetitive-programmingdpmath
CF 1776J - Italian Data Centers

Codeforces 1776J: Italian Data Centers

codeforcescompetitive-programminggraphsshortest-paths
CF 1776H - Beppa and SwerChat

The list shown by SwerChat is ordered by recency. The member who was online most recently appears first, the second most recent appears second, and so on. At 9:00, Beppa records an ordering a. At 22:00, she records another ordering b.

codeforcescompetitive-programmingtwo-pointers
CF 1776I - Spinach Pizza

We are given a strictly convex polygon with labeled vertices in counterclockwise order. Each move consists of choosing one currently unused vertex.

codeforcescompetitive-programminggamesgeometrygreedyinteractive
CF 1776F - Train Splitting

We are given a connected undirected graph. Every edge must be assigned to a company. Suppose company c owns all edges colored c. The coloring must satisfy two conditions. The first condition says that no single company is allowed to own a connected spanning network.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedy
CF 1776G - Another Wine Tasting Event

We are given a binary string of length $2n-1$, where each position represents a bottle of wine, either white or red. From this fixed sequence, we need to assign $n$ critics to $n$ distinct segments of the array.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsmathstrings
CF 1776E - Crossing the Railways

We are asked to simulate a person, Isona, crossing a set of parallel railway tracks from one platform to another, while avoiding trains. The crossing is straight and perpendicular to the railways.

codeforcescompetitive-programmingdata-structuresdp
CF 1776D - Teamwork

We are asked to schedule a team of three people to solve a set of problems with three difficulty levels: easy, medium, and hard. Each problem has a fixed duration depending on its difficulty: easy takes 2 units of time, medium 3 units, and hard 4 units.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1776A - Walking Boy

The task asks us to determine whether it is possible for the judge to have walked Boy, her dog, at least twice during a single day given a timeline of messages. Each walk takes exactly 120 minutes, cannot overlap another walk, and the judge never sends messages during a walk.

codeforcescompetitive-programminggreedy
CF 1776B - Vittorio Plays with LEGO Bricks

We are asked to place a set of LEGO Duplo bricks on a 1D line along the x-axis, with the constraint that each brick occupies a 2×2 square on the ground and has height 1.

codeforcescompetitive-programmingdpgeometry
CF 1776C - Library game

We are playing a sequential game on a line of labeled sections, each section representing a distinct subject. Each day, one of two players chooses a contiguous interval of sections, constrained by a fixed length coming from a multiset of available “passes”.

codeforcescompetitive-programminggamesgreedyinteractivesortings
Kvant Math Problem 2882

The game begins with $1000$ heaps containing $1,2,3,\dots,1000$ matches respectively.

kvantmathematicsolympiad
CF 1777E - Edge Reverse

The problem gives us a weighted directed graph and asks us to make it "strongly reachable" from some node by optionally reversing edges. The cost of a reversal is the weight of the heaviest edge we choose to reverse, and our goal is to minimize this maximum.

codeforcescompetitive-programmingbinary-searchdfs-and-similargraphstrees
CF 1777F - Comfortably Numb

We are given a sequence of non-negative integers and asked to examine every contiguous segment. For each segment, we compute two values: the bitwise XOR of all elements in the segment, and the maximum element in that same segment.

codeforcescompetitive-programmingbitmasksdata-structuresdivide-and-conquerstringstrees
CF 1777C - Quiz Master

We are asked to select a subset of students from a school to form a quiz team. Each student has a smartness value, and each quiz topic requires at least one team member whose smartness is divisible by the topic number.

codeforcescompetitive-programmingbinary-searchmathnumber-theorysortingstwo-pointers
CF 1777D - Score of a Tree

We are given a rooted tree with n nodes. Each node initially holds a value of either 0 or 1. The evolution of values in the tree is defined by a simple rule: at each integer time t 0, every non-leaf node updates its value to the XOR of the values of its children from the…

codeforcescompetitive-programmingbitmaskscombinatoricsdfs-and-similardpmathprobabilitiestrees
CF 1777B - Emordnilap

We are asked to compute a sum over all permutations of size $n$, where each permutation contributes the number of inversions in a specific array derived from it.

codeforcescompetitive-programmingcombinatoricsgreedymath
CF 1777A - Everybody Likes Good Arrays!

We are asked to transform an array of integers into a “good array,” which is defined as an array where no two consecutive elements share the same parity. Parity simply means whether a number is odd or even.

codeforcescompetitive-programminggreedymath
CF 1778E - The Tree Has Fallen!

We are given a tree with n nodes, where each node has an integer value written on it. Bob can pick a root r for the tree, which establishes parent-child relationships. Then Alice picks a node v, and Bob can choose any subset of nodes from the subtree rooted at v.

codeforcescompetitive-programmingbitmasksdfs-and-similarmathtrees
CF 1778F - Maximizing Root

We are asked to maximize the value of the root of a tree after performing at most $k$ operations. Each operation allows us to pick a vertex $v$ that has not been selected before, choose a number $x$ that divides all values in $v$'s subtree, and multiply every value in that…

codeforcescompetitive-programmingdfs-and-similardpgraphsmathnumber-theorytrees
CF 1778A - Flip Flop Sum

We are given an array consisting only of 1s and -1s. The task is to perform exactly one operation: select two consecutive elements and flip their signs. After doing this, we want to maximize the sum of all array elements.

codeforcescompetitive-programminggreedyimplementation
CF 1778D - Flexible String Revisit

Two binary strings of equal length evolve over time, but only one of them changes. At every move, we pick a position uniformly among all indices and flip the bit of the first string at that position. The second string is fixed.

codeforcescompetitive-programmingcombinatoricsdpmathprobabilities
CF 1778B - The Forbidden Permutation

We are given a permutation p of the numbers 1...n. Another array a contains m distinct values that all appear in the permutation. For every value, we care only about its position inside the permutation. Let pos[x] be the index of value x in p.

codeforcescompetitive-programminggreedymath