brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 105544D - Quarantine Policy

We are given a grid representing the seating layout of an airplane. Each cell is either empty or contains a virus source.

codeforcescompetitive-programming
CF 105544A - Counterfeit Money

We are given very large decimal numbers, each representing a banknote serial number. A number is considered valid if it is divisible by 13.

codeforcescompetitive-programming
CF 105755H - Heaps of Queries

We are given a deterministic way of building a binary tree-like structure by inserting values from 1 up to n into a skew heap.

codeforcescompetitive-programming
CF 105646M - Balance of Permutation

We are given a permutation of numbers from 1 to n, and we define its “cost” as the total displacement of elements from their natural positions, specifically the sum over all positions i of The task is not only to count or optimize this value, but to enumerate permutations…

codeforcescompetitive-programming
CF 105638H - Kyooma Loves Tree

We are given a complete k-ary tree of fixed depth, meaning every internal node has exactly k children and all leaves lie at the same depth. Each edge in this tree is independently removed with a given probability p (modulo a prime), so each edge either survives or disappears.

codeforcescompetitive-programming
CF 105636C - 树的遍历

We are given a tree, and some subset of its edges is marked as critical. The process is defined on edges rather than vertices: we start from one chosen edge, treat it as “current”, and repeatedly move to an unvisited edge that shares a vertex with the current one.

codeforcescompetitive-programming
CF 105633D - Tree Generators

We are given two expressions that describe how a labeled tree is constructed. Each expression is a binary structure written using a single leaf symbol 1 and a binary concatenation written as parentheses containing two subexpressions written side by side.

codeforcescompetitive-programming
CF 105632A - A + B = C Problem

We are given three positive integers $pA, pB, pC$. Each integer defines the period of an infinite binary string. That means the string is completely determined by its first $p$ bits, and then those bits repeat forever.

codeforcescompetitive-programming
CF 105631H - Hoppers and Doors

We are given a graph that represents a prison-like maze. There is a special starting node where K begins, a set of nodes called hoppers, and another set of nodes called doors. The remaining structure is an undirected graph connecting all nodes.

codeforcescompetitive-programming
CF 105615F - 模四识别

We are given a string of digits and we need to reason about segments of it through the lens of arithmetic modulo 4.

codeforcescompetitive-programming
CF 105588J - Just another Sorting Problem

We are given a permutation and a two-player game played on it. The goal of the game is to transform the permutation into a fully sorted sequence in increasing order.

codeforcescompetitive-programming
CF 105586H - 雪碧喝可乐

We are given a sequence of values over time, each value being either minus one, zero, or plus one. Each value represents the intrinsic “effect” of a bottle bought on that day.

codeforcescompetitive-programming
CF 105583K - Keen Coal Extraction

We are given a mine shaped like a rooted tree of shafts, where shaft 1 sits at the very top and every other shaft has exactly one connection upward that leads to a unique parent. Because of this structure, between any two shafts there is exactly one simple path.

codeforcescompetitive-programming
CF 105755K - Killer Cows

We are given a set of at most 20 cows, each identified by a bit position. Initially all cows are on the left bank of a river, and the goal is to move them all to the right bank.

codeforcescompetitive-programming
CF 105588B - Brackets

We are given a long bracket string s that uses eight bracket symbols, four opening types and their matching closing counterparts. From this string we extract m substrings. Each substring is treated as an independent sequence, and we are allowed to pair some of these substrings.

codeforcescompetitive-programming
CF 105586K - 说重话!!!

We are given a sequence of days, and on each day we want to compute how many “extra hours of effort” accumulate from a set of scheduled contributions. Each contribution starts at some day $x$ and then affects all days from $x$ to the end $n$.

codeforcescompetitive-programming
CF 105583I - Innovative String Conversion

We are given a single string of length $N$ that is currently in state $A$, and we want to transform it into a target state $B$. Each position holds either a lowercase letter or a dot. A dot represents an empty cell.

codeforcescompetitive-programming
CF 105583E - Expression

