brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 104262F - Plutonian Hot Dog Stand

Let $mathcal{S}(f)$ denote the set of all distinct subfunctions of $f(x1,dots,xn)$ obtained by repeated Shannon decomposition with respect to variables $x1,dots,xn$, as represented in the master profile chart.

codeforcescompetitive-programming
CF 104262H - Plantery Observations

We are maintaining a growing sequence of observations, which can be thought of as a string that starts empty and is extended over time. Each update of the first type appends another string to the end of this global sequence.

codeforcescompetitive-programming
CF 104262G - Path to Pluto

We are given a directed weighted graph with (n) planets and exactly (n-1) roads. Each road has a direction and a travel cost. Planet (1) is special because it represents Pluto, and every planet can reach it through some directed path.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 217

Working

taocpmathematicsalgorithmsvolume-4hard
CF 104262E - Gluing Pluto Back Together

We are given a complete weighted graph on $N$ vertices, where each vertex represents a rock. The cost $C{i,j}$ is the price of directly gluing rock $i$ next to rock $j$.

codeforcescompetitive-programming
CF 104262D - Celestial Sky

We are working on a 2D grid where both stars and black holes are placed at integer coordinates in a small bounded space. Stars represent points we want to count, while black holes invalidate nearby stars.

codeforcescompetitive-programming
CF 104262C - Calibration Complications

The five-letter word pairing scheme in Section 7.2.1.1 relies on masking a packed bitstring so that each mask isolates the lower portion of a word consisting of an integral number of fixed-size letter fields.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 216

An 8×8 chessboard is partitioned into 32 dominoes in a perfect covering.

taocpmathematicsalgorithmsvolume-4hard
CF 104264H - Best

The task gives a single integer and asks us to output another integer based on it. There is no further structure such as arrays, graphs, or multiple queries, so the entire problem reduces to understanding how the output depends on this one value.

codeforcescompetitive-programming
CF 104264F - Online

The five-letter word pairing scheme in Section 7.2.1.1 relies on masking a packed bitstring so that each mask isolates the lower portion of a word consisting of an integral number of fixed-size letter fields.

codeforcescompetitive-programming
CF 104264G - Simple

We are given a single integer $n$ in a very small range up to 2023, and we must produce one integer as output. There are no additional structures like arrays or graphs, so the task is entirely about defining a function $f(n)$ that maps each valid input to a single integer.

codeforcescompetitive-programming
CF 104264E - Permutation

We are given a small sequence of integers, and we are asked to compute a single integer answer derived from its internal structure.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 215

A domino tiling of the $8\times 8$ board assigns to each unit square a partner square so that every square belongs to exactly one $1\times 2$ or $2\times 1$ domino.

taocpmathematicsalgorithmsvolume-4medium
CF 104264D - TheFool

We are given two small integers, row and col, both ranging from 0 to 14, and we must decide whether the point represented by these coordinates is inside a certain region or outside it.

codeforcescompetitive-programming
CF 104264C - Morco

Let $f(x1,x2,x3,x4,x5)$ be a Boolean function and let $B{min}(f)$ denote the minimum, over all variable orderings, of the number of nodes in its reduced ordered binary decision diagram, including the sink nodes $bot$ and $top$.

codeforcescompetitive-programming
CF 104264A - Vowels

We are given a single string consisting only of lowercase English letters. The task is to compute a single integer based on this string, and print it. From the samples, we observe that only certain letters contribute to the answer, while all others contribute nothing.

codeforcescompetitive-programming
CF 104264B - String

I can’t write a correct editorial for that yet because the actual problem statement for “Codeforces 104264B - String” is missing from your prompt.

codeforcescompetitive-programming
CF 104270L - Sub-cycle Graph

We are given a labeled undirected simple graph on $n$ vertices with exactly $m$ edges. The graph is called valid if we can add some additional edges so that the final graph becomes a single simple cycle that visits all $n$ vertices exactly once.

codeforcescompetitive-programming
CF 104270M - Function and Function

We are given a number written in decimal form and a repeated transformation applied to it. The transformation is defined in two layers. First, there is a function that takes a number and replaces it with the sum of a digit-wise score.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 214

Let the chessboard be the standard $8 \times 8$ grid, decomposed into $64$ unit squares.

taocpmathematicsalgorithmsvolume-4medium
CF 104270K - Airdrop

We are given a fixed target height $y0$ and a set of players, each starting at some integer grid point $(xi, yi)$. There is also a hidden parameter $x0$, the x-coordinate of an airdrop position $(x0, y0)$.

codeforcescompetitive-programming
CF 104270J - Books

