brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 2098E - Bermuda Triangle

We are asked to model a simplified version of the Bermuda Triangle as a right triangle on a 2D coordinate plane, with vertices at $(0,0)$, $(0,n)$, and $(n,0)$. A plane starts inside this triangle at $(x,y)$ and moves with a velocity vector $(vx,vy)$.

codeforcescompetitive-programmingchinese-remainder-theoremgeometrynumber-theory
CF 2098C - Sports Betting

Each student fixes a specific day, and Vadim is essentially trying to “predict” what will happen on the next two days after that chosen day.

codeforcescompetitive-programminggreedymathsortings
CF 2090F2 - Key of Like (Hard Version)

We are asked to simulate a sequential key-and-lock game among n players. There are l locks, each with a unique corresponding key, and k counterfeit keys that do not open any lock.

codeforcescompetitive-programmingdpmathprobabilities
CF 2090E2 - Canteen (Hard Version)

We are given two sequences of integers, a and b, both of length n. Each element of a represents some resource or quantity that we want to reduce to zero, and each element of b represents a capacity or counter-resource.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedy
CF 2090F1 - Key of Like (Easy Version)

We are asked to calculate the expected number of successful key-lock matches for each participant in a turn-based game. There are $n$ members taking turns sequentially, $l$ locks, and exactly $l$ keys (since $k = 0$ in this easy version). Each key opens exactly one lock.

codeforcescompetitive-programmingcombinatoricsdpmathprobabilities
CF 2090E1 - Canteen (Easy Version)

We are given two sequences of integers, a and b, both of length n. The goal is to reduce all elements of a to zero by performing a repeated operation called a round.

codeforcescompetitive-programmingdata-structuresmathtwo-pointers
CF 2090B - Pushing Balls

We are given the final occupancy pattern of a grid after some sequence of ball insertions. A ball can be pushed either from the left side of a row or from the top side of a column. The ball travels forward until it reaches a cell. If that cell is empty, it stays there.

codeforcescompetitive-programmingbrute-forcedpimplementation
CF 2090C - Dining Hall

The dining hall is an infinite grid of cells. Some of these cells are grouped into tables, each table occupying a 2×2 square located at coordinates of the form $(3x+1,3y+1)$ through $(3x+2,3y+2)$, and all other cells are corridors.

codeforcescompetitive-programmingdata-structuresgreedyimplementationsortings
CF 2090D - Simple Permutation

We are asked to construct a permutation of the first $n$ positive integers such that a sequence derived from it has many prime numbers. Specifically, for a permutation $p1, p2, dots, pn$, we define $ci = lceil frac{p1 + p2 + dots + pi}{i} rceil$.

codeforcescompetitive-programmingconstructive-algorithmsnumber-theory
CF 2082F - MST in Modulo Graph

We are asked to compute the minimum spanning tree (MST) of a complete graph, but the edge weights are unusual. Each vertex has an associated weight $pi$, and the weight of an edge between two vertices $x$ and $y$ is defined as $max(px, py) bmod min(px, py)$.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedy
CF 2082E - Quaternary Matrix

We are given a matrix where each cell contains a number between 0 and 3. The task is to transform this matrix into what the problem calls a "good" matrix. A matrix is good if the XOR of all elements in every row is zero and the XOR of all elements in every column is zero.

codeforcescompetitive-programmingbitmasksgreedy
CF 2082D - Balancing

The only thing that matters about the original array is the sign of every adjacent comparison. For each position $i$, define an edge between $ai$ and $a{i+1}$. If $ai < a{i+1}$, call the edge positive. If $ai a{i+1}$, call the edge negative.

codeforcescompetitive-programminggreedy
CF 2082B - Floor or Ceil

We start with an integer value and must perform two kinds of halving operations a fixed number of times. One operation replaces the current value with the floor of half the value. The other replaces it with the ceiling of half the value.

codeforcescompetitive-programmingbrute-forcegreedy
CF 2082C - Math Division

We are given a positive integer in binary representation, and the task is to compute the expected number of operations needed to reduce this number to 1.

codeforcescompetitive-programmingbitmasksdpmathprobabilities
CF 2078G - Another Folding Strip

We are given an array of integers representing darkness levels for a strip of paper, and we have a peculiar operation: we can fold the strip any number of times, drop black dye at one position, and then unfold.

