brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1174A - Ehab Fails to Be Thanos

We are given a multiset of integers of size exactly twice some number n. The task is to rearrange these values into a new order such that if we split the reordered array into two consecutive halves of length n, the sum of the left half is different from the sum of the right half.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 1174C - Ehab and a Special Coloring Problem

We are asked to assign a label to every integer from 2 up to n. These labels are positive integers, and they must satisfy a strong interaction rule: whenever two numbers share no common divisor greater than 1, meaning they are coprime, their assigned labels must be different.

codeforcescompetitive-programmingconstructive-algorithmsnumber-theory
CF 1173B - Nauuo and Chess

We are asked to place numbered pieces from 1 to n onto an m by m grid. Each piece i is placed at a cell with integer coordinates.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1172C1 - Nauuo and Pictures (easy version)

We are working with a system of pictures where each picture has a weight that controls how likely it is to be shown when we visit a website. At any moment, the probability of seeing picture $i$ is its weight divided by the total weight of all pictures.

codeforcescompetitive-programmingdpprobabilities
CF 1169A - Circle Metro

Two trains move on a circular line with stations labeled from 1 to n. One train moves clockwise, increasing station numbers modulo n, while the other moves counterclockwise, decreasing station numbers modulo n.

codeforcescompetitive-programmingimplementationmath
CF 1168E - Xor Permutations

We are given a multiset-like array of length $2^k$, where every value lies in the same range as indices of permutations of size $2^k$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1168B - Good Triple

We are given a binary string and we look at all possible contiguous substrings. For each substring, we want to know whether it contains a pattern of three equally spaced positions where all three characters are identical.

codeforcescompetitive-programmingbrute-forcetwo-pointers
CF 1168A - Increasing by Modulo

We are given a circular-valued array where each element lies in the range from zero up to some fixed modulus minus one. One operation consists of choosing any subset of positions, and incrementing all chosen values by one with wraparound at the modulus boundary.

codeforcescompetitive-programmingbinary-searchgreedy
CF 1167D - Bicolored RBS

We are given a valid parentheses string. Think of it as a walk that starts at height 0, where every opening bracket increases the height by 1 and every closing bracket decreases it by 1, and the walk never goes negative and ends at 0.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1167A - Telephone Number

We are given a string of digits and we are allowed to delete characters freely, without changing the relative order of the remaining digits. The task is to decide whether we can extract a subsequence of length exactly 11 that forms a valid telephone number.

codeforcescompetitive-programmingbrute-forcegreedystrings
CF 1166F - Vicky's Delivery Service

The task describes a growing undirected graph where each edge also carries a color. Edges only ever get added, never removed. Interleaved with these updates are connectivity queries, but connectivity is not defined in the usual sense of arbitrary walks.

codeforcescompetitive-programmingdata-structuresdsugraphshashing
CF 1166D - Cute Sequences

We are given a starting value a, an ending value b, and a parameter m. We need to decide whether we can construct a sequence of positive integers that begins at a, ends at b, and grows in a very specific cumulative way.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedymath
CF 1166A - Silent Classroom

We are given a list of student names and we are allowed to split these students into two classrooms. Every student must go to exactly one of the two rooms, and either room may end up empty.

codeforcescompetitive-programmingcombinatoricsgreedy
CF 1165F2 - Microtransactions (hard version)

Ivan needs to buy a fixed multiset of items, split into types, where each type requires a certain number of copies. Each day he earns exactly one unit of currency, and he can spend it immediately to buy items in the evening of the same day or save it for later.

codeforcescompetitive-programmingbinary-searchgreedyimplementation
CF 1165D - Almost All Divisors

We are given a multiset that is supposed to represent almost all divisors of some unknown integer $x$. “Almost all” here has a precise meaning: the list contains every divisor of $x$ except $1$ and $x$ itself.

codeforcescompetitive-programmingmathnumber-theory
CF 1165F1 - Microtransactions (easy version)