We are given a sequence of books, each with a fixed price, and a deterministic purchasing process that scans books from left to right. At each book, if the current money is at least the price, the book is bought and the money decreases; otherwise the book is skipped.

codeforcescompetitive-programming
CF 104270I - Soldier Game

We are given an array of soldier powers arranged in a fixed order. The task is to partition this array into contiguous teams, where each team contains either a single element or exactly two adjacent elements.

codeforcescompetitive-programming
CF 104270H - Mirror

We are given a start point and a target point in the plane. At the start, there are multiple identical stones stacked at the start point. The task is to move all stones to the target point, but they must be transported one by one.

codeforcescompetitive-programming
CF 104270G - Repair the Artwork

We are given a line of $n$ cells, each cell being in one of three states. Some cells are already empty, some contain DreamGrid’s own fixed pattern that must never be touched, and some contain BaoBao’s pattern that must be removed.

codeforcescompetitive-programming
CF 104270F - Tournament

We are asked to construct a multi-round tournament schedule among $n$ knights, where each round pairs up all knights into disjoint duels.

codeforcescompetitive-programming
CF 104270D - Magic Multiplication

We are given the length of two unknown positive integers A and B, and a strange string C that is produced by multiplying them under a non-standard operation. The operation does not behave like normal multiplication.

codeforcescompetitive-programming
CF 104270E - Plants vs. Zombies

We are given a line of plants indexed from 1 to n. Each plant i has a fixed position i and a growth rate a[i]. Initially every plant has zero defense value. A robot starts at position 0, which is the “house”.

codeforcescompetitive-programming
CF 104270B - Kawa Exam

We are given an array of length $n$, where each position represents the correct answer to a multiple-choice question. Each question has an assigned correct choice, and BaoBao can pick exactly one choice per question.

codeforcescompetitive-programming
CF 104270C - Flippy Sequence

We are given two binary strings of equal length. Think of them as two rows of switches, each position holding either 0 or 1. We are allowed to perform exactly two operations, and each operation chooses a contiguous segment and flips every bit inside that segment.

codeforcescompetitive-programming
CF 104270A - Sequence and Sequence

We are given two tightly coupled sequences. The first sequence, P, is fully deterministic and grows in a structured way: the value 1 appears twice, 2 appears three times, 3 appears four times, and so on.

codeforcescompetitive-programming
CF 104273F - Устный счет

We are given a long arithmetic expression written in the usual infix form. It consists of non-negative integers combined with addition and multiplication, and an equality to a final integer value.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 213

Let the ZDD represent a family $\mathcal{F}$ of subsets of ${x_1,\dots,x_n}$, ordered by the variable indices, and let each node $k$ be labeled by $V(k)\in{1,\dots,n}$.

taocpmathematicsalgorithmsvolume-4medium
CF 104273E - Быстрый исполнитель

I can’t write a correct editorial for this yet because the problem statement for Codeforces 104273E - “Быстрый исполнитель” is missing from your prompt.

codeforcescompetitive-programming
CF 104273A - Code Plagiarism

We are given two strings built from lowercase letters. Think of the first string as a long tape of characters produced by Bob, and the second string as the shorter string Alice believes should remain after Bob’s modifications.

codeforcescompetitive-programming
CF 104273D - Перекладывание ответственности

The problem statement for Codeforces 104273D (“Перекладывание ответственности”) is not included in your message, so I don’t have enough information to reconstruct the task reliably.

codeforcescompetitive-programming
CF 104273B - SpamGPT-4

Two automated bots are sending messages to each other on a strict schedule. Both bots always send a message at time zero, and then continue sending messages periodically: the first bot sends at times 0, a, 2a, 3a, and so on, while the second sends at times 0, b, 2b, 3b, and so…

codeforcescompetitive-programming
CF 104273C - Есть n стульев...

I can’t reliably write a correct editorial for this yet because the actual problem statement is missing. “104273C - Есть n стульев...

codeforcescompetitive-programming
CF 104274J - Рудольф и математические часы

We are given a regular N-sided polygon that represents the boundary of a clock face. Its center is the origin, one vertex lies on the positive y-axis, and the polygon is oriented in a fixed way.

codeforcescompetitive-programming
CF 104274H - Рудольф и проблема вагонетки

The railway system forms a directed acyclic graph rooted at node 1. Every edge represents a one-way track segment with a number of people on it who would be hit if the train traverses that edge.

codeforcescompetitive-programming
CF 104274I - Рудольф и дни рождения великих

We are given a person’s birth date and an upper bound year. For each query, we need to count how many times this person will celebrate their birthday from the year after their birth up to and including the given end year.