We are given a hidden arithmetic expression built from the numbers 1 through N, each used exactly once and arranged in some unknown order. Between consecutive numbers there are operators chosen from plus, minus, and multiplication.

codeforcescompetitive-programming
CF 105582J - Jumping Through Hyperspace

We are given a directed complete graph of planets where each ordered pair of planets may or may not have a hyperjump available.

codeforcescompetitive-programming
CF 105580J - Maze

The task is an interactive exploration problem on a hidden rectangular grid of size at most 30 by 30. Each cell in the grid has four potential neighbors in the cardinal directions, so the underlying structure is the full grid graph.

codeforcescompetitive-programming
CF 105579L - Optimal Milk Temperature

We are given a sequence of milk batches, each batch has two attributes. The first is a coefficient $bi$ which represents how much flavor Vova gains per unit of heating temperature.

codeforcescompetitive-programming
CF 105578J - Make Them Believe

We are given a fixed eight-team single-elimination bracket, already arranged in quarterfinal order from top to bottom. Each team has a unique name and a unique integer strength.

codeforcescompetitive-programming
CF 105582E - Expressions of Dice

The task is interactive and is not about computing an answer from a fixed input. Instead, we are gradually building a pool of symbols by repeatedly choosing one of six dice types, rolling it, and observing a randomly returned symbol.

codeforcescompetitive-programming
CF 105581E - Net

We are given a set of points in 3D that form a convex polyhedron. The task is not to reconstruct the polyhedron itself in a combinatorial sense, but to output a planar “net” of it, meaning we must unfold its surface into the plane so that every face becomes a flat polygon in…

codeforcescompetitive-programming
CF 105581K - Magic Chess Piece

We are working on a grid where each cell has a value computed deterministically from its coordinates. That value is taken modulo 4, and it decides how a chess piece behaves when it is currently standing on that cell.

codeforcescompetitive-programming
CF 105580K - Knights

We are given a rooted tree of courtiers where node 1 is the king. Every other node has exactly one parent, so the structure is a rooted tree with edges directed away from the king. We must choose a subset of nodes to be “knights”.

codeforcescompetitive-programming
CF 105579H - The Hard Question

We are given a small system of boys and girls where each boy has a fixed list of girls he is willing to dance with. The process is conceptual rather than simulated: boys go in increasing order, and each boy tries to pick a girl he likes who is still available.

codeforcescompetitive-programming
CF 105579J - Kings' Dominion

We are given positions of several kings placed on a 100 by 100 grid. In one action, we choose a single king and start moving it step by step in any of the eight directions, so every move changes its cell to one of the adjacent squares including diagonals.

codeforcescompetitive-programming
CF 105578I - Growing Tree

A perfect binary tree is being built level by level. After $n$ days, the tree has height $n$, root is node $1$, and every internal node $u$ has two children $2u$ and $2u+1$.

codeforcescompetitive-programming
CF 105578M - Obliviate, Then Reincarnate

We are given an infinite line of rooms indexed by all integers. These rooms are partitioned into $n$ groups according to their value modulo $n$.

codeforcescompetitive-programming
CF 105575E - 安排时间

We are given a schedule planning problem. There are several people, and each person provides one or more time intervals during which they are available. The goal is to determine a single moment in time when the maximum number of people are simultaneously available.

codeforcescompetitive-programming
CF 105570D - Building Gondola (gondola)

We are given a left-to-right sequence of peaks, but their exact heights are not fixed. Instead, each peak has a range of possible heights derived from a noisy vertical photograph.

codeforcescompetitive-programming
CF 105562C - Connect Five

We are given five special intersections on an infinite grid of city blocks. Each block is connected by roads that run strictly horizontally or vertically, and every adjacent pair of intersections along a row or column corresponds to one road segment of equal length.

codeforcescompetitive-programming
CF 105545C - Битый ром

We are working with integers represented in binary, and a simple transformation based on bit counts. For every integer $k$ in a range starting from 1 up to $2^n - 1$, we perform a process that repeatedly replaces the number by the number of set bits in its binary representation.

codeforcescompetitive-programming
CF 105545A - Билли Бонс и монеты