codeforcescompetitive-programmingcombinatoricsdata-structuresdivide-and-conquergreedy
CF 2078F - Binary Subsequence Value Sum

We are working with a binary string that changes over time through flip operations. After every flip, we consider all non-empty subsequences of the current string. Each subsequence is assigned a score based on how it can be split into two parts.

codeforcescompetitive-programmingcombinatoricsdata-structuresdpfftmathmatrices
CF 2078E - Finding OR Sum

We are given two hidden non-negative integers, x and y, each less than $2^{30}$. Our goal is to determine the sum of bitwise ORs $(m mid x) + (m mid y)$ for a given integer m.

codeforcescompetitive-programmingbitmasksimplementationinteractivemath
CF 2078D - Scammy Game Ad

We have two lanes. Each lane starts with exactly one person. The level consists of n rounds. In each round there is a left gate and a right gate. A gate either adds a fixed number of people or multiplies the number of people currently in its lane.

codeforcescompetitive-programmingdpgreedyimplementation
CF 2078C - Breach of Faith

We are given a sequence of integers of length 2n+1 that satisfies a special alternating sum property: the first element equals the sum of the remaining elements taken with alternating signs, specifically a1 = a2 - a3 + a4 - a5 + ... + a2n - a2n+1.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathprobabilitiessortings
CF 2078B - Vicious Labyrinth

We are given a labyrinth with $n$ cells arranged linearly, where cell $i$ is $n-i$ kilometers away from the exit at cell $n$. Each cell initially contains one person.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedyimplementationmath
CF 2067F - Bitwise Slides

We are given an array of integers, and three variables P, Q, R initially set to zero. For each element of the array, we must choose to XOR it into exactly one of the three variables. The main restriction is that at every step, the three variables cannot all be distinct.

codeforcescompetitive-programmingbitmasksdata-structuresdp
CF 2067G - Tropical Season

We are given a collection of barrels, each containing some amount of water, and one of them has a tiny amount of poison. The poison adds an imperceptible 0.179 kilograms to the barrel's weight.

codeforcescompetitive-programmingdata-structures
CF 2067E - White Magic

Working

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 2067B - Two Large Bags

We start with an array of n numbers in the first bag and an empty second bag. Since the final bags must be identical, each bag must end up containing exactly n/2 numbers. There are only two allowed operations.

codeforcescompetitive-programmingbrute-forcedpgreedysortings
CF 2067D - Object Identification

We are given an array x of length n with integers from 1 to n, and a hidden array y of the same length. Each pair (xi, yi) is unique and xi ≠ yi.

codeforcescompetitive-programmingconstructive-algorithmsgraphsinteractive
CF 2047F - For the Emperor!

We have a directed graph of cities. City i initially contains ai messengers. A messenger can move along directed roads. If a messenger already knows the plan, he can carry it while travelling.

codeforcescompetitive-programmingflowsgraphs
CF 2047E - Adventurers

We are given a set of cities represented by their coordinates on a 2D plane. Four merchants want to split the cities among themselves using a single dividing point $(x0, y0)$.

codeforcescompetitive-programmingbinary-searchdata-structuresflowsgreedyimplementation
CF 2047A - Alyona and a Square Jigsaw Puzzle

Alyona builds a square puzzle layer by layer around a central piece. The first layer consists of only the center piece, so it contains 1 tile. Every later layer forms a complete square ring around the previous puzzle. Each day she adds some number of pieces, given by the array a.

codeforcescompetitive-programmingimplementationmath
CF 2047D - Move Back at a Cost

We are given an array of integers and allowed to perform a single type of operation any number of times. The operation lets us select an element, increase it by one, and then move it to the end of the array.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedysortings
CF 2047B - Replace Character

We are given a string of lowercase English letters, and we can perform exactly one operation: choose two positions, possibly the same, and set the first character equal to the second.

codeforcescompetitive-programmingbrute-forcecombinatoricsgreedystrings
CF 2047C - Swap Columns and Find a Path

We are given a 2-row matrix with n columns, where each cell contains an integer. We are allowed to swap entire columns any number of times, meaning both elements in a column move together.

codeforcescompetitive-programmingdata-structuresgreedysortings
Kvant Math Problem 1563

For $n=0$, the condition is

kvantmathematicsolympiad
CF 2027D2 - The Endspeaker (Hard Version)