codeforcescompetitive-programming
CF 104274F - Рудольф и игра в наперстки

We are dealing with a hidden binary array of length $N$. Exactly two positions contain a value of 1, and all other positions contain 0. We cannot see the array directly. Instead, we are allowed to ask queries of the form: give me the sum of values in a subsegment $[L, R]$.

codeforcescompetitive-programming
CF 104274G - Рудольф и формирование букета

We are given a row of flowers, each flower having a type represented by an integer. A florist considers a bouquet “valid” only if it corresponds to a contiguous segment of this row and the segment contains exactly K distinct flower types.

codeforcescompetitive-programming
CF 104274E - Рудольф и номера телефонов

We start with a single initial phone number consisting of digits. From this string, a sequence of new phone numbers is generated.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 212

The flaw in the previous solution is that it tried to define ZDD nodes as states indexed by a subset $X \subseteq U$.

taocpmathematicsalgorithmsvolume-4medium
CF 104274B - Рудольф и кубик Рубика

We are given a fully scrambled state of a 2×2×2 Rubik’s cube, encoded not as physical faces but as a flat list of 24 colored stickers. Each color represents one of the six faces in the solved configuration.

codeforcescompetitive-programming
CF 104274C - Рудольф и кубик Рубика (супер хард)

We are given the state of a very small Rubik-like object that is already a 1×1×1 cube, meaning there are exactly six colored faces with no internal structure.

codeforcescompetitive-programming
CF 104274D - Рудольф и НВП

You've hit your limit. Please try again later.

codeforcescompetitive-programming
CF 104274A - Рудольф и аренда

Rudolf spends up to one million days on a foreign planet, and the entire timeline is treated as a single continuous calendar starting from day one. The key complication is that two independent schedules overlap. The first schedule is monthly rent.

codeforcescompetitive-programming
CF 104279O - 爬塔

Let $S={1,dots,m}$ denote the selector variables and $T={m+1,dots,m+2^m}$ the data variables of the multiplexer $Mm$. For each $iin S$, the value of $xi$ selects one index in $T$, and the function outputs the chosen data bit.

codeforcescompetitive-programming
CF 104279R - postcard

We are dealing with a fully specified logical reconstruction problem involving six people, six mailbox owners, and six postcard themes.

codeforcescompetitive-programming
CF 104279Q - Du Cuo Ti Le

We are given an array of length $2n$, initially all zeros. We also receive $n$ interval assignment operations. Each operation $i$ comes with a segment $[li, ri)$ and, when applied, it overwrites every position in that half-open interval with the value $i$.

codeforcescompetitive-programming
CF 104279P - 三维模型

We are given a collection of triangular faces, each triangle described only by three integer vertex IDs. These IDs do not represent geometry in any meaningful way beyond identity.

codeforcescompetitive-programming
CF 104279N - 本质不同的 01 环计数

We are working with binary strings arranged on a circle. Think of a length-n binary sequence written on a ring, where position n connects back to position 1.

codeforcescompetitive-programming
CF 104279M - 操作系统计算题

We are given a collection of processes. Each process becomes available at a specific time and has a fixed processing length. At any query time $t$, we consider only processes that have already arrived, meaning their arrival time is at most $t$.

codeforcescompetitive-programming
CF 104279K - 打地鼠

We are dealing with a game on an undirected connected graph where nodes represent holes and edges represent tunnels. A mouse starts at some unknown node. In each round, Kanade “attacks” exactly one chosen node from a fixed sequence.

codeforcescompetitive-programming
CF 104279L - 树边重排

We are given a tree with n vertices and n − 1 undirected edges. The task is not to output the edges themselves or reconstruct an adjacency list, but to assign to every vertex i (from 1 to n − 1) a partner vertex pi such that the pair (i, pi) is one of the given tree edges.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 211

Let $f$ be the Boolean function that represents solutions of an exact cover instance on a universe $U$ with a family of subsets encoded by variables $x_1,\dots,x_n$.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104279F - 炸弹鸭

Let $S={1,dots,m}$ denote the selector variables and $T={m+1,dots,m+2^m}$ the data variables of the multiplexer $Mm$. For each $iin S$, the value of $xi$ selects one index in $T$, and the function outputs the chosen data bit.

codeforcescompetitive-programming
CF 104279J - 数矩形

We are given a set of points in the plane, with no duplicates, and we need to count how many rectangles can be formed by choosing four of these points as vertices.

codeforcescompetitive-programming
CF 104279I - 公主连结!Re:Dive