We are given a number written in decimal form, and we need to construct another number that is strictly larger than it while satisfying a digit-wise restriction.

codeforcescompetitive-programming
CF 105400J - Coconut vs Orange

We are given a grid with 3 rows and N columns. Each cell contains either 0 or 1, representing votes for two candidates. We can think of each cell as a unit city with a binary label.

codeforcescompetitive-programming
CF 105400F - Keys Burns Down the House

We are given a line of books, each with a value, and a process that removes books from the ends over time. At every second, two things happen in sequence: first, Keys may take exactly one remaining book from anywhere in the current segment, and then the fire burns the current…

codeforcescompetitive-programming
CF 105323B - 小文的排列

We are given a long sequence $S$ that is constructed in a very specific way. Each operation takes the numbers from $1$ to $m$, randomly permutes them, and appends that permutation to the end of $S$.

codeforcescompetitive-programming
CF 105545M - Детство капитана Флинта

We are given a graph whose vertices represent islands and whose edges represent direct travel routes between pairs of islands. The key structural constraint is that this graph contains no cycles, which means every connected component of the graph is a tree.

codeforcescompetitive-programming
CF 105545L - Мне не нравятся эти матросы!

We are working with an array that changes over time through point updates. After each update, we need to evaluate a global quantity defined over all values that appear in the array. For any value x, we look at all subarrays that do not contain x at all.

codeforcescompetitive-programming
CF 105545K - Нужно больше золота

We are given an undirected graph with a weight on each vertex and a cost function defined on step lengths of a walk.

codeforcescompetitive-programming
CF 105545J - Они заряжают пушку... ЗАЧЕМ?!

We are given two arrays of equal length that represent two competing progress tracks over time. One array describes Jim’s daily gains and the other describes the pirates’ daily gains. What matters is not the raw values themselves but the cumulative difference between them.

codeforcescompetitive-programming
CF 105545H - Путешествие к кладу

We are given a sequence of operations that repeatedly transform an interval of integers. Initially, every integer in a fixed range is considered valid. Each operation shifts the entire current valid range either left or right by a given amount.

codeforcescompetitive-programming
CF 105545G - Любимое число Флинта

We are given a list of integers. The operation we are allowed to perform is to pick exactly two of these numbers, replace them with their sum, and then consider the greatest common divisor of the resulting multiset.

codeforcescompetitive-programming
CF 105545F - Хорошее настроение

We are given an array of integers where we are allowed to select a contiguous segment and flip the sign of every element inside it. After performing this operation, we evaluate the resulting array by its minimum value.

codeforcescompetitive-programming
CF 105545E - Портальные сокровища

We are given an undirected graph that represents locations connected by passages. The task is to determine which parts of this graph remain usable if we repeatedly enter regions where we can explore fully and return to the entry point, but we cannot afford to get stuck in a…

codeforcescompetitive-programming
CF 105545D - Дробитель

We are given a process that repeatedly produces fractions and then combines them. At some point, we end up with a collection of fractions of the form $frac{a1}{b1}, frac{a2}{b2}, dots, frac{ak}{bk}$.

codeforcescompetitive-programming
CF 105545B - Шприцы

We are given a square board of size $n times n$. We are interested in ordered pairs $(a, b)$, where both $a$ and $b$ are integers between $1$ and $n$, and we want to count how many such pairs satisfy a divisibility condition: at least one of the numbers $a$ or $b$ is divisible…

codeforcescompetitive-programming
CF 106456G - Taffy vs Goblins

Each test case describes a fixed battle scenario with N independent attacks. Attack i targets goblin i and either deals full damage Ci or nothing, depending on whether its penetration Ai reaches the goblin’s defense Bi.

codeforcescompetitive-programming
CF 106444B - Emang Harusnya Bet Merah

We are given several independent dice, where each die has its own list of face values. A single operation consists of rolling some of the dice, observing their outcomes, and deciding which dice to keep active for future rolls and which to lock permanently.

codeforcescompetitive-programming
CF 106443L - Linked Letters

We are given a fixed dictionary of distinct words. Between any two words, we define a connection rule that depends only on their letters: two words are considered directly compatible if they share at least one common character.

