brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1532E - Good Array

We are given an array of integers and we are allowed to remove exactly one element at a time. For each removal, we look at the remaining array and ask a very specific question: does there exist an element that is exactly equal to the sum of all the other elements in that…

codeforcescompetitive-programming*special
CF 1532C - Uniform String

We are building strings under a very specific constraint: each string must use only the first k lowercase Latin letters, and each of those k letters must appear at least once.

codeforcescompetitive-programming*specialimplementation
CF 1532A - A+B (Trial Problem)

We are given a sequence of independent queries. Each query consists of two integers, and for every pair we must compute their arithmetic sum and output it immediately. There is no dependency between test cases.

codeforcescompetitive-programming*special
CF 1532B - Frog Jumping

The frog moves along a straight number line starting from position 0. Its motion is fully deterministic: it alternates between two fixed step sizes.

codeforcescompetitive-programming*specialmath
CF 1520F1 - Guess the K-th Zero (Easy version)

We are given a hidden binary array of length $n$. We cannot see the array directly. Instead, we can ask queries on any interval $[l, r]$, and the system returns the number of ones in that segment.

codeforcescompetitive-programmingbinary-searchinteractive
CF 1520F2 - Guess the K-th Zero (Hard version)

We are dealing with a hidden binary array of length $n$, where each position is either zero or one. The array does not change on its own, but it is modified by our own actions: every time we correctly identify the position of the current $k$-th zero from the left, that…

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresinteractive
CF 1520B - Ordinary Numbers

We are given multiple queries, and each query consists of a single positive integer $n$. For each $n$, we need to count how many numbers in the range from 1 to $n$ have all digits identical in their decimal representation. These “ordinary” numbers have a very rigid structure.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1511F - Chainword

We are building strings of length $m$, but the string itself is not the only object we care about. Along with the string, we also choose two independent ways to split it into consecutive segments. Each segment must correspond exactly to one of the dictionary words.

codeforcescompetitive-programmingbrute-forcedata-structuresdpmatricesstring-suffix-structuresstrings
CF 1511B - GCD Length

We are asked to construct two positive integers, call them $x$ and $y$, such that we fully control three properties at once: how many digits $x$ has, how many digits $y$ has, and how many digits their greatest common divisor has.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 1511D - Min Cost String

We are asked to construct a string of length n using only the first k lowercase Latin letters. Among all possible such strings, we want one that minimizes a specific cost function. The cost is defined over adjacent pairs inside the string.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgraphsgreedystrings
CF 1511A - Review Site

Each test gives a sequence of reviewers arriving one after another. Every reviewer must be sent to one of two identical servers. Each server maintains its own counters of upvotes and downvotes, and these counters influence future decisions only on that same server.

codeforcescompetitive-programminggreedy
CF 1499G - Graph Coloring

We start with a bipartite graph whose edges arrive online. Each edge must eventually be assigned one of two labels, red or blue. For any vertex, we compare how many incident edges are red versus blue, and we pay the absolute difference of these two counts.

codeforcescompetitive-programmingdata-structuresgraphsinteractive
CF 1499F - Diameter Cuts

We are working with a tree where every edge is initially present. We are allowed to remove any subset of edges, which splits the tree into several connected components. Each resulting component is still a tree.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardptrees
CF 1499E - Chaotic Merge

We are given two strings, and we imagine taking substrings from each of them and interleaving their characters while preserving internal order inside each substring.

codeforcescompetitive-programmingcombinatoricsdpmathstrings
CF 1499D - The Number of Pairs

We are asked to count how many ordered pairs of positive integers $(a, b)$ satisfy a single arithmetic constraint that mixes their least common multiple and greatest common divisor.

codeforcescompetitive-programmingdpmathnumber-theory
CF 1499C - Minimum Grid Path

We are constructing a monotone path from the bottom-left corner of a grid to the top-right corner, but the path is not just a simple sequence of unit steps.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedymath
CF 1499B - Binary Removals

We are given a binary string and we are allowed to delete characters, but with a constraint: any deleted positions must not be adjacent in the original string. After deleting some chosen characters, we concatenate the remaining ones and obtain a shorter string.

codeforcescompetitive-programmingbrute-forcedpgreedyimplementation
CF 1491H - Yuezheng Ling and Dynamic Tree

We are given a rooted tree where every node except the root has a parent pointer, so the structure is initially encoded as an array a[i] describing the parent of node i.

codeforcescompetitive-programmingdata-structurestrees
CF 1491I - Ruler Of The Zoo

We are simulating a deterministic elimination process over a queue of animals where each animal has three different strength modes depending on how many consecutive fights it has already won.

codeforcescompetitive-programmingbrute-forcedata-structures
CF 1491G - Switch and Flip

We start with a permutation placed on positions from 1 to n. Each position contains a coin with a label, and every coin also has a direction state, initially all facing up.

codeforcescompetitive-programmingconstructive-algorithmsgraphsmath
CF 1491F - Magnets

We are given a set of magnets, each secretly belonging to one of three types: North, South, or a special “inactive” type that produces no magnetic behavior.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsinteractive
CF 1491B - Minimal Cost