We are given a game system with 15 types of actions, where each action consumes a fixed amount of stamina depending on its index. Actions 1 through 4 cost 8 stamina each, actions 5 through 10 cost 9 stamina each, and actions 11 through 15 cost 10 stamina each.

codeforcescompetitive-programming
CF 104279H - 约瑟夫问题

We are simulating a Josephus-style elimination on a circular arrangement of people labeled from 1 to n. The difference from the classic version is that the step size is not fixed. Instead, there are q rounds, and each round provides its own step value k.

codeforcescompetitive-programming
CF 104279G - Guard the Kingdom

We are given a kingdom structured as a tree, meaning there are n cities connected by n − 1 roads and there is exactly one simple path between any two cities. Some of these cities are marked as important, and some cities contain troops.

codeforcescompetitive-programming
CF 104279D - 小美爱画鱼

We are given several independent test cases. In each test case, we are working on a grid in the first quadrant. Every segment we receive lies on a single 45-degree diagonal line, because each segment’s endpoints satisfy the same value of $x + y$.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 210

Let the ZDD for $f$ be given as a reduced ordered ZDD with variable ordering $x_1 < x_2 < \cdots < x_n$.

taocpmathematicsalgorithmsvolume-4medium
CF 104279E - 小团来打字

We are given a sequence of typing requests. Each request says that a certain key, identified by an integer label, is supposed to be pressed repeatedly a given number of times.

codeforcescompetitive-programming
CF 104279A - 能量采集

We are given a grid with $n$ rows and $m$ columns. Each cell contains one character, either $A$ or $B$. Starting from the top-left cell, we move only right or down until reaching the bottom-right cell.

codeforcescompetitive-programming
CF 104279C - 往日重现

We are given a set of circles in a plane with a strong structural promise: no two circles intersect or touch each other. This restriction forces a very rigid geometry. Any two circles are either completely separate, or one lies fully inside the other. There is no partial overlap.

codeforcescompetitive-programming
CF 104279B - A Boring Game

We are given a linear tower of floors, each floor i has an enemy with a required strength ai and a reward bi that increases the player’s strength after defeating that enemy. The player can walk along adjacent floors, moving only between i and i + 1 or i - 1.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 21

Yes.

taocpmathematicsalgorithmsvolume-4simple
CF 104282M - Jiubei and Construction

We are asked to construct, for each test case, a list of n distinct integers whose total sum equals a target value k, while keeping every chosen number within the range [-10^9, 10^9].

codeforcescompetitive-programming
CF 104282L - Auto Chess

We are given a set of enemy positions on a plane, all measured relative to the origin where our character stands.

codeforcescompetitive-programming
CF 104282J - Disjoint-Set-Union Sum

We start with an array of $n$ numbers. Initially, each element stands alone as a separate segment. The process repeatedly chooses two neighboring segments, merges them into one, and assigns that new segment a value equal to the sum of all elements inside it.

codeforcescompetitive-programming
CF 104282K - Equal Difference Prime

We are asked to count special groups of four prime numbers taken from the range from 1 to n. Each group consists of indices a, b, c, d such that all four numbers are prime and they form an arithmetic progression with exactly three equal gaps.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 209

Let the Boolean function be given by a ZDD with variable order $x_1,x_2,\ldots,x_n$.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104282I - Magic Tree

We start with a rooted tree where vertex 1 is the root and every other vertex has a fixed parent given in the input. Depth is defined in the standard way: the root has depth 1, and every edge increases depth by 1.

codeforcescompetitive-programming
CF 104282H - Maze

We are given an $n times m$ grid where each cell either contains a cake or is empty. The task is to eat all cakes while maximizing total satisfaction. There are two possible actions. One action eats a single cake and gives a fixed reward $p$.

codeforcescompetitive-programming
CF 104282G - Domino

We are given a collection of domino cards. Each card carries two values, a front value and a back value. From the full set of cards, we first select exactly K cards. The score for this first selection is the sum of the front values of those K chosen cards.

codeforcescompetitive-programming
CF 104282F - Crazy Thursday, V me 50!

We are given up to 8 groups of people, where each group contains a small set of uniquely named individuals. Some individuals appear in multiple groups. We must choose exactly k of these groups and decide the order in which to send a message to them.

codeforcescompetitive-programming
CF 104282E - XOR on Tree

We are given a rooted tree where vertex 1 is the root. Each vertex carries a value, and for every query we are asked to work inside a specific subtree.

codeforcescompetitive-programming
CF 104282D - Add 9 Zeros Ⅱ

We are given a list of distinct integers, and we want to choose as many of them as possible to form a subset with a single restriction: we are not allowed to pick two numbers where one is exactly 9 larger than the other.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 208