codeforcescompetitive-programming
CF 106194K - 黄金魔女的谜题

We are given a rooted tree with node 1 fixed as the root. Two players start on two different nodes, Alice on node A and Bob on node B. They move alternately, with Alice starting first.

codeforcescompetitive-programming
CF 106193G - Games of Chess

We are given a connected undirected graph with n nodes, where node i represents both a friend and their home. Each node has exactly one decision to make: it selects a “club” label from 1 to n, and multiple nodes are allowed to pick the same label.

codeforcescompetitive-programming
CF 106192K - Заливка

We are given a complete graph with $n$ vertices. Each vertex initially has a color, and colors are given as integers. The graph structure itself is not really something we need to manipulate explicitly because every pair of vertices is connected.

codeforcescompetitive-programming
CF 106170D - Building A Smooth Playlist

We are given several independent test cases. Each test case describes a collection of music genres, where the i-th genre contains ci distinct songs.

codeforcescompetitive-programming
CF 106167G - Grid Delivery

The city is a rectangular grid of intersections, where each cell may contain a customer parcel that must be picked up. Movement is constrained by one-way streets: from any intersection you can only move either south or east.

codeforcescompetitive-programming
CF 106164D - Dungeons and Dragons

We are building a very large multiset of monster HP values, each value chosen from the range from zero up to some maximum $N$. There are $R$ monsters, and the order of these values matters, so we are effectively dealing with sequences of length $R$.

codeforcescompetitive-programming
CF 106161K - K-Coverage

We are given a rooted tree, and every node carries two values, one from array a and one from array b. Some entries in both arrays may be zero, and zero acts as a wildcard that can match anything.

codeforcescompetitive-programming
CF 106144G - String Transformation

We are given a string and a single allowed operation that modifies it by deleting characters. One operation works by selecting a contiguous segment of the string and also selecting a character, then removing every occurrence of that character inside that segment only.

codeforcescompetitive-programming
CF 106142D - Нужное количество единиц

We are asked to process multiple independent queries. Each query gives an interval $[a, b]$ and a target number $k$. For every integer $x$ in that interval, we convert $x$ into binary without leading zeros and count how many bits are equal to 1.

codeforcescompetitive-programming
CF 106141D - How to Annoy a Turtle

We are given a rectangular grid of size $h times w$. A token starts at the top-left cell $(1,1)$ and wants to reach the bottom-right cell $(h,w)$. Movement is constrained to only go right or down, so every valid path is a monotone path in the grid.

codeforcescompetitive-programming
CF 106136L - Forest Path

We start with a tree on n vertices. Then one extra edge is added between two previously non-adjacent vertices, turning the structure into a single cycle graph with exactly one cycle. We are not directly told which edge was added.

codeforcescompetitive-programming
CF 106084C - One-Way Abyss

Each test case describes a vertical cave system with several shafts. You start at the top of one chosen shaft and move strictly downward. While descending, you may encounter horizontal tunnels placed at distinct depths.

codeforcescompetitive-programming
CF 106082H - Maximum Satisfaction

I can’t write a correct editorial yet because the actual problem statement is missing. Right now all we have is the title “Maximum Satisfaction”, but no description of: what is given in the input, what choices are allowed, what “satisfaction” depends on, or what must…

codeforcescompetitive-programming
CF 106073I - Investigating Quadradômeda

We are given a sequence of points in the plane, representing stars visited in a fixed order. Consecutive stars are always aligned either horizontally or vertically, so each move between star $i$ and star $i+1$ is a straight segment parallel to an axis.

codeforcescompetitive-programming
CF 106072I - DAG Query

We are given the full structure of a directed acyclic graph, but the weights of the edges are unknown. The only way to learn anything about the weights is through an interactive oracle: we choose a pair of vertices $s, t$ and a scalar $c$, and the oracle returns the sum over…

codeforcescompetitive-programming
CF 106068E - Sasha and palindrome