We are working with two sequences that interact through a kind of “resource budgeting” process. The first sequence, a, represents a list of tasks we must completely remove by repeatedly cutting off prefixes.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedyimplementationtwo-pointers
CF 2027B - Stalin Sort

We are asked to determine how many elements must be removed from an array to make it vulnerable. A vulnerable array is one that can be made non-increasing by repeatedly applying Stalin Sort on any of its subarrays.

codeforcescompetitive-programmingbrute-forcegreedy
CF 2027D1 - The Endspeaker (Easy Version)

We have an array a that must be removed completely. At any moment we are at some index k in array b, starting from k = 1. For the current value b[k], we may repeatedly remove a non-empty prefix of the remaining array whose sum is at most b[k]. Every such removal costs m - k.

codeforcescompetitive-programmingbinary-searchdpgraphsgreedyimplementationtwo-pointers
CF 2027C - Add Zeros

We are given an array of integers, and we can perform a specific operation repeatedly to extend its length. The operation allows us to choose a position i in the array (not the first element) such that the value at that position equals the array’s current size minus i plus one.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similardpgraphsgreedy
CF 2025C - New Game

The game revolves around a deck of cards, each labeled with an integer. Monocarp can start by taking any card. On subsequent turns, he can only take a card that either has the same number as the last card taken or is exactly one greater.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedyimplementationsortingstwo-pointers
CF 2025F - Choose Your Queries

For a polynomial $f$ of degree $n$, define $Fk(x)=sum{j=0}^{k}f(x+j).$ The dependence on $k$ is described by Faulhaber's formulas.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardpgraphsgreedytrees
CF 2024F - Many Games

Each game has a success probability $pi/100$ and a reward $wi$. We may choose any subset of games. The catch is that we receive the reward only if every chosen game is won. If even one chosen game is lost, the final reward becomes zero.

codeforcescompetitive-programmingdpmath
CF 2024E - C+K+S

We are given two directed graphs, each with the same number of vertices, and we are asked to add exactly one edge from each outgoing vertex to an incoming vertex in the other graph.

codeforcescompetitive-programmingconstructive-algorithmsgraphshashingstrings
CF 2024D - Skipping

We are given a process that starts from problem 1 and moves through problems in a very unusual way. At each problem, we either submit it or skip it. Submitting gives us points and forces the next problem to be chosen only from strictly smaller indices than the current one.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdivide-and-conquerdpflowsgraphsgreedyimplementationshortest-paths
Kvant Math Problem 1554

Consider a triangle $ABC$ with outward squares $ABMN$, $BCKL$, and $ACPQ$ constructed on its sides.

kvantmathematicsolympiad
CF 2024B - Buying Lemonade

We have a vending machine with n hidden slots, each containing a known number of lemonade cans. There are also n buttons, each mapped to exactly one slot, but the mappings are lost.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmssortings
CF 2024C - Concatenation of Arrays

We are given several test cases, and each test case consists of a collection of pairs. Each pair behaves like a tiny block of length two, and we are allowed to reorder these blocks arbitrarily. After choosing an order, we concatenate all blocks into one long array of length $2n$.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 2019C - Cards Partition

We are given a collection of cards, where each card has an integer written on it. For each number from 1 to $n$, we know exactly how many cards of that type we initially possess. In addition, we have $k$ coins, and each coin allows us to buy a card of any type we choose.

codeforcescompetitive-programminggreedyimplementationmath
CF 2019E - Tree Pruning

We are given a sorted list of integer coordinates on a line. From every pair of these points, we draw a closed segment, meaning every integer point between the endpoints is included in that segment.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardpsortingstrees
CF 2019F - Max Plus Min Plus Size

We are given an array of positive integers, and we are allowed to mark some of them as "red" under the constraint that no two adjacent elements can both be red.

codeforcescompetitive-programmingdata-structuresdpdsugreedysortings
Kvant Math Problem 1553

I cannot produce a mathematical solution to Kvant M1553 because the problem statement itself is missing.

kvantmathematicsolympiad
Kvant Math Problem 1552

The polynomial $P_n(x)=1+x+\cdots+x^{n-1}$ satisfies

kvantmathematicsolympiad
CF 2019D - Speedbreaker

We have a row of $n$ cities, each with a deadline $ai$. You pick one city to start conquering at time 1, and each subsequent time step you expand to an adjacent unconquered city. The goal is to conquer every city $i$ at or before time $ai$.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedymath
CF 2007D - Iris and Game on the Tree