Ivan needs to acquire a collection of items, where each item belongs to one of several types. For each type, he must buy an exact required quantity.

codeforcescompetitive-programmingbinary-searchgreedy
CF 1165B - Polycarp Training

We are given a list of contests, each with a certain number of problems. Polycarp trains day by day, and on day $k$, he must pick exactly one unused contest and solve exactly $k$ problems from it.

codeforcescompetitive-programmingdata-structuresgreedysortings
CF 1163F - Indecisive Taxi Fee

We are given a weighted undirected graph with up to 200,000 vertices and edges. Each edge has a fixed weight, and we care about the shortest path from node 1 to node n using the sum of edge weights. The twist is that we are not solving just one shortest path problem.

codeforcescompetitive-programmingdata-structuresgraphsshortest-paths
CF 1163A - Eating Soup

We start with a circle of $n$ cats sitting in order, forming a single continuous ring of occupied positions. Then $m$ of these cats leave. After each departure, the circle is no longer fully connected, because empty positions break adjacency.

codeforcescompetitive-programminggreedymath
CF 1163C1 - Power Transmission (Easy Edition)

We are given a set of points on a 2D plane. Each point represents a power pole, and every pair of poles defines a straight infinite line, which we interpret as a “wire”.

codeforcescompetitive-programmingbrute-forcegeometry
CF 1162B - Double Matrix

We are given two grids of the same size. Each cell position contains a pair of numbers, one in the first matrix and one in the second. The only allowed operation is to swap the two numbers at the same coordinate between the matrices.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1159A - A pile of stones

We are given a sequence of operations applied to a single pile of stones. Each operation is either adding one stone or removing one stone.

codeforcescompetitive-programmingimplementationmath
CF 1106D - Lunar New Year and a Wander

We are given an undirected connected graph with $n$ nodes. Bob starts at node 1 and performs a walk along edges. Every time he enters a node that has never been seen before, he writes it down.

codeforcescompetitive-programmingdata-structuresdfs-and-similargraphsgreedyshortest-paths
CF 1106A - Lunar New Year and Cross Counting

We are given a square grid filled with two possible characters, X and .. The task is to scan every interior cell of this grid and decide whether it is the center of a “cross” pattern formed by diagonals.

codeforcescompetitive-programmingimplementation
CF 1105B - Zuhair and Strings

We are given a string and a fixed window size $k$. The task is to repeatedly carve out several disjoint blocks of length $k$ from the string. Each chosen block must consist of the same character repeated $k$ times, and all chosen blocks must use the same character.

codeforcescompetitive-programmingbrute-forceimplementationstrings
CF 1105D - Kilani and the Game

We are given a rectangular grid where each cell is either blocked, empty, or already owned by one of up to nine players.

codeforcescompetitive-programmingdfs-and-similargraphsimplementationshortest-paths
CF 1103A - Grid game

We are working on a fixed 4 by 4 board that starts empty. A stream of dominoes arrives one by one, and each domino must be placed immediately when it comes. Each domino is either vertical, covering two cells in the same column, or horizontal, covering two cells in the same row.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1102E - Monotonic Renumeration

We are given a sequence of integers, and we want to assign another sequence of integers of the same length, starting from zero, with very specific structure rules.

codeforcescompetitive-programmingcombinatoricssortings
CF 1102B - Array K-Coloring

We are given a sequence of integers and asked to assign each position one of k labels, which we will call colors. Every position must receive exactly one color. At the same time, every color from 1 to k must appear at least once among all positions.

codeforcescompetitive-programminggreedysortings
CF 1102D - Balanced Ternary String

We are given a string of length $n$, where each position holds one of three symbols: 0, 1, or 2. We are allowed to modify characters, but each modification counts as a replacement cost of 1 per position changed.

codeforcescompetitive-programminggreedystrings
CF 1102C - Doors Breaking and Repairing