We are given a grid that has a very unusual shape: it has n rows and a very large number of columns, from 0 up to 10^6 + 1. Each row contains exactly one obstacle placed at a given column position a[i]. These obstacles block movement through their cells.

codeforcescompetitive-programmingbrute-forcemath
CF 1491C - Pekora and Trampoline

We are given an array of trampoline strengths arranged in a line. Each trampoline behaves like a forced jump: if Pekora lands on position i, she is immediately launched to i + S[i].

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedyimplementation
CF 1437F - Emotional Fishermen

We are given a multiset of positive integers representing fish weights. We must arrange these values in a permutation, then reveal them one by one. As the sequence unfolds, each revealed value is compared against the maximum value seen so far.

codeforcescompetitive-programmingcombinatoricsdpmathtwo-pointers
CF 1437G - Death DBMS

We maintain a fixed collection of strings, each representing a “name”, and each name has an associated value that changes over time.

codeforcescompetitive-programmingdata-structuresstring-suffix-structuresstringstrees
CF 1437B - Reverse Binary Strings

We are given a binary string where zeros and ones appear in equal quantity, and the length is even. The target configuration is not arbitrary: we want the string to become perfectly alternating, meaning every adjacent pair of characters must differ.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1437A - Marketing Scheme

We are choosing a single pack size a for selling cat food cans. Every customer initially wants to buy some number x within a fixed range [l, r].

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedymath
CF 1411D - Grime Zoo

We are given a binary string where some positions are already fixed as 0 or 1, while others are unknown and written as ?. Each ? must be replaced by either 0 or 1, and this choice determines the final string.

codeforcescompetitive-programmingbrute-forcegreedyimplementationstrings
CF 1411C - Peaceful Rooks

We are given a chessboard where no two rooks initially share a row or a column, so every rook sits in a distinct row and a distinct column.

codeforcescompetitive-programmingdfs-and-similardsugraphs
CF 1404D - Game of Pairs

We are working with a two-player construction game on the numbers from 1 to 2n. One player first partitions these numbers into n disjoint pairs. After that, the second player selects exactly one number from each pair.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similarinteractivemathnumber-theory
CF 1404B - Tree Tag

We are given a tree where two players start on different vertices. Alice moves first. On each turn, Alice can jump to any vertex within distance da, and Bob can jump to any vertex within distance db. Distance is standard shortest path length in the tree.

codeforcescompetitive-programmingdfs-and-similardpgamestrees
CF 1400B - RPG Protagonist

We are given a fixed amount of carrying capacity split between two people, you and your follower. Each test case describes a small “loot selection” problem: there are two types of weapons, swords and war axes, each type having a fixed weight per item and a limited stock in…

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1400A - String Similarity

We are given a binary string s of length 2n - 1. From this string, we look at every contiguous window of length n. There are exactly n such windows, starting at positions 1 through n. Each window represents a candidate string that overlaps heavily with its neighbors.

codeforcescompetitive-programmingconstructive-algorithmsstrings
combinatoricsdpmathnumber theoryprobabilities
*special
math
bitmasksdp
divide and conquerdpgreedyimplementation
bitmaskscombinatoricsdfs and similardpgraphsmathtrees
*specialdfs and similargeometryimplementation
greedymath
implementationstrings
binary searchcombinatoricsdpmath
greedysortingstwo pointers
math
binary searchconstructive algorithmsgreedyimplementation
math
math
greedysortings
implementation
greedyimplementationmath
binary searchbrute forcedata structuresdptwo pointers
data structuresdsugraphstrees
constructive algorithmsdfs and similardsugraphsgreedyimplementationshortest paths
*specialdata structuresgames
brute forcemath
brute forcecombinatoricsmathnumber theory
brute forcedata structuresgreedytwo pointers
combinatoricsgreedymath
combinatoricsdpmath
data structuresimplementationmath
binary searchgreedyimplementation
bitmasksconstructive algorithmsgreedynumber theory
*special
binary searchmath
brute force
gamestwo pointers
bitmasksconstructive algorithmsdfs and similargreedymathtrees
constructive algorithmsdata structuresgreedyimplementation
dfs and similardpgreedytreestwo pointers
greedyimplementation
dfs and similardpgraphstrees
binary searchbitmasksconstructive algorithmsdata structuresmathsortings
binary searchdfs and similargraphsinteractiveshortest pathstrees
implementation
*specialbrute forcedpstrings
dpgames
binary searchbrute forcecombinatoricsimplementationmath
brute forcedp
mathnumber theory
dpgreedy
brute forcedfs and similargraphsmathnumber theory
binary searchconstructive algorithmsdata structuresstringstwo pointers
bitmasksdpstring suffix structures
*special
constructive algorithms
dfs and similargraphsshortest paths
math
greedy
brute forcedpgamesgreedy
data structuresdfs and similargraphsgreedy
implementation
greedyimplementation
mathnumber theoryprobabilities
brute forcedivide and conquergraphsmath
*special
greedymath
brute forcedata structures
greedyimplementationmath