We are given a tree rooted at vertex 1 where each node contains either a 0, 1, or an undecided value represented as ?.

codeforcescompetitive-programminggamesgraphsgreedytrees
CF 2007C - Dora and C++

We are given an array of integers and two fixed step sizes, $a$ and $b$. We can repeatedly pick any position and add either $a$ or $b$ to that element any number of times.

codeforcescompetitive-programmingmathnumber-theory
CF 2007F - Eri and Expanded Sets

For every subarray, we throw all of its values into a set, removing duplicates. Starting from that set, we may repeatedly pick two distinct elements whose average is an integer and add that average if it is not already present.

codeforcescompetitive-programmingbinary-searchdata-structuresnumber-theorytwo-pointers
CF 2007E - Iris and the Tree

We are given a rooted tree with vertex 1 as the root. Each non-root vertex $i$ has a parent $pi$ and an unknown non-negative weight $ti$ on its connecting edge. The sum of all weights is $w$.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similarmathtrees
CF 2004B - Game with Doors

We are given a one-dimensional line of 100 rooms, connected consecutively by 99 doors. Each door can either be open or locked, and movement is only possible through open doors between adjacent rooms.

codeforcescompetitive-programmingbrute-forcegreedy
CF 2004C - Splitting Items

We are given a list of items with integer costs, and two players, Alice and Bob, take turns picking items starting with Alice. After all items are taken, the score is the total cost Alice collected minus the total cost Bob collected.

codeforcescompetitive-programminggamesgreedysortings
CF 2004G - Substring Compression

We are given a digit string. For every substring of length exactly k, we must compute the minimum possible length after performing one compression operation.

codeforcescompetitive-programmingdata-structuresdpmatrices
CF 2004F - Make a Palindrome

Working

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresgreedymath
CF 2004A - Closest Point

We are given a set of integer points on a one-dimensional line. The distance between two points is their absolute difference.

codeforcescompetitive-programmingimplementationmath
CF 2000H - Ksyusha and the Loaded Set

We are maintaining a dynamic set of integers drawn from a bounded universe up to about two million. Elements can be inserted and removed, and after each modification we may be asked a query about the structure of the “holes” in the set.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresimplementation
CF 2000D - Right Left Wrong

We have a line of cells. Each cell contains a positive value a[i] and a character, either L or R. An operation chooses a pair of positions (l, r) with l < r, where position l currently contains L and position r currently contains R.

codeforcescompetitive-programminggreedyimplementationtwo-pointers
CF 2000G - Call During the Journey

We are working on a weighted undirected graph where each edge has two travel modes. Walking is always available and slower, while a bus ride is faster but only usable outside a fixed time interval during the day.

codeforcescompetitive-programmingbinary-searchbrute-forcegraphsgreedyshortest-paths
CF 2000B - Seating in a Bus

We have a bus with n seats in a single row, numbered from 1 to n. Passengers board one by one, and each chooses a seat according to a simple rule: the first passenger can sit anywhere, but any subsequent passenger must sit adjacent to an already occupied seat.

codeforcescompetitive-programmingtwo-pointers
CF 1994G - Minecraft

We are given a fixed array of integers and a target value, and we are allowed to choose a single non-negative integer x. The operation applied to the array is simple: we XOR every element of the array with x, then sum the results.

codeforcescompetitive-programmingbitmasksbrute-forcedpgraphsmath
CF 1994H - Fortnite

The first problem asks whether an infinite sequence of perfect squares $(an^2)$ can exist such that each term starting from the third satisfies the Fibonacci-type recurrence $an^2 = a{n-1}^2 + a{n-2}^2.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsgamesgreedyhashinginteractivemathnumber-theorystrings
CF 1994F - Stardew Valley

Codeforces 1994F: Stardew Valley

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphstrees
CF 1994E - Wooden Game

We are given several independent forests, where each forest consists of multiple rooted trees. Every tree has a fixed root at vertex 1, and each vertex defines a natural subtree consisting of itself and all descendants in this rooted structure.

codeforcescompetitive-programmingbitmasksgreedymathtrees
CF 1994B - Fun Game

