brain

tamnd's digital brain — notes, problems, research

41641 notes

CF 104990F - Friends Reunion at the Park

We are given a tree, which is a connected graph with no cycles, where every edge represents a path of equal length one. Each query gives us three distinct starting nodes, representing the initial positions of three people inside this tree.

codeforcescompetitive-programming
CF 104990E - Enchanted Labyrinth

We are given an undirected graph where each vertex represents a chamber in a labyrinth and each edge is a corridor of equal traversal cost. Elisa starts at node 1 and wants to reach any of the designated exit chambers as quickly as possible.

codeforcescompetitive-programming
CF 104990C - Counting Relative Lists

We are asked to count sequences of length $N$, where each element is chosen from the integers $1$ to $M$, and every pair of adjacent elements must be coprime, meaning their greatest common divisor equals 1.

codeforcescompetitive-programming
CF 104990D - Dynamic Park Pricing

We are given a parking duration expressed as hours and minutes, which we first convert into a single total number of minutes. The parking fee is not constant over time.

codeforcescompetitive-programming
CF 104990B - Balindromes

We are given many independent queries. Each query describes an interval on the positive integers, and we must count how many numbers inside that interval have the property that their decimal representation reads the same from left to right and from right to left.

codeforcescompetitive-programming
CF 104990A - Apartment Tycoon

We start with a single apartment that already produces a fixed monthly rental income. Each additional apartment costs a fixed amount of money, and once purchased it immediately contributes the same monthly income as the initial one.

codeforcescompetitive-programming
CF 105002M - Нодные обмены

We are given a row of $n$ numbers. The only allowed operation is swapping two positions if the numbers at those positions share a common divisor greater than 1.

codeforcescompetitive-programming
CF 105002K - Пиратские сундуки

We are given a sequence of chests arranged in a line, each chest carrying a value that can be positive or negative. A player starts before the first chest and has a limited number of tokens.

codeforcescompetitive-programming
CF 105002J - Сколько различных

We are given a multiset of cards, where each card has a number written on it. From these cards, we consider every possible subset of cards. For each subset, we compute how many distinct values appear inside it, then we sum this quantity over all subsets.

codeforcescompetitive-programming
CF 105002L - Монстры

We are given a collection of monsters, and we want to choose some of them to maximize how many we take, under a global limit on total “aggressiveness”. Each monster behaves in a slightly conditional way.

codeforcescompetitive-programming
CF 105002I - Придумай задание

Each test case gives a word, and for that word we need to decide whether it can be seen as an “expanded” version of some shorter string after inserting exactly one character.

codeforcescompetitive-programming
CF 105002H - Table Football

We are given a string made of lowercase Latin letters. Two players alternate turns. On a turn, a player may delete one character from the string, but only if the character is not at either end and its removal does not create two identical adjacent characters.

codeforcescompetitive-programming
CF 105002G - Балда

We are given a grid of size n by m, where each cell contains either a letter or a dot indicating an empty cell. On this grid, we want to determine whether a given word s already appears as a valid “snake” path.

codeforcescompetitive-programming
CF 105002D - Красно-синие фишки

We are working with a 3×3 sliding board where the middle cell is special. Initially, that center cell is empty, and the other eight cells contain chips colored either red or blue.

codeforcescompetitive-programming
CF 105002F - Замени на сумму

Two sequences of numbers are given, and the allowed operation is to repeatedly compress any adjacent pair inside either sequence by replacing it with their sum. Each compression reduces the length of that sequence by one, while preserving the total sum of its elements.

codeforcescompetitive-programming
CF 105002E - МегаПокер

We are given a sequence of cards arranged in a fixed order. Each card carries an integer value between 1 and m. We are allowed to delete any subset of cards, but we cannot reorder the remaining ones.

codeforcescompetitive-programming
CF 105002C - Игра в домино

We are given a valid chain of domino tiles, already placed in order. Each tile has two numbers from 0 to 6. Adjacent tiles in the chain already match on touching ends, so the chain is consistent.

codeforcescompetitive-programming
CF 105002B - Семь чудес

We are given three piles of science cards, each pile corresponding to a different symbol. One pile counts cards of type R, another S, and another T.

codeforcescompetitive-programming
CF 105002A - Ряд из кубиков

We are given a sequence of identical standard dice placed in a straight line on a table. Each die has the usual six faces, and opposite faces always sum to 7. The dice are aligned left to right, touching each other side-by-side, and the table hides the bottom faces of all dice.

codeforcescompetitive-programming
CF 105003E - To Play or Not to Play, That is the Question

We are given a weighted undirected graph of cities connected by roads. Two players start from different sets of cities: Huize controls a set of starting cities, and Jacobo controls another set.

codeforcescompetitive-programming
CF 105003F - Erdős-Straus Conjecture

We are asked to decide whether a pair of positive integers $x, y$ exists such that a fixed rational expression equals a sum of three Egyptian fractions where the third denominator is constrained to be the product $xy$.

codeforcescompetitive-programming
CF 105003B - Beauty

We are given a list of numbers and a fixed number of swap operations. A swap operation means picking any two positions and exchanging their values.

codeforcescompetitive-programming
CF 105003D - Changes

Working

codeforcescompetitive-programming
CF 105003C - Equipartition

Working

codeforcescompetitive-programming
CF 105003A - Debugging Terence Tao's Code

I can’t reliably write a correct editorial for this yet because the actual problem statement is missing. “Codeforces 105003A - Debugging Terence Tao’s Code” is not something I can reconstruct safely from the title alone, and guessing would risk inventing constraints…

codeforcescompetitive-programming
CF 105006H - Favorite Treat

We are given a tree with up to 20 nodes, where each node represents a treat with a fixed tastiness value. Two players repeatedly remove nodes until nothing remains. In each move, Bob first selects any two nodes that are currently leaves in the remaining tree.

codeforcescompetitive-programming
CF 105006G - The Great Escape

We are working inside a rectangular park that can be treated as a continuous 2D plane from the bottom-left corner $(0,0)$ to the top-right corner $(N,M)$. A corgi starts at $(0,0)$ and wants to reach $(N,M)$.

codeforcescompetitive-programming
CF 105006I - Corgi Counting

We are given a collection of corgis, each assigned a 22-bit integer personality value. If we pick any subset of these corgis, every pair inside that subset contributes a “happiness” equal to the bitwise AND of their personalities.

codeforcescompetitive-programming
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 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 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 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