brain

tamnd's digital brain — notes, problems, research

41513 notes

CF 105006F - Walk in the Park

Each dog-walking job can be seen as an item that Alice may choose at most once. A job comes with two pieces of information: a 7-day requirement pattern and a payment value. The pattern is a length-7 binary vector indicating on which days of the week the dog must be walked.

codeforcescompetitive-programming
CF 105006E - Colorful Corgis

We are given a circular arrangement of $N$ corgis. Each corgi carries a very small “color set”, either one color or two colors, both represented by lowercase letters. The circle means that the first and last corgi are also adjacent.

codeforcescompetitive-programming
CF 105006D - Dog

We are given a rooted tree with node 1 acting as the root of a “proof structure”. Each node represents a subgoal, and leaves are the only things that can be removed during a verification step.

codeforcescompetitive-programming
CF 105006C - The Corgi Genes

We are given a single string representing a long sequence of genetic markers, where each character is one of 26 possible letters. Our task is to count how many substrings are “valid palindromic gene segments” under an additional biological constraint.

codeforcescompetitive-programming
CF 105007B - Corgi Hike

We are given a one-dimensional terrain described by an array of elevations. Each index represents a location along a path, and each location has a height value.

codeforcescompetitive-programming
CF 105007H - Favorite Treat

We are given a tree with $N$ nodes, where each node represents a treat with a fixed tastiness value. Two players, Bob and Charlie, repeatedly remove two leaves from the current tree. For each chosen pair of leaves, Charlie picks one to eat and Bob gets the other.

codeforcescompetitive-programming
CF 105007G - The Great Escape

The park is a huge grid where you start at the bottom-left corner and want to reach the top-right corner. Movement is not explicitly constrained, but geometrically the only thing that matters is whether there exists a continuous path from start to exit that avoids all…

codeforcescompetitive-programming
CF 105007F - Walk in the Park

Each friend brings a potential job. A job is defined by two things: the set of days in a fixed 7-day week when Alice must walk that friend’s dog, and the payment for completing that job for the whole week.

codeforcescompetitive-programming
CF 105007E - Colorful Corgis

We are given a circular arrangement of corgis, where each corgi has a small label describing its fur colors. Each label is either a single color or a pair of colors. We want to partition this circle into contiguous segments.

codeforcescompetitive-programming
CF 105007D - Dog

We are given a rooted tree with node 1 acting as a special root representing the final goal, while every other node represents a subgoal derived from it.

codeforcescompetitive-programming
CF 105007A - Finding Bo

The grid describes a dog park laid out as a rectangle of cells. Each cell is either empty, marked by a dot, or contains a single digit from 1 to 9 representing a dog’s height at that position.

codeforcescompetitive-programming
CF 105007C - The Corgi Genes

We are given a single string of length up to 50,000 consisting of lowercase English letters. Each position represents a gene base, and we are asked to examine every contiguous substring and count those substrings that satisfy two conditions at the same time.

codeforcescompetitive-programming
CF 105009C - Balanced Difference

We are given a list of numbers and we must split it into two groups that do not overlap and together contain every element. Each group must contain at least two elements.

codeforcescompetitive-programming
CF 105009A - TriNum Array

We are given a sequence of integers laid out in a single line, and we are asked to find a contiguous segment of this sequence that uses at most three distinct values, while being as long as possible. Think of the array as a timeline of trades in Numerica.

codeforcescompetitive-programming
CF 105009L - Modulo Queries

We are given a fixed array of integers and many independent range queries. Each query picks a contiguous segment from index $l$ to $r$, and a modulus value $x$.

codeforcescompetitive-programming
CF 105009K - Counting Pairs

We start from a single state described by an ordered pair of positive integers, initially (1, 1). Each move changes the state in a very structured way: either the first component absorbs the second, or the second absorbs the first.

codeforcescompetitive-programming
CF 105009J - CRP Game