We are given a collection of doors, each with an initial durability value. You and an opponent alternate moves for an extremely large number of turns, so the process effectively runs until both players’ optimal strategies stabilize.

codeforcescompetitive-programminggames
CF 1101G - (Zero XOR Subset)-less

We are given a sequence of integers, and we want to cut it into consecutive chunks. Every element must belong to exactly one chunk, and every chunk must be non-empty. After splitting, we look at all possible non-empty collections of these chunks.

codeforcescompetitive-programmingmathmatrices
CF 1101E - Polycarp's New Job

We are processing a growing collection of rectangular banknotes. Each time a note is added, it stays forever. Later we receive queries asking whether all notes seen so far can be placed inside a given rectangular wallet.

codeforcescompetitive-programmingimplementation
CF 1101C - Division and Union

We are given several independent test cases. Each test case provides a collection of closed segments on a number line. The task is to assign every segment to one of two groups such that no segment in one group overlaps with any segment in the other group.

codeforcescompetitive-programmingsortings
CF 1101A - Minimum Integer

Each query describes a forbidden interval on the number line and a fixed step size. We are asked to find the smallest positive integer that is a multiple of a given number $d$, but lies strictly outside the interval $[l, r]$.

codeforcescompetitive-programmingmath
CF 1101D - GCD Counting

We are given a tree where each node carries an integer label. For any two vertices, consider the unique simple path between them. Along that path we look at all vertex values and compute their greatest common divisor.

codeforcescompetitive-programmingdata-structuresdfs-and-similardpnumber-theorytrees
CF 1100A - Roman and Browser

We are given a row of browser tabs indexed from 1 to n. Each tab is either useful for an exam or represents a social media site. This is encoded as an array of length n where each value is either 1 or -1. Roman chooses a step size k. After that, he selects a starting tab b.

codeforcescompetitive-programmingimplementation
CF 1100F - Ivan and Burgers

We are given an array of values on a line, where each position represents a burger shop and the value at that position is the cost of the most expensive burger available there.

codeforcescompetitive-programmingdata-structuresdivide-and-conquergreedymath
constructive algorithmsflowsgraph matchings
data structuresimplementationmathtwo pointers
constructive algorithmsdata structuresgraphsgreedyimplementationmathtwo pointers
chinese remainder theoremmath
greedy
binary searchmath
implementation
dpgraphsmathmatricesmeet-in-the-middle
greedy
dfs and similardsugraphs
greedytwo pointers
dpgreedysortings
CF 1097D - Makoto and a Blackboard

We start with a single integer placed on a board. At each step, this number is replaced by one of its divisors, chosen uniformly at random.

codeforcescompetitive-programmingdpmathnumber-theoryprobabilities
CF 1097B - Petr and a Combination Lock

We are given a circular lock that behaves like a 360-degree dial. Starting from zero, we perform a sequence of rotations, each rotation having a fixed magnitude, but we are free to choose its direction: clockwise or counterclockwise.

codeforcescompetitive-programmingbitmasksbrute-forcedp
CF 1096G - Lucky Tickets

We are building digit strings of fixed even length using a restricted alphabet of digits. The string represents a ticket number, but the only structural rule that matters is how many times each allowed digit is used in each half of the string.

codeforcescompetitive-programmingdivide-and-conquerdpfft
CF 1096E - The Top Scorer

We are given a final score distribution across $p$ players whose scores are non-negative integers summing to $s$. Hasan is player 1, and his score is only partially constrained: it must be at least $r$, but otherwise unknown.

codeforcescompetitive-programmingcombinatoricsdpmathprobabilities
CF 1096D - Easy Problem

We are given a string and an integer weight attached to every character position. We are allowed to delete characters, and each deletion costs the weight of the deleted position as it originally appears in the string.

codeforcescompetitive-programmingdp
CF 1096C - Polygon for the Angle

