brain

tamnd's digital brain — notes, problems, research

41641 notes

TAOCP 7.1.4 Exercise 171

A BDD is **skinny** if for each variable $x_j$ there is exactly one branch node labeled $j$, and at that node exactly one of the two outgoing edges, LO or HI, leads to a sink node.

taocpmathematicsalgorithmsvolume-4math-hard
CF 104354K - 排列与质数

We are asked to build a cyclic arrangement of the numbers from 1 to n, meaning we output a permutation where every number appears exactly once and the sequence is considered circular, so the last element is also adjacent to the first.

codeforcescompetitive-programming
CF 104354J - Mocha 沉迷电子游戏

We are given a fixed geometric setup per test case: three points $P, A, B$ that form a non-degenerate isosceles triangle with $PA = PB$, and a line segment $AB$ acting as the “blade”.

codeforcescompetitive-programming
CF 104354I - 数正方形

We are given a large square grid of size $(2n+1) times (2n+1)$. Inside this grid, there are $n$ axis-aligned rectangles. Each rectangle is described by its bottom-left and top-right coordinates.

codeforcescompetitive-programming
CF 104354H - Travel Begins

We are allowed to split a fixed real value $n$ into $k$ nonnegative real parts. Think of this as distributing a total “mass” $n$ across $k$ containers, where each container $ai$ can hold any real amount between $0$ and $n$, as long as everything sums back to $n$.

codeforcescompetitive-programming
CF 104354G - Toxel 与字符画

We are asked to turn a mathematical expression of the form $x^y$ into a fixed-size ASCII artwork. Each test case gives a string representation of two positive integers $x$ and $y$, and we must decide what to draw based on the value of $z = x^y$.

codeforcescompetitive-programming
CF 104354E - 矩阵游戏

We are given a grid of size n by m. Each cell is either a fixed 0, a fixed 1, or a wildcard character that can be converted into a 1, but only up to x times per test case.

codeforcescompetitive-programming
CF 104354F - Art for Last

We are given a sequence of non-negative integers. From this sequence we must choose exactly $k$ elements while preserving their relative order of indices. Once we pick these $k$ values, we look at all pairwise absolute differences between the chosen values.

codeforcescompetitive-programming
CF 104354D - Toxel 与多彩的宝可梦世界

We are given a graph of towns connected by roads, where each road has a color. The graph can contain multiple edges between the same pair of towns and even self-loops, so it is a general multigraph rather than a simple one.

codeforcescompetitive-programming
CF 104354C - Toxel 与随机数生成器

We are given a binary string of length one million that was produced by one of two pseudorandom bit generators based on a fixed seed. The first generator is a standard XorShift64 machine. It starts from the seed once and then evolves a 64-bit state forever.

codeforcescompetitive-programming
CF 104354B - Art for Rest

We are given an array of non-negative integers. For a chosen integer k, we cut the array into consecutive chunks of length k, except the last chunk which may be shorter.

codeforcescompetitive-programming
CF 104354A - 小水獭游河南

We are given a string s and we need to decide whether it can be split into two consecutive parts a and b such that the whole string is exactly a + b. The first part a must be a string where every character is distinct, so no letter appears twice inside a.

codeforcescompetitive-programming
CF 104355O - 打则

We are asked to count how many “strength tables” can be formed under a somewhat unusual rule system. A strength table consists of two choices. First, we choose a full ranking of the $n$ machines, i.e. a permutation $a1, a2, dots, an$.

codeforcescompetitive-programming
CF 104355N - 栈列

I’m missing the actual problem content beyond the title “栈列”, and there’s no input/output or constraints included. With only that, any editorial would be guesswork and likely wrong.

codeforcescompetitive-programming
CF 104355M - 斑马子树

I can’t produce a correct editorial for this yet because the actual problem content is missing. Right now only the title “斑马子树” is provided, but there is no definition of what a zebra subtree is, no input format, no constraints, and no required output behavior.

codeforcescompetitive-programming
CF 104355L - 绘画爱好者以撒

I can’t write a correct editorial for this problem yet because the actual problem statement is missing. Right now I only see the title “L 绘画爱好者以撒”, but there are no details about the input format, output format, constraints, or what needs to be computed.