We are given a sequence of length $N$ containing only values $0,1,2,3$. All elements start on board $A$, and we must move them to board $B$ by repeatedly taking the front of $A$ and appending it to $B$.

codeforcescompetitive-programming
CF 105009I - Hori and Cake

We are given a collection of line segments on a number line. The key structural constraint is that any two segments are either disjoint or one fully contains the other.

codeforcescompetitive-programming
CF 105009H - Cheating the Group System

There are many students, but only a relatively small number of them are explicitly connected by “must-stay-together” relationships. These relationships form an undirected graph over students.

codeforcescompetitive-programming
CF 105009G - Soccer League

We are given a summary of a football team’s season. Each team is described by five numbers: how many matches they won, drew, and lost, and the total goals they scored and conceded across all matches.

codeforcescompetitive-programming
CF 105009F - Farmer John's Cities

We are given a directed weighted graph representing a road network between cities. From a fixed starting city $s$, we want to reach a target city $t$. The graph already contains $M$ roads, and additionally there are $K$ optional roads.

codeforcescompetitive-programming
CF 105009E - Gardening is Hard

We are given an $n times n$ grid where each cell represents one of three terrain types: usable planting land, a water source, or unusable blocked land. We are asked to count how many horizontal strips of height exactly two rows are “valid gardening strips”.

codeforcescompetitive-programming
CF 105009D - Producing Digits

Each test case gives two arrays of the same length. You process positions from left to right. At position i, you start with the value a[i] and are allowed to optionally multiply it by any subset of the earlier values a[1] ... a[i-1].

codeforcescompetitive-programming
CF 105009B - Two Way Homework

We are given two sequences of the same length. At each position we must pick exactly one value, either from the first sequence or from the second, and sum up all chosen values.

codeforcescompetitive-programming
CF 105010I - Inclusion and Diversity

Each candidate can be represented purely by which of the $m$ minority groups they belong to. So every applicant corresponds to a subset of a set of size $m$, and the pool contains all $2^m$ possible subsets.

codeforcescompetitive-programming
CF 105011A - Треугольники

We are given a multiset of positive integers. From this set we want to count how many integers $x$ have the following property: if we take $x$ together with any two numbers from the given set, those three values can always form a non-degenerate triangle.

codeforcescompetitive-programming
CF 105011D - Путешествие миньонов

We are given a sequence of cities in a fixed travel order from 1 to n. Each city has a value a[i], and a parameter c that affects one of the scoring modes.

codeforcescompetitive-programming
CF 105011B - Взлом сейфа

We are given an initial string and a target string of the same length. The only allowed operation takes a parameter $x$, splits the string into a prefix of length $n-x$ and a suffix of length $x$, reverses that suffix, and moves it to the front, leaving the prefix behind it…

codeforcescompetitive-programming
CF 105011C - Шестиугольный рисунок

We are given a set of selected cells on an infinite hexagonal grid. Each cell has integer coordinates, and adjacency is defined by sharing a full edge. The grid has the additional geometric property that every grid vertex is incident to exactly three cells.

codeforcescompetitive-programming
CF 105012M - Methodical Mixing

We start with an array that is initially a permutation of length $n$, specifically $[1,2,dots,n]$. A sequence of $m$ operations is applied in order. Each operation first swaps two positions $xp$ and $yp$, then performs a cyclic right rotation of the entire array.

codeforcescompetitive-programming
CF 105012L - Legendary Gyrating Mill

We are given a set of points in the plane, with the guarantee that no three lie on a single line. We imagine a process that starts from one point together with a directed line passing through it.

codeforcescompetitive-programming
CF 105012K - Kickball

We are simulating a group of people moving on an infinite integer grid. Each person appears at a given time, starts at a fixed coordinate, and initially faces north. Time advances in discrete minutes, and every active person performs two actions in a fixed order each minute.

codeforcescompetitive-programming
CF 105012J - Jovial Jaunt

We are given a tree with values on its vertices. A player chooses any two vertices as endpoints of a simple path and walks along the unique path between them. The score of a path is not a simple sum or maximum.

