brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1548D2 - Gregor and the Odd Cows (Hard)

We are given a set of points on the plane that act as fixed vertices. From these points, we choose any three distinct points to form a triangle. Inside this triangle lies an infinite integer grid of “cows”, one at every lattice point.

codeforcescompetitive-programmingbrute-forcegeometrymathnumber-theory
CF 1548D1 - Gregor and the Odd Cows (Easy)

We are given a set of points on a plane that serve as possible vertices of a triangle. Every point has even integer coordinates, and no three points are collinear. From these points we choose any triple and form a triangle.

codeforcescompetitive-programmingbitmasksgeometrymathnumber-theory
CF 1548C - The Three Little Pigs

We are looking at a process that lasts for $n$ minutes. Each minute, exactly three new items are added, so after minute $t$, there are $3t$ items available.

codeforcescompetitive-programmingcombinatoricsdpfftmath
CF 1548A - Web of Lies

We are working with a graph whose vertices are fixed nobles numbered from 1 to n, where the label also represents their strength. Edges represent mutual friendships, and these edges change over time through insertions and deletions.

codeforcescompetitive-programmingbrute-forcegraphsgreedy
CF 1547G - How Many Paths?

We are given a directed graph where we start from node 1 and consider all possible directed walks that end at each vertex. A walk can revisit nodes and edges arbitrarily many times.

codeforcescompetitive-programmingdfs-and-similardpgraphstrees
CF 1547E - Air Conditioners

We are given a one-dimensional strip of length $n$. Some positions on this strip contain air conditioners, each fixed at a known coordinate and each producing its own base temperature.

codeforcescompetitive-programmingdata-structuresdpimplementationshortest-pathssortingstwo-pointers
CF 1547D - Co-growing Sequence

We are given a sequence $x1, x2, dots, xn$. Our task is to construct another sequence $y1, y2, dots, yn$ such that when we XOR them elementwise, the resulting sequence $$ai = xi oplus yi$$ has a monotone bit-structure: every bit that is set in $ai$ must also be set in $a{i+1}$.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedy
CF 1547C - Pair Programming

Two programmers are contributing edits to the same file, but their work histories are interleaved in time. We are given two ordered sequences of actions, one for each person. Each action is either an insertion at the end of the file or an edit of an existing line.

codeforcescompetitive-programminggreedytwo-pointers
CF 1547B - Alphabetical Strings

We are given a string and we need to decide whether it could have been constructed by a very specific process that builds strings from left to right choices.

codeforcescompetitive-programminggreedyimplementationstrings
CF 1547A - Shortest Path with Obstacle

We are working on an infinite grid where movement is allowed in four directions: up, down, left, and right, each costing one step. We are given three special cells: a start cell, a target cell, and a forbidden cell that cannot be stepped on.

codeforcescompetitive-programmingimplementationmath
CF 1546B - AquaMoon and Stolen String

We are given a multiset of original strings and a second multiset formed after a disturbance process. The disturbance worked in two stages. First, all strings were paired except one special string that stayed unpaired.

codeforcescompetitive-programminginteractivemath
CF 1546A - AquaMoon and Two Arrays

Two players give us two arrays of equal length. One array can be modified by repeatedly moving a single unit from one position to another position. Each move removes one from index i and adds one to index j, and the array must remain non-negative after every move.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1545E1 - AquaMoon and Time Stop (easy version)

A single person moves deterministically along a number line: starting from position $x$ at time $0$, his position at time $t$ is exactly $x+t$.

codeforcescompetitive-programmingdata-structuresdp
CF 1545E2 - AquaMoon and Time Stop (hard version)

We are given a person who moves deterministically along a number line: starting at position $x$ at time $0$, and then increasing position by exactly one unit per second. So at time $t$, the person is at $x+t$.

codeforcescompetitive-programmingdata-structuresdp
CF 1545C - AquaMoon and Permutations

We are given $2n$ permutations of size $n$. Each row is a rearrangement of numbers $1$ to $n$. We are promised that there exists a hidden structure behind these rows: they originally came from two intertwined Latin squares of size $n$, but then the rows were shuffled.

codeforcescompetitive-programming2-satbrute-forcecombinatoricsconstructive-algorithmsgraph-matchingsgraphs
CF 1545B - AquaMoon and Chess

We are given a binary string of length $n$, where each position either contains a pawn or is empty. The board is a line, and pawns can move only in a very constrained way: a pawn can “jump” two cells left or right, but only if the intermediate cell is occupied and the…

codeforcescompetitive-programmingcombinatoricsmath
CF 1543E - The Final Pursuit

The input describes a graph that is guaranteed to be a permuted hypercube. This means the graph has exactly $2^n$ vertices, every vertex has degree exactly $n$, and the structure is isomorphic to the standard $n$-dimensional hypercube, but the vertex labels have been…

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdivide-and-conquergraphsgreedymath
CF 1543C - Need for Pink Slips

We are repeatedly running a stochastic process that evolves a small probability distribution over three outcomes. At any moment there are up to three “active” slips, one of which is a terminal success state (the pink slip) and the other two are transient states.

codeforcescompetitive-programmingbitmasksbrute-forcedfs-and-similarimplementationmathprobabilities
CF 1543B - Customising the Track

We are given a list of non-negative integers where each value represents how many cars sit on a segment of a road. The “cost” of the whole configuration is defined by comparing every pair of segments and summing the absolute difference of their car counts.