We are given a string $S$ of length at most 40. Think of its characters arranged in a line. We also have an empty string $T$. We repeatedly remove characters from either the left end or the right end of the remaining $S$, and append each removed character to the end of $T$.

codeforcescompetitive-programming
CF 106059G - Graph Orientation

We are given a connected bipartite graph with up to 100 vertices, where each vertex has a positive weight. The task is not just to assign directions arbitrarily to edges, but to orient every edge so that a particular cost function becomes as small as possible.

codeforcescompetitive-programming
CF 106059L - Lantern Festival

The problem is essentially asking us to process a row of lanterns along a riverbank, where each lantern is either on or off. The input gives us a sequence of length n, and each position contains either a 0 meaning the lantern is unlit or a 1 meaning it is glowing.

codeforcescompetitive-programming
CF 106057A - Decreasing Trees

We are counting a very specific family of rooted trees on labeled vertices from 1 to n. The tree is rooted at node 1, and labels behave in a monotone way along any root-to-node path: whenever we move away from the root, labels must strictly increase.

codeforcescompetitive-programming
CF 106030H - str(list(s))

The task revolves around applying a very specific transformation to a single string using Python’s built-in list conversion semantics.

codeforcescompetitive-programming
CF 105928J - k-MEX

We are given a rooted tree with a value written on every vertex. The root is fixed at vertex r. Alongside this tree, we are allowed to repeatedly perform a structural modification that targets a vertex v (different from the root).

codeforcescompetitive-programming
CF 105755D - Drowsy Robots

We are given a line of robots labeled from left to right. Robot $i$ starts at position $x = i$, and all robots begin moving left at time zero.

codeforcescompetitive-programming
CF 105638C - Reborn and SegmentTree

We are given an array and a segment tree that was built over it for range minimum queries. The tree is standard: every node represents a segment of the array, and stores the minimum value on that segment.

codeforcescompetitive-programming
CF 105633H - Remodeling the Dungeon 2

The dungeon is given as a grid where only certain cells are actual rooms. Between neighboring rooms there may be doors embedded in the walls, and these doors define an undirected graph: each room is a node, and each door connects two adjacent rooms.

codeforcescompetitive-programming
CF 105632K - Brotato

A run in this game is a sequence of $n$ levels that must all be cleared in order. At each level, a single attempt either succeeds with probability $1-p$ or fails with probability $p$.

codeforcescompetitive-programming
CF 105632H - The Witness

We are given a rectangular grid where each cell is colored either black or white. The grid is naturally embedded on a vertex lattice: an $n times m$ cell grid corresponds to $(n+1) times (m+1)$ lattice vertices, and moves are allowed only along unit edges between adjacent…

codeforcescompetitive-programming
CF 105631E - Erasing Numbers

We are given a binary sequence written on a board. Each position contains either 0 or 1, and two players play alternately starting from the leftmost turn. Alice is responsible for interacting with zeros, while Bob is responsible for interacting with ones.

codeforcescompetitive-programming
CF 105629I - 倒反天罡

We are given a sequence of cats, each cat having an age and a binary label that represents whether it is believed to be “senior” or “junior”. For a query, we look only at a contiguous segment of cats, and we are allowed to select exactly $k$ cats from that segment.

codeforcescompetitive-programming
CF 105615N - Pentiment - Mark of Submission -

The statement you provided is not actually sufficient to reconstruct a Codeforces problem. What is visible is only the title, a stray “N”, and some formatting artifacts (“Lament Rain”, time/memory limits), but the core definition of the task is missing: there is no…

codeforcescompetitive-programming
CF 105608D - Два шифра

We are given two integers that represent a desired result of some hidden encoding process applied to a string of lowercase Latin letters.

codeforcescompetitive-programming
CF 105592D - Шоколадка

We start with a rectangular chocolate bar of size $n times m$. The final goal is to end up with a square chocolate, but the allowed operation is not free-form cutting.

codeforcescompetitive-programming
CF 105591B - Последовательный треугольник

We are asked whether it is possible to form a triangle whose side lengths are three consecutive natural numbers and whose perimeter equals a given value $p$. A valid triangle in this setting is fully determined by a starting integer $a$.