codeforcescompetitive-programming
CF 105012I - Interesting Constructive

We are given a rectangular grid where every cell starts uncolored. We must output an order in which to color all cells exactly once.

codeforcescompetitive-programming
CF 105012H - Haphazard Reconstruction

We are working on an $n times n$ grid that starts completely white. We must paint exactly $k$ cells black, but the final pattern must look unchanged after a 90-degree clockwise rotation.

codeforcescompetitive-programming
CF 105012G - GCD Spanning Tree

We are given a complete undirected graph on vertices labeled from 1 to n. Every pair of distinct vertices i and j is connected, and the weight of that edge is defined as gcd(i, j).

codeforcescompetitive-programming
CF 105012E - Ezra and Experiments

We are given a rooted tree with vertex 1 as the root. Each vertex has a value called “aliveness”, which is defined recursively from the leaves upward. For any vertex, we first compute a quantity $S$, which is the sum of aliveness of all its children plus one extra unit.

codeforcescompetitive-programming
CF 105012F - Funky Finding

We are given two integers $x$ and $y$, and instead of comparing them in the usual increasing order of natural numbers, we compare them in a very specific permutation of the positive integers called the Sharkovskii ordering. This ordering is constructed in layers.

codeforcescompetitive-programming
CF 105012D - Deviously Disorganized Documents

We are given an array that represents a permutation-like document of essays, where position and value both matter. The value at index i is the label of the essay currently placed there.

codeforcescompetitive-programming
CF 105012A - An X-Camp Transformer Game

We are given two integer arrays of equal length. The first array is a starting configuration, and the second array is the target configuration. We are allowed to perform a sequence of exactly n operations, where each operation is defined by choosing an index i.

codeforcescompetitive-programming
CF 105012B - Big Data

We are given a binary array and a second array that describes target segment sizes. If we take the binary array and compress it into maximal runs of equal values, we get a sequence of block lengths. For example, a sequence like 1 1 0 0 0 1 becomes blocks of lengths [2, 3, 1].

codeforcescompetitive-programming
CF 105012C - Crazy Dance

We are given $n$ independent dancers placed somewhere on an integer line. Each dancer starts at some integer coordinate, and then simultaneously moves one step either left or right, each direction chosen independently with probability $1/2$.

codeforcescompetitive-programming
CF 105013L - 聪明的小高

There are four players, and each player holds exactly two cards. Each card has a rank and a suit. In every game, each player ultimately plays exactly one of their two cards in the first round, and the remaining cards form the second round. The play proceeds in two tricks.

codeforcescompetitive-programming
CF 105013K - Going to Find Your Love

The task can be understood as a shortest path problem on a directed weighted graph, but with an extra layer of state tracking. Each node in the graph can be visited multiple times depending on how many special “bad” nodes have been passed so far.

codeforcescompetitive-programming
CF 105013I - YiYi and Her Unsorted Array

We are given an array where some positions are “locked” in the sense that elements at those indices are fixed barriers. These locked indices split the array into consecutive regions.

codeforcescompetitive-programming
CF 105013H - 石头剪刀布

We are given two players, each of whom distributes a fixed number of Rock, Paper, and Scissors tokens. One player has counts for Rock, Paper, and Scissors, and the other player has their own counts of the same three types.

codeforcescompetitive-programming
CF 105013B - Infinite Binary String

We are maintaining an infinite binary string indexed by positive integers. Initially, every position behaves as if it contains a zero, and then we are allowed to repeatedly overwrite segments of this infinite string.

codeforcescompetitive-programming
CF 105013A - 破晓狂想曲

We are given multiple queries, each query provides two positive integers, which we can think of as the dimensions of a rectangle grid or two independent ranges.

codeforcescompetitive-programming
CF 105013C - 猫狗大战

We are given a number of test cases. For each test case, we receive a string of length $n$. The task is to transform the string in a very specific way and decide which of three fixed outputs it matches after processing. The processing rule is simple but strict.