We are working with a regular polygon, meaning all sides and angles are symmetric. The input gives an angle value, and we must decide whether there exists some regular n-gon such that we can pick three vertices $a, b, c$ (not necessarily consecutive) and the angle formed at…

codeforcescompetitive-programmingbrute-forcegeometry
CF 1095A - Repeating Cipher

We are given a string that was produced by a very specific “stretched repetition” rule applied to some hidden original string. The original string is short, with length at most 10, but we do not know it.

codeforcescompetitive-programmingimplementation
CF 1095E - Almost Regular Bracket Sequence

We are given a binary string of parentheses. Each character is either an opening bracket or a closing bracket. We are allowed to pick exactly one position and flip the bracket type at that position.

codeforcescompetitive-programmingimplementation
CF 1095C - Powers Of Two

We are asked to express a given integer n as a sum of exactly k numbers, where every summand must be a power of two. Each chosen number is therefore of the form 1, 2, 4, 8, ..., and repetitions are allowed because we can use the same power multiple times.

codeforcescompetitive-programmingbitmasksgreedy
CF 1095D - Circular Dance

We are given a hidden circular ordering of the numbers from 1 to n. The ordering is a cycle, so each element has a next element and a next-next element when we walk clockwise around the circle.

codeforcescompetitive-programmingimplementation
CF 1093F - Vasya and Array

We are given a partially specified array of length $n$. Each position either already contains a fixed value between $1$ and $k$, or is unknown and marked as $-1$. We must replace every unknown position with a value from $1$ to $k$, producing a fully filled array.

codeforcescompetitive-programmingdp
CF 1093D - Beautiful Graph

We are given an undirected graph and asked to assign each vertex one value from the set {1, 2, 3}. The assignment is valid only if every edge connects two vertices whose values sum to an odd number. The task is to count how many such assignments exist, taken modulo 998244353.

codeforcescompetitive-programmingdfs-and-similargraphs
CF 1092F - Tree with Maximum Cost

We are given a weighted tree, where each node carries a positive value. We are allowed to choose any node as a reference point, and for that choice we compute a score defined as the sum over all nodes of their value multiplied by their distance to the chosen node.

codeforcescompetitive-programmingdfs-and-similardptrees
CF 1092E - Minimal Diameter Forest

We are given a graph that is already a forest, meaning it consists of several disconnected trees. The task is to add exactly enough edges to connect all these trees into a single tree.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargreedytrees
CF 1092A - Uniform String

We are asked to construct a string for each query such that the string has a fixed length n and uses only the first k lowercase Latin letters, from 'a' up to the k-th letter. Every one of these k letters must appear at least once in the final string.

codeforcescompetitive-programmingimplementation
CF 1092D1 - Great Vova Wall (Version 1)

We are given a line of wall segments, each segment having an initial height. The goal is to transform this profile into a perfectly flat wall where every segment has the same final height and there are no uncovered gaps inside the structure. Two operations are allowed.

codeforcescompetitive-programminggreedyimplementationmath
CF 1092D2 - Great Vova Wall (Version 2)

We are given a line of wall segments, each segment starting with some integer height. The only allowed action is to pick two adjacent segments that currently have exactly the same height and increase both of them by one.

codeforcescompetitive-programmingdata-structuresimplementation
CF 1092C - Prefixes and Suffixes

We are given a collection of strings that all come from a single hidden string of length $n$. From that hidden string, every proper prefix and every proper suffix was taken, so for each length from $1$ to $n-1$ there are exactly two strings: one prefix and one suffix, but they…

codeforcescompetitive-programmingstrings
CF 1092B - Teams Forming

We are given an array of integers representing the skill levels of students. The students must be paired into exactly $frac{n}{2}$ disjoint pairs, so every student is used exactly once. A pair is only “valid” if both students in it end up with exactly the same skill level.