codeforcescompetitive-programming
CF 105588I - Items

We are given several independent test cases. In each test case, there are $n$ types of items. Each type can be used any number of times, including zero, and every item of type $i$ has a fixed weight $wi$.

codeforcescompetitive-programming
CF 105588E - Extracting Weights

We are given a fixed tree with $n$ nodes. Each node $i$ hides a value $wi$, with the root node $1$ guaranteed to have value $0$. The only way to obtain information is by querying pairs of nodes $(u, v)$.

codeforcescompetitive-programming
CF 105586C - 交通要塞

We are moving along a straight corridor divided into vertical “lanes” indexed from 0 to n + 1. Time is discrete. At each second, you either stay in your current lane or move exactly one lane to the right.

codeforcescompetitive-programming
CF 105586E - 黑塔的奇物

We are asked to arrange $n^2$ items on an $n times n$ grid. Each item has a type from $1$ to $n$, and each type appears exactly $n$ times, so the multiset is perfectly uniform.

codeforcescompetitive-programming
CF 105583D - Delicious Pizza

We are given points on the boundary of a unit circle. Each point is specified by an angle, and these points represent available endpoints for straight cuts inside the circle.

codeforcescompetitive-programming
CF 105583H - Harvest

We are given a tree where each node represents a tree in a plantation and each node initially contains some number of mango batches. Two people operate on this tree: Bob and Alice.

codeforcescompetitive-programming
CF 105582M - Maximum Paths

The structure is a complete binary tree where every node from 2 onward has a parent given by integer division by two. This makes the topology fixed and implicit: node 1 is the root, node 2 and 3 are its children, node 4 to 7 are next level, and so on up to n.

codeforcescompetitive-programming
CF 105582G - Glasses of Solutions

We are given several containers, each containing a liquid solution. For each container we know two values: the total mass of the solution and how much of that mass is salt.

codeforcescompetitive-programming
CF 105582A - Apple

We are given an undirected simple graph with at most 100 vertices and 100 edges. The task is not to “draw” anything geometrically in a computational sense, but to decide whether this graph can be interpreted as a very specific structure called an apple.

codeforcescompetitive-programming
CF 105581C - File Manager

The input describes a directory structure through a list of file paths. Each path represents a file located somewhere inside a hierarchy of directories separated by slashes.

codeforcescompetitive-programming
CF 105581J - Origami

We start with a right isosceles triangular sheet of paper. Think of it as a 45-45-90 triangle. Vitya repeatedly folds this triangle along lines that split it into two congruent parts.

codeforcescompetitive-programming
CF 105580A - Forks

We are given five collections, each collection containing exactly five integers. Each integer describes a fork by the number of tines it has. Two forks are considered identical if their integer labels match. A “set” here is really a multiset of five integers.

codeforcescompetitive-programming
CF 105580E - Millionaire

We maintain an array of bank balances indexed from 1 to N. Initially each account already contains some integer amount, and then we must process a sequence of operations that modify or query this array. There are two update operations and one query operation.

codeforcescompetitive-programming
CF 105579E - Uniform Square Tiling

We are given an $n times n$ grid representing a tiled wall. Each cell contains either a gold tile, written as G, or a silver tile, written as S. We are also given an integer $k$, and we want to choose a contiguous $k times k$ sub-square of this grid.

codeforcescompetitive-programming
CF 105579D - Fibonacci Grouping

We are given a line of $n$ people indexed from 1 to $n$. The process repeatedly forms a group from the current line by selecting all positions whose indices are Fibonacci numbers.

codeforcescompetitive-programming
CF 105578E - Light Up the Grid

We are working with a fixed 2 by 2 binary grid, so every configuration is a 4-bit state. Each operation flips bits in a specific pattern: either one cell, an entire row, an entire column, or all four cells at once.

codeforcescompetitive-programming
CF 105578B - Magical Palette

We are given a grid with $n$ rows and $m$ columns. Before filling the grid, we assign one number to each row and one number to each column. Call the row values $a1 dots an$ and the column values $b1 dots bm$.

codeforcescompetitive-programming