codeforcescompetitive-programming
CF 105017M - Mean Absolute Deviation

We are given an array of real numbers and many range queries. For each query, we take the subarray defined by its endpoints, compute its arithmetic mean, and then measure how far the elements deviate from this mean using the average of absolute differences.

codeforcescompetitive-programming
CF 105017K - Count the squares

We are given a grid formed by unit squares, with height $N$ and width $M$. Inside this grid, we want to count how many axis-aligned squares exist, considering all possible sizes.

codeforcescompetitive-programming
CF 105017L - Two Shortest Paths

Working

codeforcescompetitive-programming
CF 105017J - Journey Through Time

We are given a tree where each node represents a moment in time, and each node carries a non-negative damage value. A subset of nodes is marked as special, and we must start from node 1 and eventually visit all of these special nodes in any order.

codeforcescompetitive-programming
CF 105017G - Game of Cards

Two players start with two equal-sized collections of numbers. These numbers are not directly compared; instead, they are gradually “decomposed” during a game.

codeforcescompetitive-programming
CF 105017I - Non-Increasing Dilemma

We are given an array of integers and an operation that aggressively reshapes it. In one move, we pick an index i, and then we add a[i] to every other element in the array, leaving a[i] unchanged.

codeforcescompetitive-programming
CF 105017E - Exam

We are given a square grid of size n by n that must be filled with zeros and ones. Each cell represents whether we place a black square (1) or leave it white (0).

codeforcescompetitive-programming
CF 105017D - Decrypting the Password

We are given a long string of decimal digits, and we need to count how many of its contiguous substrings represent numbers divisible by 11 when interpreted as integers.

codeforcescompetitive-programming
CF 105017F - 800

We are given an $N times M$ grid of lowercase letters. We are allowed to repeatedly perform a very specific operation: pick any cell $(i, j)$, choose a positive integer $k$, and copy its character to either $(i-k, j-k)$ or $(i-k, j+k)$, provided those target cells stay inside…

codeforcescompetitive-programming
CF 105017A - Group of Permutations

Working

codeforcescompetitive-programming
CF 105017B - Simulation

We are simulating a very simple random process repeated many times. We start with an array of size $n$, initially all zeros. Then we perform $m$ independent operations, and each operation picks one of the $n$ positions uniformly at random and increments it by one.

codeforcescompetitive-programming
CF 105017C - Co-sortable Strings

We are given two strings of equal length. At every position, we can look at the pair of characters formed by taking one character from the first string and one from the second string.

codeforcescompetitive-programming
CF 105018N - The Volcano And the Dragon Egg

The problem describes a volcanic pit represented as an $n times m$ grid where each cell stores how much higher that point is compared to the magma level at time zero. Cells with value zero are already at magma level, meaning they are submerged immediately.

codeforcescompetitive-programming
CF 105018L - Good Transformations

We are given an integer $m$ and a linear transformation on integer grid points of the form $$T(i, j) = (a i + b j,; c i + d j),$$ where $a, b, c, d$ are integers in the range $[0, m-1]$. The plane is also partitioned into $m times m$ blocks.

codeforcescompetitive-programming
CF 105018M - Colour the Banners

Codeforces 105018M: Colour the Banners

codeforcescompetitive-programming
CF 105018K - Splitting Game

We are given a multiset of positive integers, stored as an array. Two players alternate turns, starting with the first player.

codeforcescompetitive-programming
CF 105018J - Multiplicative Array

We are given an array indexed from 1 to n with a special multiplicative structure, but that structure is not what we directly compute with. Instead, the process repeatedly transforms the array using divisor aggregation.

codeforcescompetitive-programming
CF 105018G - Find The Array

We are asked to construct any integer array such that its prefix sums and suffix sums satisfy four extremal conditions simultaneously. For a chosen array, consider the running prefix sum sequence that starts from zero and accumulates elements from left to right.

codeforcescompetitive-programming
CF 105018H - Balance The sequence