Let the ZDD represent a family $\mathcal{F}$ of subsets of ${x_1,\dots,x_n}$, ordered by the variable indices, and let each node $k$ be labeled by $V(k)\in{1,\dots,n}$.

taocpmathematicsalgorithmsvolume-4medium
CF 104282B - Emoji Master BSQ

We are given a fixed dictionary of word replacements. Each rule states that a specific word should always be replaced by another fixed word. After reading all rules, we are then given a sequence of words that form a sentence spoken by BSQ.

codeforcescompetitive-programming
CF 104282C - Genshin Master

There are 6 independent tracks, and each track contains several disjoint time segments during which blocks appear. Each segment [l, r] means that on every integer second from l to r inclusive, that track contributes exactly one point if we choose to press it at that second.

codeforcescompetitive-programming
CF 104282A - Zawei The Rock

The task is extremely direct. There is no input at all, and the program is required to produce a single fixed string as output. The string is exactly Jesus Bocchi, including capitalization and spacing, and nothing else should be printed.

codeforcescompetitive-programming
CF 104283L - Ultimate Game

We have a number line from position 0 to position N, with stones placed at distinct integer coordinates strictly inside this interval.

codeforcescompetitive-programming
CF 104283K - Special Lattice Path

We are walking on integer grid points starting from the origin. The destination is a fixed point $(Rx, Ry)$. At each step, the movement rules allow several local transitions that can shift the position in different directions, but we are constrained to stay in the first…

codeforcescompetitive-programming
CF 104283J - Magic Balls

We are given a collection of balls, each ball initially has a color and each color has an associated value. In addition to this, there are transformation rules that allow us to change a ball’s color from one specific color to another.

codeforcescompetitive-programming
CF 104283I - The Secret Key

We are given two integers, $A$ and $B$, along with two target remainders $m1$ and $m2$. The task is to find the smallest positive integer $X$ such that when $A$ is divided by $X$, the remainder is exactly $m1$, and when $B$ is divided by $X$, the remainder is exactly $m2$.

codeforcescompetitive-programming
CF 104283H - Sequential Nim

I can’t write a correct editorial for this yet because the problem statement is corrupted/incomplete. Right now only fragments are visible (mentions of gcd(p, q), factorials, and a modulo definition), but the actual game rules, input format, and what needs to be computed are…

codeforcescompetitive-programming
CF 104283G - Another Tree Query

We are given a sequence of piles arranged in a fixed order. Each pile contains some number of stones, and players alternate turns.

codeforcescompetitive-programming
CF 104283D - Search For Beauty

We are given a single positive integer $N$. For every integer $k$ from $1$ to $N$, we define a value called “beauty” based on the relationship between $k$ and $N$.

codeforcescompetitive-programming
CF 104283F - Find GCD

We are given three integers in each test case, describing a base number and two exponent parameters. The expression to evaluate is the greatest common divisor of two numbers that are both powers of the same base, where the exponents are factorials. Concretely, we compare $n^{a!

codeforcescompetitive-programming
CF 104283E - Tree query with update

We are given a tree where every node stores a value. The tree structure does not change, but node values do. We must answer two kinds of operations: we can update the value stored at a single node, and we can query a subtree to find the maximum value currently present among…

codeforcescompetitive-programming
CF 104283B - Johny English and Group Formation

We are given a line of people, each person assigned a country label. For every query, a segment of the line is declared to be VIPs, while everyone outside that segment is non-VIP.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 207

Let $A={i_1,i_2,\ldots,i_\ell}$ and let $F = e_{i_1}\cup\cdots\cup e_{i_\ell}$.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104283A - Yet Another Short Statement

We are given multiple independent queries. Each query defines a closed numeric interval from l to r, together with two parameters: a target digit sum x and a rank k. Inside that interval we conceptually look at all positive integers whose digits add up to exactly x.

codeforcescompetitive-programming
CF 104283C - Johnny English Strikes Again

The problem presents multiple independent test cases. Each test case consists of four integers that define some configuration or instance of a system. The task is to compute a valid result for each instance or report that no valid construction exists.

codeforcescompetitive-programming
CF 104285M - Mini Factorization Challenge

We are given two large integers for each test case, but both of them have been slightly corrupted. The first number is supposed to represent an integer $n$, and the second is supposed to represent $k$, the number of positive divisors of $n$.

codeforcescompetitive-programming
CF 104285N - Nancy's Numbers

We are given a list of integers, and we are allowed to repeatedly increase any chosen element by exactly one. The goal is to transform the array so that all values become distinct, while performing as few increments as possible.

codeforcescompetitive-programming