We are given two binary sequences of equal length, s and t. Vanya can perform a specific operation on s repeatedly: he chooses a contiguous subarray from position l to r, and for each position i in that subarray, replaces s[i] with s[i] XOR s[i - l + 1].

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedymath
CF 1994A - Diverse Game

We are given a grid that already contains every integer from 1 to $n cdot m$ exactly once, arranged in some arbitrary order. The task is to construct another grid of the same dimensions using the same set of numbers such that no number stays in its original cell.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1994D - Funny Game

We are asked to construct a connected graph on $n$ vertices, starting from an empty graph, by performing $n-1$ operations. Each operation is numbered from 1 to $n-1$.

codeforcescompetitive-programmingconstructive-algorithmsdsugraphsgreedymathnumber-theorytrees
CF 1994C - Hungry Games

We are given a row of values, and we want to count how many contiguous segments behave “well” under a very specific simulation rule. When we pick a segment $[l, r]$, we process its elements from left to right, maintaining a running sum $g$.

codeforcescompetitive-programmingbinary-searchdptwo-pointers
CF 1987G2 - Spinning Round (Hard Version)

We are given a permutation of integers from 1 to $n$ and a string of instructions of length $n$, where each instruction is either L, R, or ?. Each position in the permutation can either connect to its nearest larger number to the left (L) or to the right (R), and ?

codeforcescompetitive-programmingdivide-and-conquerdptrees
CF 1987H - Fumo Temple

We are asked to find a hidden cell in a rectangular matrix of size $n times m$, where each cell contains either -1, 0, or 1.

codeforcescompetitive-programminginteractive
CF 1987G1 - Spinning Round (Easy Version)

We are given a permutation p of length n and a string s of the same length consisting only of ?. Each position i in the permutation defines two special indices: li is the last index before i where the permutation value is larger, and ri is the first index after i where the…

codeforcescompetitive-programmingdivide-and-conquerdptrees
CF 1987B - K-Sort

We are given an array of integers representing a sequence of numbers that we want to make non-decreasing. The only operation allowed is to choose a set of k indices and increment each of those selected elements by one, paying k + 1 coins for the operation.

codeforcescompetitive-programminggreedy
CF 1987D - World is Mine

We have a two-player game between Alice and Bob played over a set of cakes, each with an integer tastiness. Alice goes first.

codeforcescompetitive-programmingdpgames
CF 1987F2 - Interesting Problem (Hard Version)

We are given an array of integers where each element lies between 1 and the array's length. The operation we can perform requires finding an index i such that the value at that position equals i. When we do, we remove both a[i] and the following element a[i+1] from the array.

codeforcescompetitive-programmingdp
CF 1987F1 - Interesting Problem (Easy Version)

We are given an array of integers of length $n$. At each step, we can choose an index $i$ where $ai = i$ and $i < n$, and remove both $ai$ and $a{i+1}$. The goal is to maximize the number of times we can perform this operation until no more valid indices exist.

codeforcescompetitive-programmingdp
CF 1987A - Upload More RAM

We are asked to determine the minimum time required to upload a certain amount of RAM, measured in gigabytes. You can upload either 0 or 1 GB per second, but there is a constraint on the network: in any consecutive block of $k$ seconds, the total upload cannot exceed 1 GB.

codeforcescompetitive-programminggreedymath
CF 1972E - Fenwick Tree

The problem asks us to reverse-engineer a Fenwick tree, or binary indexed tree, operation. A Fenwick tree s is derived from an array a by summing a specific range for each index k.

codeforcescompetitive-programmingcombinatoricsdata-structuresmathmatrices
CF 1972C - Permutation Counting

We are given a multiset of cards, each labeled with an integer from 1 to $n$, and for each type $i$ we know how many cards $ai$ we already own. We also have $k$ coins to buy additional cards, and the shop has unlimited supply of each type.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedyimplementationmathsortings
CF 1972F - Long Way to be Non-decreasing

Connection interrupted. Waiting for the complete answer

codeforcescompetitive-programmingbinary-searchdfs-and-similargraphsimplementation
CF 1972B - Coin Games

We are given a circular arrangement of coins. Each coin is either facing up or facing down. Two players alternate turns, and on each turn a player must pick one coin that is currently facing up, remove it, and then flip its two neighbors.

codeforcescompetitive-programminggames
Kvant Math Problem 1527

We shall prove that the only integer $n>3$ for which a configuration of points $A_1,\dots,A_n$ and real numbers $r_1,\dots,r_n$ satisfying the problem conditions exists is