We are given a string that consists only of opening and closing brackets. The string is guaranteed to be “balanced” in the classical sense, meaning it can be turned into a valid arithmetic expression if we insert plus signs and ones between characters.

codeforcescompetitive-programming
CF 105018I - Hall of Faces

We are given a circular arrangement of labeled faces. Each position contains a string label describing the face, and exactly one position is marked with the label "Jaqen", which represents the current position of the traveler.

codeforcescompetitive-programming
CF 105018F - Expected Runtime

We start with a number R = 1 and repeatedly multiply it by uniformly random integers from 0 to n-1. After each multiplication we check whether the current value is divisible by n.

codeforcescompetitive-programming
CF 105018E - Casino II

We are given a long sequence of real numbers between 0 and 1, and a fixed number of rounds $k$. We traverse the sequence from left to right exactly once, and we cut it into $k$ consecutive parts.

codeforcescompetitive-programming
CF 105018D - Casino I

We are playing a repeated interactive betting game against a dealer. In each round, both sides build a score starting from zero by repeatedly drawing random values uniformly from the interval $[0,1]$. On your turn you decide whether to draw another random value or stop.

codeforcescompetitive-programming
CF 105018C - Rooks

We are given an $n times n$ grid and several rooks placed on distinct cells. A rook controls every cell in its row and every cell in its column. A cell is considered “safe” only if no rook shares its row or column. The operation allowed is removing rooks from the board.

codeforcescompetitive-programming
CF 105018A - Antiprefix Function

We are given a binary string and asked to compute, for every prefix ending at position i, how well that prefix can be matched by a previous prefix of the string under a very strict rule. For a fixed position i, we try all possible lengths j from 0 up to i-1.

codeforcescompetitive-programming
CF 105018B - GCD LCM SUM

We are trying to construct two positive integers $a$ and $b$, with $a le b$, under a very specific arithmetic constraint involving their greatest common divisor and least common multiple.

codeforcescompetitive-programming
CF 105020N - How many rectangles?

Each rectangle in the input is fully determined by its bottom-left corner and its top-right corner. Because all rectangles start in the non-negative quadrant, the origin (0, 0) acts as a natural reference point. A query gives a point (x, y).

codeforcescompetitive-programming
CF 105020M - Delivery

We are asked to determine whether a given integer $x$ can be expressed as a sum of a contiguous block of positive integers starting from some $l$ and ending at $r$.

codeforcescompetitive-programming
CF 105020L - Black and White Tree

We are given a rooted tree where each node is painted either black or white. The tree structure defines parent-child relationships with node 1 as the root. For each query node $u$, we look only inside the subtree of $u$, meaning all nodes reachable by moving downward from $u$.

codeforcescompetitive-programming
CF 105020K - Wrong digits

Two long numbers are given as strings, and we are allowed to modify them digit by digit until they become identical. The catch is that digits are not treated as abstract values, but as seven-segment displays made of small “dashes”.

codeforcescompetitive-programming
CF 105020I - Omar and Trees

The problem gives a rooted tree where each node stores an integer value. The tree is fixed, but two operations are performed on it repeatedly. One operation overwrites every node in a chosen subtree with the same value.

codeforcescompetitive-programming
CF 105020J - Hide and Seek

Each test case describes a park with several trees, where each tree has a fixed height. Amr chooses one tree to hide behind. Whether he gets caught depends only on a comparison between his height and the height of that chosen tree.

codeforcescompetitive-programming
CF 105020H - Cookies

We are given several independent scenarios. In each scenario there are $n$ cookies in total, among which $a$ are large. Donia wants to eat some cookies, but she must avoid getting caught. The rule is that after she eats cookies, at least $m$ cookies must still remain uneaten.

codeforcescompetitive-programming
CF 105020G - String Rotation

We are given two strings of equal length. We are allowed to modify characters in the first string freely, but each modification costs one operation. After modifying, we do not compare it directly to the second string.

codeforcescompetitive-programming
CF 105020D - Beautiful decrease