codeforcescompetitive-programmingcombinatoricsgreedymath
CF 1542C - Strange Function

We are given many queries. Each query provides a very large integer $n$, and we consider every integer $i$ from 1 to $n$. For each $i$, we define a function $f(i)$ as the smallest positive integer that fails to divide $i$.

codeforcescompetitive-programmingmathnumber-theory
CF 1538F - Interesting Function

We are effectively watching a number grow from l to r by repeatedly adding one, and we want to measure how “violent” each increment is in terms of decimal digit changes.

codeforcescompetitive-programmingbinary-searchdpmathnumber-theory
CF 1538A - Stone Game

We are given a row of stones, each stone having a distinct strength value. In one move, we are allowed to remove only one of the two boundary stones, either the leftmost or the rightmost remaining stone.

codeforcescompetitive-programmingbrute-forcedpgreedy
CF 1536E - Omkar and Forest

We are given a grid where some cells are forced to be zero and the rest are flexible cells that may take any non-negative integer value.

codeforcescompetitive-programmingcombinatoricsgraphsmathshortest-paths
CF 1536D - Omkar and Medians

We are given a sequence b which is claimed to come from a hidden process involving another array a. The process builds a step by step in odd lengths: at step i, we look at the first 2i-1 elements of a, compute their median, and store it as b[i].

codeforcescompetitive-programmingdata-structuresgreedyimplementation
CF 1536C - Diluc and Kaeya

We are given a binary string made only of the characters D and K. For every prefix of this string, we want to determine how finely we can split that prefix into contiguous pieces such that every piece has the same internal balance between D and K.

codeforcescompetitive-programmingdata-structuresdphashingnumber-theory
CF 1536B - Prinzessin der Verurteilung

We are given a short lowercase string and asked to find a very specific “missing pattern” inside it. The task is to identify the shortest possible string over lowercase letters that does not appear anywhere as a contiguous substring of the given input.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsstrings
CF 1536A - Omkar and Bad Story

We are given a small set of distinct integers and are allowed to add new distinct integers to it. The goal is to build a final set such that it satisfies a very strong closure property: whenever we pick any two numbers from the set, the absolute difference between them must…

codeforcescompetitive-programmingbrute-forceconstructive-algorithms
CF 1533I - Excursions

We can view the situation as a two-layer directed routing process between two bipartite sets of nodes. One set corresponds to sights in Saratov, the other to sights in Engels.

codeforcescompetitive-programming*specialconstructive-algorithmsdfs-and-similarflowsgraph-matchingsgraphs
CF 1533G - Biome Map

We are given a small grid of biome “types”, where each type is identified by a pair of parameters coming from a fixed $n times m$ table. Some of these pairs exist and are assigned a unique integer identifier, while others are unavailable.

codeforcescompetitive-programming*specialconstructive-algorithmsdfs-and-similargraphs
CF 1533H - Submatrices

We are working with a grid of uppercase letters, but the alphabet is extremely small: only the first five letters appear.

codeforcescompetitive-programming*specialbitmasksdata-structuresdp
CF 1533D - String Searching

We are given a fixed collection of strings, all of the same length, and we are asked to answer many queries about a slightly longer string. Each stored string has length $m$. Each query string has length $m+1$.

codeforcescompetitive-programming*specialhashing
CF 1533C - Sweets

We are given a circular arrangement of sweets labeled from 1 to n. Each sweet is either “liked” or “not liked”. Anya performs a deterministic process that removes sweets one by one from the circle. The process has two phases in every test case.

codeforcescompetitive-programming*specialdata-structuresimplementation
CF 1533A - Travel to Bertown

Vika arrives in Bertown on a fixed day $k$. She has several friends, and each friend offers a single continuous interval of days during which she can stay at their home.

codeforcescompetitive-programming*specialimplementationmath
CF 1533B - Nearest Point Function

We are given several test cases, each consisting of a sorted array of distinct integers. Think of these numbers as fixed points on a number line. A query point $y$ is chosen, and a function returns the closest point in the array to $y$ based on absolute distance.

codeforcescompetitive-programming*specialimplementation
CF 1532F - Prefixes and Suffixes

We are given a multiset of strings that all come from a single unknown string of length $n$. For every length $k$ from $1$ to $n-1$, we are given exactly two strings of that length, and each of those two strings is either a prefix or a suffix of the hidden string.

codeforcescompetitive-programming*specialstrings
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
dpfftmath
implementationsortings
binary searchbrute forcedata structuressortingstwo pointers
constructive algorithmsdfs and similargraphstrees
*specialbitmasks
mathnumber theoryprobabilities
combinatoricsdata structuresdp
binary searchdpgeometrygraphs
*special
greedysortings
math
greedymathsortingstwo pointers
binary searchgreedymathsortingsternary search
constructive algorithmsgreedyimplementationmathtwo pointers
combinatoricsfftmath
data structuresgeometrygraphstrees
combinatoricsdpmath
constructive algorithmsgreedyimplementation
geometrymathmatricesnumber theory
data structureshashingstringstwo pointers
brute forcemath
brute forceconstructive algorithms
binary searchbitmasksconstructive algorithmsdata structuresmathsortings
brute forcemath
*special
greedysortings
*special
data structuresdpimplementationtwo pointers
binary searchbrute forcedata structuresdptwo pointers
gamesmathnumber theory
*special
implementationmath