codeforcescompetitive-programming
CF 104355K - 莉可丽丝

The problem statement is not actually present here beyond the title “K 莉可丽丝”. There is no description of the input format, output format, constraints, or task definition, so there is nothing concrete to derive a solution from.

codeforcescompetitive-programming
CF 104355J - 大秦酒店欢迎您

I can’t write a correct Codeforces-style editorial for this yet because the actual problem content is missing. Right now the statement only shows the title “大秦酒店欢迎您” with empty input and output sections, so there is no way to know what the task is (no…

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 170

A skinny BDD is an ordered chain of nodes $x_1,\dots,x_n$ where each node $x_j$ has exactly one outgoing edge to a sink and one outgoing edge to the next node $x_{j+1}$, except $x_n$, whose two childr...

taocpmathematicsalgorithmsvolume-4math-medium
CF 104355I - 喵喵喵

This problem is deliberately minimal: there is no meaningful input structure, and the task reduces to producing a fixed output string. The only information we are given is the text “I 喵喵喵”, which is best interpreted as the required output itself.

codeforcescompetitive-programming
CF 104355H - 字符游戏

I’m missing the actual problem statement details (inputs, operations, and required output). Right now only the title “字符游戏” is provided, so there’s no way to reconstruct a correct solution or write a meaningful editorial without guessing.

codeforcescompetitive-programming
CF 104355G - 和而不同

I can’t reliably write an editorial for this yet because the actual problem content is missing. Right now, “Codeforces 104355G - 和而不同” only shows a title, but there is no statement, no input/output description, and no constraints.

codeforcescompetitive-programming
CF 104355F - 渡渡鸟游乐场

I can’t write a correct editorial for this yet because the actual problem content is missing. Right now the statement only shows the title, input/output sections are empty, and there’s no description of what operations, structures, or constraints are involved.

codeforcescompetitive-programming
CF 104355E - 全错

I can’t write a correct editorial for this because the actual problem content is missing. What you provided only includes the title “E 全错” without any description, input/output format, or constraints.

codeforcescompetitive-programming
CF 104355D - 点集扩张

The problem statement is missing from your prompt (it only shows the title “点集扩张” without any description, input, or rules). Without that, I can’t reliably reconstruct the task or produce a correct Codeforces-style editorial.

codeforcescompetitive-programming
CF 104355A - 大水题

The problem statement is intentionally minimal, essentially just labeling the task as a “big easy problem” without specifying any real computation.

codeforcescompetitive-programming
CF 104355B - 原粥率

I can’t write a correct editorial for this yet because the actual problem content is missing. Right now we only have the title “原粥率” and no description, input format, or required output behavior, which makes it impossible to reconstruct the algorithm without guessing.

codeforcescompetitive-programming
CF 104355C - 话剧

I can’t reliably write a correct editorial from that yet because the actual problem content is missing. Right now you’ve only provided the title “话剧”, but there are no constraints, no input/output format, and no description of what needs to be computed.

codeforcescompetitive-programming
CF 104359F - Пазл

We are given two configurations of a very thin grid with two rows and many columns. Each cell contains either a 0 or a 1. In one configuration we start with some arrangement of ones and zeros, and in the other configuration we want to reach a target arrangement.

codeforcescompetitive-programming
CF 104359E - Пират Серёжа

We are given a grid of size $n times m$ that contains each integer from $1$ to $nm$ exactly once. Think of each number as occupying a unique cell in a grid graph where movement is allowed only between edge-adjacent cells. We are allowed to construct a walk on this grid.

codeforcescompetitive-programming
CF 104359D - Шлюзы

We are given a linear system of water tanks arranged in a row. Each tank has a fixed capacity. Initially all tanks are empty, and each tank has a pipe that can be turned on, producing a constant inflow of one unit of water per second into that tank.

codeforcescompetitive-programming
CF 104359A - Вордл наоборот

We are given a secret word S of length n, where all characters are distinct, and a color pattern P describing how another unknown guessed word T was evaluated against S using Wordle rules. The evaluation works position by position. If T[i] equals S[i], the result is green.

codeforcescompetitive-programming
CF 104359C - Помогаем природе

We are given an array representing moisture levels along a line of trees. Each operation modifies a contiguous segment in a very structured way. One operation decreases a prefix by 1, another decreases a suffix by 1, and a third operation increases the entire array by 1.

codeforcescompetitive-programming
CF 104359B - Палиндромные числа

We are given a decimal number represented as a string of length $n$. Our task is to construct another positive integer of the same length, also with no leading zeros, such that when we add it to the given number digit by digit, the resulting sum forms a palindrome.

codeforcescompetitive-programming
CF 104360F - Необычный массив

We are given an array and we focus on each position independently. Fix an index $i$. We look at every contiguous subarray that contains this index. For each such subarray, we sort its elements and locate the value $ai$ inside this sorted list.

codeforcescompetitive-programming
CF 104360E - Игра с картами

We are given a sequence of moves. At the start, Bob holds two integers, one in his left hand and one in his right hand, both equal to zero. At each move i, Alice presents a new number ki. Bob must choose whether to replace the value in his left hand or in his right hand with ki.

codeforcescompetitive-programming
CF 104360D - PriceFixed

We are given several product types, each requiring a fixed number of purchases. Every purchase normally costs 2 units of money. There is a global counter that increases every time we buy any item, regardless of type.

codeforcescompetitive-programming
CF 104360A - Старт олимпиады

There are $n$ participants taking part in an olympiad. Each participant $i$ starts at a fixed time forming an arithmetic progression: the first starts at time $0$, the second at time $x$, the third at $2x$, and so on, so participant $i$ starts at $(i-1)x$.

codeforcescompetitive-programming
CF 104360C - Стабильные параллели

We are given a collection of student skill levels, and we want to split them into several groups called parallel classes. Inside each class, if we sort students by skill, every adjacent pair must differ by at most a fixed value x.

codeforcescompetitive-programming
CF 104360B - Вася и Петя

We are given a string of lowercase English letters. Each query selects a contiguous substring, and we transform that substring using a fixed rule: every character is expanded independently, where a letter at position x in the alphabet is repeated exactly x times.

codeforcescompetitive-programming
CF 104361E - Шахматные баталии

We are working on a rectangular grid of size $2n times 2m$ with a fixed chess coloring: a cell $(i, j)$ is white if $i + j$ is even, otherwise it is black. Only white cells matter for the game.

codeforcescompetitive-programming
CF 104361D - Перевернутые родословные

We are given a structure on $n$ labeled people where each person has either zero or exactly one child. If a person has no child, their outgoing pointer is 0. Otherwise, every person points to exactly one child index in $[1, n]$.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 17

A reduced ordered binary decision diagram (BDD) for a Boolean function $f(x_1,\dots,x_n)$ consists of a rooted directed acyclic graph in which each non-sink node $v$ has a variable index $V(v)\in{1,\d...

taocpmathematicsalgorithmsvolume-4hard
CF 104361B - Выбор цветов для букета

We are given a bouquet that must contain exactly n flowers, and there are m flower types. Each type can be used any number of times. The reward model for a type is not constant per flower.

codeforcescompetitive-programming
CF 104361C - Межпланетные электрички

We are working with a cyclic daily timetable split into minutes. A passenger railway service must run forever with a fixed periodic pattern: trains depart exactly every m/2 minutes, and each departure occupies the platform for a fixed interval before it.

codeforcescompetitive-programming
CF 104361A - Подготовка к экзамену

We are asked to construct three integers $a, b, c$, all chosen from a fixed interval $[l, r]$, together with a positive integer $n$, such that a linear expression holds exactly: $$n cdot a + b - c = m.$$ The input gives us the bounds $l$ and $r$, and a target value $m$.

codeforcescompetitive-programming
CF 104363K - Turn-based Game

We are simulating a sequence of battles where each battle consists of fighting a small group of identical monsters. Each monster has a fixed amount of health, and every attack reduces the chosen monster’s health by exactly one.

codeforcescompetitive-programming
CF 104363L - Subxor

We are given an array of integers and a fixed integer $K$. For each query, we look at a subsegment of the array, from index $l$ to $r$, and we want to choose a contiguous subarray inside this segment that maximizes its length under a constraint on XOR.

codeforcescompetitive-programming
CF 104363J - XOR String

We are given a circular string, so substrings are allowed to wrap from the end back to the beginning. Each position in this circle has a lowercase character and an associated integer value.

codeforcescompetitive-programming
CF 104363I - Club

We are given a collection of n clubs, and we must assign each club one of m badge types. Multiple clubs can share the same badge type, but every badge type must appear at least once. After the assignment is fixed, a participant repeatedly visits clubs.

codeforcescompetitive-programming
CF 104363H - KingZ

We are given a fixed 10×10 board where each cell represents a battlefield tile. Some cells are walls and cannot be used. Every other cell may initially contain a number of troops and also belongs to a category such as core, keep, lawn, or neutral territory.

codeforcescompetitive-programming
CF 104363G - Gravity

We are given a set of points in the plane, each representing an asteroid of equal mass. We must split these points into two nonempty groups.

codeforcescompetitive-programming
CF 104363F - Folder

We are given a rooted tree where each node represents a folder. Folder 1 is fixed as the root, and every other folder has exactly one parent. So the structure is a hierarchy of directories.

codeforcescompetitive-programming
CF 104363D - Pandemic

We are asked to count how many valid “distribution plans” Kanade can follow while serving a row of $n$ rooms arranged in a line. The process always moves strictly from left to right, never revisiting rooms.

codeforcescompetitive-programming
CF 104363E - Ethernet

We are simulating a very small randomized process on a fixed set of ports and cables, where each cable ultimately ends up plugged into exactly one port. There are n ports labeled from 1 to n and n cables also labeled from 1 to n.

codeforcescompetitive-programming
CF 104363C - Compass

We are dealing with a system of three rotating components. Each component has a position on a circular scale, and each full rotation brings it back to the starting point after a fixed number of steps. The twist is that we do not directly choose how much each component rotates.

codeforcescompetitive-programming
CF 104363B - Chevonne's Game

We are given a binary string representing a row of pearls, where each pearl is either white or black. The system supports two operations over time. One operation flips the colors of all pearls in a range, turning white into black and black into white.

codeforcescompetitive-programming
CF 104363A - Magic Computer

We are given a process involving a collection of USB disks, where each disk initially holds a unique file. The computer has a very unusual constraint: at any moment, it only interacts with the two most recently inserted disks, and when two disks are inserted together they…

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 169

Let $f$ be a read-once Boolean function of $22m+1$ variables, represented by a rooted formula tree in which each variable appears exactly once.

taocpmathematicsalgorithmsvolume-4math-research
CF 104366L - Spatial Quantum Energy Theory

We are given a system of atoms, where each atom is defined by a subset of at most 20 possible elementary particle types. Each particle type has a fixed energy value.

codeforcescompetitive-programming
CF 104366M - Easy Problem of Prime

We are given many independent queries. Each query provides a number $n$, and for that value we first imagine all integers from $2$ up to $n$. For each integer $i$, we define a value $f(i)$, where $f(i)$ is the smallest number of prime numbers whose sum equals exactly $i$.

codeforcescompetitive-programming
CF 104366J - Less Time on the Road

We are given a directed graph where every edge has unit cost, and the graph is guaranteed to be strongly connected. Two workers start at vertex 1. A sequence of requests arrives, and each request specifies a vertex that must be visited to perform a repair.

codeforcescompetitive-programming
CF 104366K - The Secret Comparison

Two competitors each have a single integer score. The task is to compare these two numbers and declare who has the higher score, or whether they are equal. The input consists of exactly two integers, representing the scores of the two players.

codeforcescompetitive-programming
CF 104366I - Subsetting and Summing

We are given a collection of 3D vectors. From these vectors we may choose any subset, including the empty set, and sum the chosen vectors component-wise to obtain a single resultant vector.

codeforcescompetitive-programming
CF 104366H - Light the Street

We are placing streetlights along a one-dimensional segment of length $n$. We are allowed to choose up to $k$ positions for these lights.

codeforcescompetitive-programming
CF 104366G - Expected Sum

We are given a long decimal string, interpreted as a sequence of digits placed left to right. Between every adjacent pair of digits, we independently decide whether to insert a plus sign.

codeforcescompetitive-programming
CF 104366E - Triangle Pick

We are given a collection of triangular surfaces in 3D space. Each triangle is a flat solid piece defined by three vertices.

codeforcescompetitive-programming
CF 104366F - MPFT

We are simulating a chat group that changes over time. People either join the group or send messages, and the group has strict rules that can forcibly remove members. The first rule is a capacity constraint. The group can hold at most N people.

codeforcescompetitive-programming
CF 104366D - Concrete Painting

We are given a collection of segments on a number line. From these segments, we consider every possible subset of them. For any chosen subset, we imagine painting all of its segments onto the number line, where overlapping parts are still counted only once.

codeforcescompetitive-programming
CF 104366B - Problem B

The town is a rectangular grid of intersections with roads connecting adjacent intersections in the usual four-direction structure. Vehicles enter from any boundary road endpoint and must eventually leave through some boundary endpoint.

codeforcescompetitive-programming
CF 104366C - Abstract Painting

We are given a collection of axis-aligned line segments on an infinite 2D plane. Each segment is either vertical or horizontal. Two segments are considered connected if they physically intersect at any point, including touching at endpoints.

codeforcescompetitive-programming
CF 104366A - Cask Effect

We are given several wooden boards, each with a fixed length. The “strength” or “capacity” of a cask built from these boards is defined as the length of the shortest board used in it.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 168

Let a read-once Boolean function $f(x_1,\dots,x_n)$ be given, and let $B(f)$ denote the number of BDD nodes including sinks, as defined in Section 7.

taocpmathematicsalgorithmsvolume-4hm-project
CF 104369M - Computational Geometry

We are given a convex polygon described by its vertices in counterclockwise order. The task is to choose two distinct vertices and draw a chord between them, but not every pair is allowed: the chord must actually split the polygon into two regions, and both resulting pieces…

codeforcescompetitive-programming
CF 104369L - Classic Problem

We are given a very large graph on vertices labeled from 1 to n, where every pair of vertices is connected by an edge, so the graph is complete.

codeforcescompetitive-programming
CF 104369J - X Equals Y

We are asked to choose two bases, one for $x$ and one for $y$, so that when both numbers are written in their respective bases, the resulting digit sequences are identical when read from least significant digit to most significant digit.

codeforcescompetitive-programming
CF 104369K - Peg Solitaire

We are given a very small chessboard, at most six rows by six columns, with up to six pegs placed on distinct cells.

codeforcescompetitive-programming
CF 104369I - Path Planning

We are given a grid where every cell contains a distinct integer from the range $[0, n cdot m - 1]$. We start at the top-left cell and can only move right or down until reaching the bottom-right cell.

codeforcescompetitive-programming
CF 104369H - Canvas

We are given a sequence of length $n$, initially filled with zeros. We also have $m$ operations. Each operation selects two positions $li < ri$ and assigns values $xi$ and $yi$ to those positions, overwriting whatever is currently there.

codeforcescompetitive-programming
CF 104369G - Swapping Operation

We are given an array of non-negative integers. For any split point $k$, we can divide the array into a prefix and a suffix. For that split, we compute the bitwise AND of the prefix and the bitwise AND of the suffix, then sum the two results.

codeforcescompetitive-programming
CF 104369F - Traveling in Cells

We are given a line of cells, each cell having a fixed position, a color, and a value associated with a single removable ball. The structure changes over time because both colors and values of individual cells can be updated.

codeforcescompetitive-programming
CF 104369E - New but Nostalgic Problem

We are given a collection of strings and we are allowed to pick exactly k of them. Once the subset is fixed, we look at every pair inside it and compute their longest common prefix. Among all these pairwise LCP values, we take the lexicographically largest one.

codeforcescompetitive-programming
CF 104369D - New Houses

We are given a line of houses indexed from 1 to m, and we must place n people into distinct houses. Two people are considered neighbors only when they occupy adjacent house indices.

codeforcescompetitive-programming
CF 104369C - Trading

We are given a street with several shops, each shop offering the same type of product at a fixed price. In each shop, the price is symmetric: if you buy or sell one unit there, the cost or revenue is exactly the same value.

codeforcescompetitive-programming
CF 104369B - Base Station Construction

We are given a line of positions from 1 to n, where each position has a cost for building a base station. We are allowed to choose any subset of positions to build base stations, paying the sum of their costs.

codeforcescompetitive-programming
CF 104369A - Programming Contest

We are looking at a yearly event that starts at some initial year y1. From that year onward, the contest is intended to happen once every year. However, there is a small list of exceptional years where the contest did not take place.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 167

We restart from the structural characterization of read-once Boolean functions and the defining property of reduced ordered binary decision diagrams.

taocpmathematicsalgorithmsvolume-4medium
CF 104373K - Link-Cut Tree

We are given an undirected graph where each edge has a very special weight: the i-th edge in input order has weight $2^i$.

codeforcescompetitive-programming
CF 104373J - Colorful Tree

We are building a tree incrementally. The structure starts with a single node, and each operation either attaches a new node to an existing node with a weighted edge or changes the color of an existing node.

codeforcescompetitive-programming
CF 104373I - LCS Spanning Tree

We are given a collection of strings, each representing a vertex in a complete undirected graph. Every pair of vertices is connected, and the weight of an edge is defined by how similar the two strings are: specifically, it is the length of the longest substring that appears…

codeforcescompetitive-programming
CF 104373H - Permutation on Tree

We are given a rooted tree with $n$ labeled vertices. We consider all permutations of the vertices, but we only keep those permutations that respect the tree’s ancestor structure: whenever a node $u$ is an ancestor of node $v$, then $u$ must appear earlier in the permutation.

codeforcescompetitive-programming
CF 104373G - Cyclic Buffer

We are given a circular array that contains a permutation of the numbers from 1 to n. There is a fixed window of size k that represents the “visible” part of the buffer, specifically the first k positions at any moment.

codeforcescompetitive-programming
CF 104373D - Shortest Path Fast Algorithm

The algorithm in the statement is a modified shortest path routine that behaves like SPFA but uses a priority queue instead of a FIFO queue. Every time a vertex is extracted from the queue, it relaxes its outgoing edges.

codeforcescompetitive-programming
CF 104373F - Sandpile on Clique

We are given a complete graph with $n$ vertices, where every vertex is connected to every other vertex. Each vertex starts with some number of chips.

codeforcescompetitive-programming
CF 104373E - Pass the Ball!

We are given a directed mapping over n children. Each child always passes whatever ball they currently hold to exactly one fixed destination child p[i].

codeforcescompetitive-programming
CF 104373B - The Matching System

We are given a length $n$, and we must construct two binary strings of that length: a pattern string and a target string. The pattern is not purely binary; it also contains two special symbols that define a recursive matching process against the binary string.

codeforcescompetitive-programming
CF 104373A - So I'll Max Out My Constructive Algorithm Skills

We are given a square grid of size $n times n$, where every cell contains a distinct integer from 1 to $n^2$. You can think of this grid as a weighted graph laid out on a lattice: each cell is a node, and edges exist between orthogonally adjacent cells.

codeforcescompetitive-programming
CF 104373C - Laser Trap

We are given a set of points in the plane. Each point acts as a laser generator, and every pair of generators is connected by a straight laser segment. So for n points, the system forms a complete geometric graph where every edge is a segment between two given coordinates.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 166

We restart the argument from the formal semantics of ordered binary decision diagrams and build canonicity directly from evaluation, without assuming any uniqueness of a construction procedure.

taocpmathematicsalgorithmsvolume-4math-hard
CF 104375K - Kingdom Power C.

The game can be modeled as a directed graph where each level is a node and each prerequisite relation is a directed edge. If there is an edge from level u to level v, then finishing u unlocks v, so v becomes playable after u is completed.

codeforcescompetitive-programming