We are given an array of positive integers. The array evolves through a sequence of queries, and each query allows a limited number of identical operations called “beautiful decreases”. A single beautiful decrease works on one contiguous segment of the array.

codeforcescompetitive-programming
CF 105020F - Distinct

We are given a sequence of instructions that transform a single integer variable starting from 1. Each instruction either doubles the current value or halves it using floor division.

codeforcescompetitive-programming
CF 105020E - The Detective Game

Each player in this game maintains a personal list of other players they would vote against if those players were put on trial.

codeforcescompetitive-programming
CF 105020A - Mood

We are given multiple independent scenarios where a person has a fixed amount of money and wants to buy a drink with a known price. For each scenario, we need to determine how much additional money is required so that the available amount is enough to cover the cost.

codeforcescompetitive-programming
CF 105020B - Hungry

We are given a single queue of customers already lined up at a shop. Each customer in the queue requires a known amount of time to be served, and the shop processes them strictly one after another.

codeforcescompetitive-programming
CF 105020C - Ice Coffee

We are given two arrays of integers of the same length. We are allowed to repeatedly transform elements, but only in one direction: each operation replaces a value by its largest proper divisor, meaning the greatest divisor strictly smaller than the number itself.

codeforcescompetitive-programming
CF 105022L - Silver Wolf and IPC (Advanced)

We are given a permutation of size $N$. Then we are given a sequence of $Q$ operations, each operation taking a segment $[l, r]$ and rotating it cyclically to the right by one position. After all $Q$ operations are applied, we obtain a final permutation.

codeforcescompetitive-programming
CF 105022K - Turning Trucks

We are given a vertical stack of trucks, each truck contributing a fixed length segment. Initially, the stack is perfectly aligned on the y-axis starting from the origin, so the head of the top truck ends up at a point whose y-coordinate is the sum of all truck lengths and…

codeforcescompetitive-programming
CF 105022J - Not So Generous Genie

We are given a string consisting only of digits 1 and 2, and we are allowed to modify it using a limited budget of coins.

codeforcescompetitive-programming
CF 105022I - Find Iron Bundle

We are given a tree representing a metro network where every station is connected and there is exactly one simple path between any two stations. Two people matter: Psyduck, who starts at a uniformly chosen station, and Iron Bundle, who is located at some station.

codeforcescompetitive-programming
CF 105022H - One Step Closer To The AK

We are given a binary array that changes over time through two kinds of operations. One operation flips every value in a range, turning zeros into ones and ones into zeros. The other operation asks us to look at a subarray and play a deterministic removal game on it.

codeforcescompetitive-programming
CF 105022G - Just Visiting Relatives

We are given two length-N sequences, and we use them to define an N by N matrix where every entry is formed by multiplying a row weight from the first sequence with a column weight from the second sequence.

codeforcescompetitive-programming
CF 105022F - Sparkle's Stage

We are given a set of trucks placed on a number line, each with a starting position and a constant velocity. Every truck moves in a straight line, and whenever two trucks meet at the same point at the same time, they collide.

codeforcescompetitive-programming
CF 105022E - Distressed Driver

We are given a sequence of scheduled trips, each with a start time and an end time. Chad performs these trips in the given order. The key mechanic is that if a trip starts while he is still busy finishing a previous delayed trip, it does not start on its original time.

codeforcescompetitive-programming
CF 105022D - Air Taxi Game

We are given several independent test cases. In each test case, there is a list of distinct positive integers representing city populations.

codeforcescompetitive-programming
CF 105022C - Car Go or Not Car Go

We are looking at a deterministic process on a directed graph where every city has exactly one outgoing edge defined by doubling the index modulo $N$. Starting from city $1$, the car repeatedly follows this rule, producing a sequence of visited cities.

codeforcescompetitive-programming
CF 105022A - Truck-Kun

We are given a complete directed graph on up to 300 vertices, where every ordered pair of vertices has a weight, which can be positive, zero, or negative.

codeforcescompetitive-programming