brain

tamnd's digital brain — notes, problems, research

41641 notes

CF 105498F - Make Permutation

We are given an array of integers, and for each element we are allowed to repeatedly turn off any single set bit, but only up to once per bit per element, which is equivalent to saying each number can be reduced to any value obtainable by subtracting a sum of distinct powers…

codeforcescompetitive-programming
CF 105498C - Expected Final Score

We start with a row of $n$ positions, each containing a distinct element. A pointer $p$ is also given, initially somewhere between $0$ and $n$, inclusive. We repeatedly remove elements from the current row until nothing remains.

codeforcescompetitive-programming
CF 105505K - Kool Strings

We are given a binary string and a threshold value $K$. The string is considered “bad” if it contains a run of $K$ or more identical consecutive characters, meaning a block like $0000$ when $K = 4$, or $111$ when $K = 3$.

codeforcescompetitive-programming
CF 105505F - Finding Privacy

We are given a row of $N$ identical toilets, all initially empty. People arrive one after another, and each person must choose a toilet that is currently empty and also has no occupied neighbor on either side.

codeforcescompetitive-programming
CF 105505A - Append and Panic!

We are given a single uppercase string that was produced by a two-step process. First, someone had an original string t. Then they created a second string by taking all distinct letters of t, sorting them alphabetically, and writing each letter once.

codeforcescompetitive-programming
CF 105507A - Покупка велосипеда

We are asked to pay an exact amount using only two coin types, one worth 2 units and the other worth 5 units. The goal is not just to determine whether the sum can be formed, but to construct a combination of coins whose total value is exactly the required amount and uses as…

codeforcescompetitive-programming
CF 105530F - Nice (Hard Version)

We are working with numbers formed from decimal strings, but only two digits actually matter: 6 and 9. A number is considered “nice” if it can be interpreted under a very specific ordering rule that effectively treats these two digits as comparable states, and all other…

codeforcescompetitive-programming
CF 105530A - GCD Sort

We are given a permutation of size $n$, meaning each number from $1$ to $n$ appears exactly once but in arbitrary order across positions $1$ to $n$. The task is to transform this permutation into the sorted order where value $i$ sits at position $i$.

codeforcescompetitive-programming
CF 105535L - Late Autumn Set of Cards

We are given a multiset of positive integers written on cards. From these cards, we may select any subset, and the value of that subset is defined as the product of all selected numbers.

codeforcescompetitive-programming
CF 105535J - Jolly Polygon

We are asked to construct a simple polygon with exactly n vertices placed on integer grid points within a large bounding box.

codeforcescompetitive-programming
CF 105535H - Huh? Oh, Yes, Welcome to the Contest!

The task simulates a fixed registration dialogue for a contest team, where the only variable part is the team name.

codeforcescompetitive-programming
CF 105535F - Fairly Easy Problem

We are given a sequence of fixed points $C1, C2, dots, Cn$ on a plane and a special point $D$. For each $Ci$, we must choose a circle centered at $Ci$, with radius $ri$.

codeforcescompetitive-programming
CF 105535E - Enter the Museum

We are given a connected undirected graph that forms a tree, rooted at room 1. Each room contains a number of exhibits, and the total number of exhibits across all rooms is at most 2 · 10^5. Petya starts at room 1 and must end at room 1.

codeforcescompetitive-programming
CF 105535C - Confusion

We are given a fixed 32-bit unsigned integer $a$. For each test case, we must find all 32-bit unsigned integers $b$ such that two quantities become identical when viewed modulo $2^{32}$: the first quantity is the power $a^b$, computed in the usual mathematical sense, and the…

codeforcescompetitive-programming
CF 105535B - Byte Pair Encoding

We are given a sequence of bytes, each value initially in the range from 0 to 255. The process repeatedly compresses adjacent pairs by repeatedly selecting a specific ordered pair of values and collapsing all its occurrences in one batch operation.

codeforcescompetitive-programming
CF 105536D - Собеседование в Сбер

We are given a sequence of tasks laid out in a line, where each task has an integer difficulty. A character named Vanya has a skill level that starts at a low value and can increase as he completes tasks.

codeforcescompetitive-programming
CF 105536B - Рафаэль и Кейси Джонс

We are given a collection of independent encounters indexed by $i$. For each encounter there are two time costs, $ai$ and $bi$, corresponding to how much work is required if it is handled by two different fighters.

codeforcescompetitive-programming
CF 105544B - Recurring Decimal to Fractions

The problem asks us to evaluate a real number that is given in a mixed decimal form, where part of the decimal expansion does not repeat and another part repeats forever.

codeforcescompetitive-programming
CF 105544M - Task scheduler

Each test case describes a very small scheduling system that receives a list of tasks. Every task has an identifier and a priority value, and the system must decide the order in which tasks are executed.

codeforcescompetitive-programming
CF 105544L - Nine Never

We are asked to split a given number of soldiers into several nonempty groups whose sizes are positive integers summing to $N$.

codeforcescompetitive-programming
CF 105544K - Chemical Storage

We are given a tree describing a network of storage rooms. Each room is a node, and each connection is a railroad. The structure is not arbitrary: it has a strong restriction that every node lies within distance at most two from a single central path.

codeforcescompetitive-programming
CF 105544J - Lead Time Estimation

We are given a production system that can be modeled as a directed acyclic graph of jobs. Each job takes a fixed amount of time to process, and moving from one job to another incurs an additional transfer time.

codeforcescompetitive-programming
CF 105544I - The Pentagon Conjecture

We are given several test cases. Each test case describes an undirected simple graph, but not in the usual edge-list form. Instead, the graph is specified indirectly as a collection of triangles.

codeforcescompetitive-programming
CF 105544H - Bank Deposit Challenge

We are given a fixed amount of cash and a list of bank deposit opportunities. Each opportunity requires spending a specific amount of money to participate, and in return it yields a fixed amount of interest.

codeforcescompetitive-programming
CF 105544G - A Packing Problem

We are given a set of items and a set of boxes. Each box has a fixed capacity $T$. Each item has one of two possible sizes, and these sizes are very “polarized”: every item is either very small (at most $T/4$) or very large (at least $3T/4$).

codeforcescompetitive-programming
CF 105544E - Slabstones Rearrangement

We are given a set of axis-aligned rectangular slabs placed inside a larger rectangular garden. Each slab has a fixed vertical position, meaning its bottom and top y-coordinates are immutable, but we are allowed to shift slabs horizontally left or right.

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