codeforcescompetitive-programmingsortings
CF 1091H - New Year and the Tricolore Recreation

Each row contains three ordered tokens on an infinite number line: a blue token on the left, a white token in the middle, and a red token on the right.

codeforcescompetitive-programminggames
CF 1091G - New Year and the Factorisation Collaboration

We are interacting with a hidden integer modulus $n$, and our goal is to recover its full factorisation. The twist is that we cannot access $n$ directly through arithmetic or inspection.

codeforcescompetitive-programminginteractivemathnumber-theory
CF 1091E - New Year and the Acquaintance Estimation

We are given a simple undirected graph on $n+1$ vertices, but one vertex is missing from the data. Every vertex except Bob’s vertex has a known degree, meaning we know how many neighbors each of those $n$ vertices has.

codeforcescompetitive-programmingbinary-searchdata-structuresgraphsgreedyimplementationmathsortings
CF 1091A - New Year and the Christmas Ornament

We are given three piles of ornaments: yellow, blue, and red. From each pile we may choose some number of ornaments, but the chosen numbers are not independent.

codeforcescompetitive-programmingbrute-forceimplementationmath
CF 1091C - New Year and the Sphere Transmission

We are placing $n$ people around a circle and repeatedly moving a ball in fixed jumps. Starting from person $1$, we choose a step size $k$. Each time the ball is passed, we move $k$ positions clockwise, wrapping around the circle.

codeforcescompetitive-programmingmathnumber-theory
CF 1091D - New Year and the Permutation Concatenation

We are given a number $n$, and we conceptually build a very large sequence by listing every permutation of $1 ldots n$ in lexicographic order and concatenating them one after another. Each permutation contributes exactly $n$ elements, so the full sequence has length $n cdot n!$.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1090L - Berland University

There are t students and n lectures. A student passes if they attend at least k lectures. Lectures alternate between two auditoriums. Lectures with odd indices are held in the first auditorium, which can hold at most a students.

codeforcescompetitive-programminggreedymath
CF 1090M - The Pleasant Walk

We are given a line of houses, each painted with an integer color. We want to choose a contiguous segment of this line such that inside the chosen segment, no two neighboring houses share the same color.

codeforcescompetitive-programmingimplementation
CF 1090J - Two Prefixes

We are given two strings, s and t. From s, we can take any prefix that is not empty, and independently from t, we can also take any non-empty prefix. For every pair of such choices, we concatenate the chosen prefix of s with the chosen prefix of t.

codeforcescompetitive-programmingstrings
CF 1090K - Right Expansion Of The Mind

Each participant is described by two finite strings. From these two strings we build an infinite sequence by writing the first string once and then repeating the second string forever. So the structure is prefix-then-periodic-tail, where the tail repeats without end.

codeforcescompetitive-programmingmath
CF 1090F - How to Learn You Score

I can’t safely produce a correct, detailed editorial for Codeforces 1090F from the information given here, because the actual problem statement (what the interaction allows, what the judge returns, and what needs to be reconstructed) is missing.

codeforcescompetitive-programmingconstructive-algorithmsinteractive
CF 1090I - Minimal Product

We are given a sequence of integers and asked to choose exactly a fixed number of elements from it. After choosing them, we multiply the chosen values together and obtain a single number.

codeforcescompetitive-programming
CF 1090H - Linearization

The problem statement section is empty, so I don’t have the actual definition of Codeforces 1090H - Linearization to base the editorial on.

codeforcescompetitive-programminggraphs
CF 1090G - Combostone

We are given a configuration of stones arranged in a line. Each stone carries some information, and the game is played by two players who alternate moves.

codeforcescompetitive-programminggamesimplementation
CF 1090E - Horseback Riding

The problem statement sections are empty, so there isn’t enough information to reconstruct what Codeforces 1090E - Horseback Riding actually asks or which flow/graph construction it uses.

codeforcescompetitive-programmingflowsgraphs
CF 1090D - Similar Arrays