kvantmathematicsolympiad
CF 1972D2 - Reverse Card (Hard Version)

We are asked to count ordered pairs of positive integers (a, b) such that 1 ≤ a ≤ n and 1 ≤ b ≤ m, with an additional divisibility condition: b gcd(a, b) must be divisible by a + b.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1972D1 - Reverse Card (Easy Version)

We are asked to count how many ordered pairs of integers $(a, b)$ satisfy a divisibility condition under bounded ranges. For each test case, we are given two limits $n$ and $m$.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1966F - Missing Subarray Sum

We are asked to reconstruct a hidden array of positive integers that is a palindrome, given nearly all of its subarray sums. Each subarray sum corresponds to the sum of a contiguous segment of the array, and exactly one subarray sum is missing.

codeforcescompetitive-programmingconstructive-algorithms
CF 1966D - Missing Subsequence Sum

The task is to construct a small sequence of non-negative integers such that every sum from 1 to $n$, except a single forbidden value $k$, can be represented as the sum of some subsequence.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathnumber-theory
CF 1966A - Card Exchange

We are given a hand of cards, each labeled with a number, and a fixed integer $k$. The operation allowed is to take any $k$ identical cards and exchange them for $k-1$ cards of any number we choose. The goal is to reduce the total number of cards as much as possible.

codeforcescompetitive-programmingconstructive-algorithmsgamesgreedy
CF 1966E - Folding Strip

We are given a binary string representing a strip of paper with 0s and 1s. We can fold the strip at any position between adjacent characters.

codeforcescompetitive-programminggreedyimplementation
CF 1966C - Everything Nim

We are asked to analyze a two-player game with multiple piles of stones. On a player's turn, they choose a number $k$ that does not exceed the smallest non-empty pile, then remove $k$ stones from every pile that still has stones.

codeforcescompetitive-programminggamesgreedy
CF 1966B - Rectangle Filling

We are given a grid of size $n times m$ filled with black and white tiles. Each tile is either 'B' (black) or 'W' (white). The task is to determine whether it is possible, using a series of rectangle-filling operations, to make all tiles in the grid the same color.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1944F2 - Counting Is Fun (Hard Version)

We are asked to count arrays of length n with elements between 0 and k that can be reduced to all zeros using a specific operation. The operation allows selecting two distinct indices l and r and subtracting 1 from all elements between l and r inclusive.

codeforcescompetitive-programmingcombinatoricsdp
CF 1944F1 - Counting Is Fun (Easy Version)

We are given an array of length $n$, where each position can independently take any value from $0$ to $k$. So the total universe is all $(k+1)^n$ arrays. The question is not about simulating the process directly.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1944C - MEX Game 1

Alice and Bob play on a multiset of numbers. Alice and Bob alternately remove elements from the array, with Alice moving first. The difference is that whenever Alice removes a value, she also keeps it in her personal array c, while Bob simply deletes a value.

codeforcescompetitive-programmingconstructive-algorithmsgamesgreedy
CF 1944E - Tree Compass

We are asked to color all nodes of a tree black using the fewest operations. Each operation lets us pick a node $v$ and a distance $d$, and it colors all nodes that are exactly distance $d$ from $v$.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargreedytrees
CF 1944B - Equal XOR

This is a Type A problem: find all natural numbers $x$ satisfying a given condition. For a Type A problem, the solution must do two things: 1. Derive necessary conditions and prove that every solution must satisfy them. 2.

codeforcescompetitive-programmingbitmasksconstructive-algorithms
CF 1944D - Non-Palindromic Substring

We are given a string of lowercase English letters and a set of queries, each specifying a contiguous substring of the string. For each query, we are asked to compute the sum of all lengths $k$ for which there exists at least one substring of length $k$ that is not a palindrome.

codeforcescompetitive-programminghashingimplementationstrings
CF 1937F - Bitwise Paradox

We are given two integer arrays, a and b, of length n, along with a fixed integer v. We are asked to process queries of two types. The first type updates a single element in b.

codeforcescompetitive-programmingdata-structurestwo-pointers
CF 1937B - Binary Path

We have a grid with exactly two rows and n columns. Every cell contains either 0 or 1. The path always starts at the top-left cell and ends at the bottom-right cell.

codeforcescompetitive-programmingdpgreedyimplementation