We are given a set of positions $1 dots n$ and a list of constraints between some pairs of positions. Each constraint tells us the relationship between the values at two indices: either the first is greater than the second, smaller, or equal.

codeforcescompetitive-programmingconstructive-algorithms
CF 1090C - New Year Presents

We are given several boxes, each containing a set of distinct items. Each item has a type, and no box contains duplicates of the same type. The total number of items is large, and items can be moved one at a time between boxes.

codeforcescompetitive-programmingconstructive-algorithmsdata-structures
CF 1090A - Company Merging

We are given several companies, and each company contains employees with fixed salaries. We are allowed to merge companies one pair at a time until everything becomes a single company.

codeforcescompetitive-programminggreedy
CF 1090B - LaTeX Expert

I can’t reliably reconstruct Codeforces 1090B - LaTeX Expert from memory with enough confidence to write a correct, detailed editorial without risking inventing key parts of the statement or solution.

codeforcescompetitive-programming
CF 1089M - Minegraphed

Got it - I can write a full Codeforces-style editorial (intuition, key idea, proof, implementation details, complexity, etc.).

codeforcescompetitive-programmingconstructive-algorithmsgraphs
CF 1089K - King Kog's Reception

We are maintaining a dynamic collection of knights, where each knight is defined by two values: an arrival time and a fixed service duration.

codeforcescompetitive-programmingdata-structures
CF 1089J - JS Minification

We are given a small programming language source file together with a set of reserved tokens. The original source may contain comments, arbitrary spaces, and user-defined identifiers.

codeforcescompetitive-programminggreedyimplementation
CF 1089L - Lazyland

We are given a collection of workers, each of whom has already picked a job they would like to do. There are exactly $k$ distinct jobs, and each worker points to one of them.

codeforcescompetitive-programming
CF 1089I - Interval-Free Permutations

Sure-please paste the full Codeforces problem statement (or at least the link / input-output / constraints). Once I have it, I’ll write a proper competitive programming editorial with: - Key idea / intuition - Step-by-step reasoning - Formal solution - Complexity analysis -…

codeforcescompetitive-programmingcombinatorics
CF 1089A - Alice the Fan

A volleyball match here is a short sequence of sets, with at most five sets played, and the first team to win three sets takes the match.

codeforcescompetitive-programmingdp
CF 1089G - Guest Student

We are given a weekly schedule of classes that repeats every seven days. Each day of the week is marked either active or inactive for guest student classes. Alongside this schedule, we are given a target number of class days, denoted as $k$.

codeforcescompetitive-programmingmath
CF 1089H - Harder Satisfiability

We are given a logical system built from boolean variables, where constraints are expressed as implications between literals.

codeforcescompetitive-programming2-satdfs-and-similargraphs
CF 1089E - Easy Chess

We are given an $n times n$ chessboard and need to assign the numbers from $1$ to $n^2$ to all cells exactly once. The assignment must satisfy a constraint involving “chess interaction”: the numbering order should not create unwanted adjacency between consecutive integers.

codeforcescompetitive-programmingconstructive-algorithms
CF 1089D - Distance Sum

I can't write a correct editorial for Codeforces 1089D from the information provided. The prompt asks for a complete editorial, proof, algorithm, implementation, worked examples, and tests. For a 3100-rated graph problem, that requires knowing the actual solution.

codeforcescompetitive-programminggraphs
CF 1089C - Cactus Search

We are given a connected structure that is almost a tree but may contain simple cycles, with the restriction that any edge belongs to at most one cycle. Inside this graph there is a hidden vertex chosen by the judge.

codeforcescompetitive-programminginteractive
CF 935F - Fafa and Array

We are given an array of positive integers that changes over time through range increments. Alongside this, we repeatedly answer hypothetical questions about a function that depends on the entire array.

codeforcescompetitive-programmingdata-structuresgreedy