brain

tamnd's digital brain — notes, problems, research

43815 notes

TAOCP 7.1.4 Exercise 249

Let $f(x_1,\dots,x_n)$ be a Boolean function with truth table $\tau$ and BDD $T(f)$.

taocpmathematicsalgorithmsvolume-4hm-hard
CF 104207K - Knightmare

We are watching a knight moving on an infinite chessboard. It starts from a single square, and every time it jumps, it moves according to the usual chess knight rules.

codeforcescompetitive-programming
CF 104207I - Inkopolis

We are given a connected undirected graph with exactly one cycle, meaning the number of edges equals the number of vertices. Each edge has a color.

codeforcescompetitive-programming
CF 104207H - Equidistance

We are given several points in an N-dimensional Euclidean space. The key condition is that every pair of given points is exactly one unit apart, so these points already form a perfectly regular geometric structure where all mutual distances are identical.

codeforcescompetitive-programming
CF 104207J - Subway Chasing

We are given a linear subway line with stations numbered from 1 to N. Between every pair of adjacent stations i and i+1 there is an unknown travel time ti, and these values are strictly positive integers bounded above by 2×10^9.

codeforcescompetitive-programming
CF 104207F - Fair Lottery

We are given several groups of people. Each group has a fixed size, and if a group is chosen in a lottery outcome then all its members win together. In any single outcome, the total number of winners across all chosen groups is limited by an upper bound $M$.

codeforcescompetitive-programming
CF 104207G - Alice's Stamps

We are given a line of positions from 1 to N, where each position represents a distinct stamp type. Instead of buying stamps individually, Alice can only purchase bundles, and each bundle contributes all stamp types in a contiguous interval [L, R].

codeforcescompetitive-programming
CF 104207B - Same Digit

We are given a single digit $D$ and a target integer $N$. Using only copies of the digit $D$, we are allowed to build arithmetic expressions using concatenation and standard operations like addition, subtraction, multiplication, division, factorial, negation, and a few unary…

codeforcescompetitive-programming
CF 104207D - Mr. Panda and Circles

We are working on a line segment that has integer positions from 0 to $M-1$. At each integer coordinate we may place at most one circle center, and we must place all $N$ circles.

codeforcescompetitive-programming
CF 104207E - Evil Forest

We are asked to size production for a sequence of painting competitions. Each competition has a known number of participants, and every participant consumes exactly one sketchpad.

codeforcescompetitive-programming
CF 104207C - Rich Game

Each test case describes a repeated interaction where a player tries to maximize how many badminton sets he can win, starting with no money. In each point of a match, he can choose whether to intentionally win or lose that point.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 248

A Boolean function is sweet when every subtable arising from any prefix assignment is a bead.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104207A - Dogs and Cages

We are given a system with the same number of dogs and cages, both labeled from 0 to N − 1. Each dog independently chooses a cage uniformly at random, and each cage can hold at most one dog, which means the final configuration is a random permutation of the dogs over the cages.

codeforcescompetitive-programming
CF 104217H - Sled Ordering

We are building ordered sequences of length $N$, where each position is filled with one of two indistinguishable types: spotted or brown. Because cows of the same type are identical, a valid configuration is fully described by a binary string of length $N$.

codeforcescompetitive-programming
CF 104217F - The Austin Longhorn Race

We are given a set of checkpoints scattered in a 2D plane. Each checkpoint appears only at a specific time, and if we happen to be exactly at its coordinates at that exact time, we can collect some amount of reward.

codeforcescompetitive-programming
CF 104217G - Journey to Nome

Let the given BDD for $f(x1,dots,xn)$ be a rooted directed acyclic graph whose branch nodes are labeled by variables $V(u)in{1,dots,n}$ and whose sink nodes are $bot,top$, with orderedness ensuring that along every directed path the labels strictly increase.

codeforcescompetitive-programming
CF 104217E - Snowy Hill

We are given an array representing snow heights along a straight hill. The array is monotonic non-decreasing, meaning as we move from index 0 to index N−1, values never decrease.

codeforcescompetitive-programming
CF 104217D - Outfit Ordeal

Connection interrupted. Waiting for the complete answer

codeforcescompetitive-programming
CF 104217C - Sled Circle

We are dealing with a circular track of n evenly spaced positions, labeled from 0 to n-1. Each dog starts at a unique position i, and every dog moves clockwise at a constant speed vi, meaning that after t time steps, dog i will be located at position (i + t · vi) mod n.

codeforcescompetitive-programming
CF 104217A - Swapped Signs

We are given two uppercase strings, one representing the current word displayed on a board and another representing the word we want to replace it with.

codeforcescompetitive-programming
CF 104217B - Max Difference

We are given a single integer $n$, and we are asked to look at all permutations of the sequence $(1, 2, 3, dots, n)$. Each permutation is interpreted as a number formed by concatenating its elements in order.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 247

A truth table of order $n$ is a binary string of length $2^n$.

taocpmathematicsalgorithmsvolume-4math-hard
CF 104218J - March March

We are given a directed graph on $n le 20$ labeled cities, where some one-way roads already exist. The intended goal is to ensure that there is a valid “March March route” that visits cities in order from 1 through $n$, meaning that for every consecutive pair $i to i+1$, we…

codeforcescompetitive-programming
CF 104218I - Balto's Training

We are given a directed structure over $N$ villages. From every village there are exactly two outgoing roads: one labeled left and one labeled right, each pointing to some (possibly the same or different) village.

codeforcescompetitive-programming
CF 104218G - Journey to Nome

We are given a fixed number $M$, and we are interested only in positive integers that share no prime factor with $M$. In other words, we filter the natural numbers and keep only those that are coprime to $M$, then index this filtered sequence starting from 1.

codeforcescompetitive-programming
CF 104218E - Snowy Hill

We are given an array representing snow heights along a straight hill. The values are non-negative and the sequence is monotonic non-decreasing from left to right. Each query asks for a contiguous segment whose elements sum exactly to a given value $K$.

codeforcescompetitive-programming
CF 104218D - Outfit Ordeal

We are simulating a stack-like wardrobe where clothing items are inserted, removed from the top, and occasionally removed from the middle by name. Each operation modifies or queries this pile. There are three operations.

codeforcescompetitive-programming
CF 104221B - Динислам и столовая

We are given a line of students who must eventually “clear” their dishes, and each student contributes some amount of work measured in seconds. The initial situation contains a queue of $n$ existing students.

codeforcescompetitive-programming
CF 104221E - Чайный магазин

We are given several possible positions for a shop along a straight line and a set of customers, each living at a fixed point and having a personal tolerance threshold.

codeforcescompetitive-programming
CF 104221D - Карим и дороги

We are given an undirected simple graph with $n$ intersections and $m$ roads. Each road connects two distinct intersections, and between any pair of intersections there is at most one road.

codeforcescompetitive-programming
CF 104221C - Кузя и день рождения

Kuzya is preparing a birthday party, but the number of guests he can invite depends entirely on how a cake is sliced at an unknown bakery. There are several bakeries in his city, and each bakery always cuts a cake into a fixed number of slices.

codeforcescompetitive-programming
CF 104221A - Сафия и подсчет карандашей

Something went wrong. If this issue persists please contact us through our help center at help.openai.com.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 246

Let $G=(V,E)$ be a graph, and let $f$ be a monotone Boolean function on $V$ expressed in family algebra as in Section 7.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104229D - Tourists

We are given a country whose road network forms a tree. Each city is a node, and every pair of cities is connected by exactly one simple path.

codeforcescompetitive-programming
CF 104229B - Lego Wall

We are building a rectangular structure of width $w$ and height $h$ using two types of pieces. One piece is a single unit cube that occupies exactly one cell. The other is a domino-shaped piece of size $2 times 1$, placed horizontally, covering two adjacent cells in the same row.

codeforcescompetitive-programming
CF 104229C - SocialEngineering

We are given a connected undirected graph where vertices represent people and edges represent friendships. Two players take turns moving along edges, effectively walking through the graph, but with a strict rule that each edge can be used at most once throughout the entire play.

codeforcescompetitive-programming
CF 104230D - Chika Wants to Cheat

We are designing a system that assigns a unique identifier to each number using a pattern drawn on a very small geometric canvas, a 2 by 2 square with integer lattice points.

codeforcescompetitive-programming
CF 104230B - Superpiece

We are working on an infinite chessboard where each query gives a start square and a target square, together with a set of chess pieces that are allowed to be used. A move means choosing one of the allowed pieces and applying one legal move of that piece from the current square.

codeforcescompetitive-programming
CF 104234M - Siteswap

We are given a sequence that describes a repeating juggling pattern over discrete beats. On each beat, either a throw happens with a specified delay, or nothing happens.

codeforcescompetitive-programming
CF 104234L - Directed Vertex Cacti

We are asked to count how many directed graphs can be formed on n labeled vertices under two structural restrictions, together with a global edge count constraint.

codeforcescompetitive-programming
CF 104234K - Determinant, or...?

We are given an array of length $2^n$, and from it we construct a $2^n times 2^n$ matrix. The rows and columns are indexed from $0$ to $2^n - 1$, and the entry at position $(i, j)$ is defined as $a{i , So each matrix entry does not depend on two independent values of the array…

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 245

Let $f:\{0,1\}^n\to\{0,1\}$ be monotone.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104234J - Persian Casino

We are simulating a constrained gambling process that behaves less like independent betting and more like a controlled state machine with limited “time travel” resets. Prince starts with a single coin and must go through exactly n betting rounds.

codeforcescompetitive-programming
CF 104234I - DAG Generation

We are looking at a randomized procedure that constructs a directed acyclic graph by processing vertices one by one. At any moment there is a set of already inserted vertices, and a set of remaining vertices.

codeforcescompetitive-programming
CF 104234G - Palindromic Differences

We are given an array of numbers, and we are allowed to reorder it arbitrarily. For each chosen ordering, we build a second array consisting of consecutive differences between adjacent elements.

codeforcescompetitive-programming
CF 104234H - Graph Isomorphism

We are given an undirected simple graph on $n$ vertices. From this graph, we conceptually generate all graphs that can be obtained by relabeling vertices in every possible way. Two relabelings that produce different edge sets count as different graphs.

codeforcescompetitive-programming
CF 104234F - Palindromic Polynomial

We are given several independent test cases. In each one, a hidden polynomial is known to have a symmetric coefficient pattern, meaning the coefficient list reads the same from left to right and from right to left.

codeforcescompetitive-programming
CF 104234E - Garbage Disposal

We are given a continuous block of integers from L to R. Think of these numbers as both “positions” and “items” at the same time. For every number i in this segment, we must assign it a distinct number yᵢ from the same segment, forming a permutation of the interval.

codeforcescompetitive-programming
CF 104234D - Triterminant

We are given a binary sequence where each element is either +1 or −1. From this sequence we build, for every prefix length k, a determinant of a special k by k matrix.

codeforcescompetitive-programming
CF 104234B - Super Meat Bros

We are building two independent story sequences, one for Meatio and one for Meatigi. Each sequence is formed by concatenating story arcs.

codeforcescompetitive-programming
CF 104234C - Testing Subjects Usually Die

We are repeatedly trying to identify a hidden number between 1 and n. The hidden number is not chosen uniformly: each value i has a given weight pi, and the actual probability of being the correct answer is proportional to these weights.

codeforcescompetitive-programming
CF 104234A - Square Sum

We are given a modulus $m$, and then a list of values $z1, z2, dots, zn$. For each query value $zi$, we want to count how many ordered pairs $(x, y)$ with $0 le x, y < m$ satisfy the congruence $$x^2 + y^2 equiv zi pmod m.

codeforcescompetitive-programming
CF 104235J - Счастливая конфигурация

We are given an array length $n$ and a prime number $k$ such that $n$ is divisible by $k$. The indices $1..n$ form a permutation $P$, and we are asked to construct such a permutation. The constraint introduces a second hidden object: another permutation $B$ of $1..

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 244

Let the edges of $P_3$ be $e_1$ and $e_2$, where $e_1$ joins vertices $1$ and $2$, and $e_2$ joins vertices $2$ and $3$.

taocpmathematicsalgorithmsvolume-4medium
CF 104235I - Отгадай два числа

We are interacting with a hidden pair of integers $A$ and $B$, both in the range from $0$ to $10^9$. We do not see them directly. Instead, we can send a query value $X$, and the system returns the value $(A oplus X) + B$, where $oplus$ is bitwise XOR.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 243

Let $\mathcal{f}$ be a family of sets.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104235H - Красно-синие маршруты

We are given a directed graph where every vertex has exactly two outgoing edges: one red edge and one blue edge. From any starting vertex, a move consists of repeating a fixed pattern of edge traversals, and we must determine where we end up after applying that pattern many…

codeforcescompetitive-programming
CF 104235E - Запросы на массиве

We are maintaining a mutable array where two operations repeat over time. One operation asks, for a fixed position i, to look strictly to the right and find the smallest value that is strictly greater than a[i]. The other operation flips the sign of a single element in the array.

codeforcescompetitive-programming
CF 104235D - На уголки не разрезать!

We are given a rectangular grid of size $n times m$, fully covered by unit cells. A player wants to tile all remaining cells after removing exactly one cell using a specific shape called a “corner tromino”: a shape made of three cells that forms an L, i.e.

codeforcescompetitive-programming
CF 104235C - Разговор о деревьях

We are working with a tree on $n$ vertices where vertex 1 and vertex 2 are fixed in a special way: the distance between them is exactly $m$, and no pair of vertices in the tree is farther apart than $m$.

codeforcescompetitive-programming
CF 104235B - Мед в сотах

We are given two identical geometric objects on a grid, each object is a regular hexagon of side length 1. Each hexagon is placed in a fixed orientation: two of its edges are vertical, and its lowest vertex is anchored at an integer coordinate point.

codeforcescompetitive-programming
CF 104235A - Красивое окно

We are given a rectangular window of height H and width W. Two cuts are made. First, we choose a vertical cut at some integer position A, splitting the window into a left rectangle of width A and a right rectangle of width W - A.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 242

A set $S \subseteq {1,\dots,8}^2$ is admissible if no three distinct points of $S$ lie on a common affine line in $\mathbb{R}^2$.

taocpmathematicsalgorithmsvolume-4medium
CF 104236J - Discount Spiderman

We are given a set of vertical “trees” placed at distinct x-coordinates. Each tree is just a segment from ground level up to some height. Alice starts at the leftmost side and moves strictly from left to right, but she does not move along the ground.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 241

Let $Q_8$ be the queen graph on the $8\times 8$ chessboard.

taocpmathematicsalgorithmsvolume-4hard
CF 104236H - Environmental Policy

We are given an array of integers representing environmental impact scores for different policies. Each query asks us to look inside a fixed segment of this array and consider only subarrays whose lengths lie inside a given range.

codeforcescompetitive-programming
CF 104236I - Possible Meetings

We are given a sequence of animals arranged in a line. Each animal has two attributes: a species label and a skill value. The task is to consider every contiguous segment of this line and compute a score for each segment.

codeforcescompetitive-programming
CF 104236G - Aranara Game (Hard)

We are given a directed graph on $N$ nodes where every node has exactly one outgoing edge. From each node $i$, there is a deterministic move to $nxti$. Two tokens start on nodes $a$ and $b$. In every round, both tokens simultaneously follow their outgoing edges.

codeforcescompetitive-programming
CF 104236F - Meltdown

We are given a row of $N$ ice pillars, each with an initial integer height. Over time, the system receives two kinds of operations applied to subarrays.

codeforcescompetitive-programming
CF 104236D - J IDs

We are given a rectangular grid, and two players are placed on two different cells. The grid has no obstacles, so movement is always possible in the four cardinal directions.

codeforcescompetitive-programming
CF 104236E - Wifi Connection

We are given a set of points on a 2D plane, each representing an observation station in a national park. Every station is equipped with a wireless device that has a uniform power level $P$.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 240

Let $G=(V,E)$ be a finite graph.

taocpmathematicsalgorithmsvolume-4medium
CF 104236C - Testing Building Strength

We are given a chain of rigid segments placed end to end in the plane. Each segment has a fixed length, and consecutive segments are connected by joints that allow rotation.

codeforcescompetitive-programming
CF 104236A - Aranara Game (Easy)

We are given a directed structure on $N$ nodes where each node has exactly one outgoing edge to another node, and no node points to itself.

codeforcescompetitive-programming
CF 104236B - Perfect Parks

We are given an ordering of the numbers from 1 to N placed across N positions. Think of the array a as Larry’s “ideal layout”, where position i ideally wants the value a[i]. Harry is allowed to rearrange the same set of values 1 through N into another permutation b.

codeforcescompetitive-programming
CF 104237J - Colossal Cash

We are given a set of barns arranged as vertices in a graph. Each barn gives Joe a fixed profit every time he arrives there. Between barns there are directed roads, each with an associated cost.

codeforcescompetitive-programming
CF 104237I - Mostly Successful Mailman

We are asked to count how many permutations of the numbers from 1 to N the farmer can produce while making at most K “mistakes”. A mistake occurs at a position i if the value placed at position i is not i itself.

codeforcescompetitive-programming
CF 104237H - Sunset Drifting

We are given a grid representing a city map where each cell is either free road, an obstacle, a start position, or one or more exits.

codeforcescompetitive-programming
CF 104237G - Calculating Max Grade

We are given a collection of courses. Each course has two values attached to it: a score and a number of units. We are required to pick exactly K courses.

codeforcescompetitive-programming
CF 104237E - Tree Counting

We are given a line of blocks, each block having a certain number of trees. A series of walks is also given, where each walk covers a contiguous segment of blocks from one endpoint to another, inclusive.

codeforcescompetitive-programming
CF 104237D - Aranara Game (Easy)

We are given a directed graph on $N$ nodes where every node has exactly one outgoing edge, defined by an array nxt. From any node $i$, a token moves deterministically to nxt[i] every round.

codeforcescompetitive-programming
CF 104237A - Fun with Food Audits

Four trash bins are placed around a campus, and at the end of lunch each bin is weighed. Each bin has a known empty weight of six pounds, and the input gives the total measured weight of each bin after use.

codeforcescompetitive-programming
CF 104237B - Road Intersections

We are given a collection of infinite straight lines laid out on a plane. Each line is either vertical, representing an avenue with a fixed x-coordinate, or horizontal, representing a street with a fixed y-coordinate.

codeforcescompetitive-programming
CF 104239D - Доступ к серверу

We are given a long array b that contains, somewhere inside it, a hidden structure built from two parts glued together: a key segment of length q, followed immediately by an encrypted version of a known array a of length m. The encryption is very structured.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 24

Let $G$ be the grid graph of Fig.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104239B - Симулятор студента

We start from the origin on an infinite grid and want to reach a fixed target cell at coordinates $(x, y)$. Each basic action moves the character by one unit in one of the four cardinal directions, and each such action costs one button press.

codeforcescompetitive-programming
CF 104239C - Кубки

We are given two sequences of integers, each representing the order of trophies on two separate shelves. Within each shelf, all values are distinct, but the same value may appear in both shelves.

codeforcescompetitive-programming
CF 104239A - Лабораторные работы

The semester is modeled as a single continuous timeline of days. Each laboratory occupies a consecutive block of days, and these blocks do not overlap. If the first lab lasts $a1$ days, then it spans days $1$ through $a1$.

codeforcescompetitive-programming
CF 104243B - Цены на бензин

We are given a network of cities connected by undirected roads. Each road has a fixed fuel requirement, meaning that to traverse it we must consume a certain number of liters of gasoline.

codeforcescompetitive-programming
CF 104243D - Музыкальный фестиваль

I’m missing the actual problem statement for Codeforces 104243D - “Музыкальный фестиваль”, so I can’t reliably reconstruct the task or derive a correct algorithm.

codeforcescompetitive-programming
CF 104243C - Королевская задача

I can’t reliably write a correct editorial for “Codeforces 104243C - Королевская задача” because the actual problem statement is missing from your prompt. Right now I only have the title, but no definition of the input, output, or rules.

codeforcescompetitive-programming
CF 104243A - Ещё одна $n$-мерная шоколадка

I can’t write a correct editorial for this yet because the actual problem statement is missing from your prompt.

codeforcescompetitive-programming
CF 104244D - Путь домой

The problem describes a traveler who starts in city 1 with some initial amount of money and wants to reach city n using directed flights. Each flight has a cost in money, and can only be taken if the traveler currently has at least that cost available.

codeforcescompetitive-programming
CF 104244B - Покупка подарков

The problem statement for “Codeforces 104244B - Покупка подарков” is missing from your prompt, so there’s no reliable way to reconstruct the task or its constraints.

codeforcescompetitive-programming
CF 104244C - Поиск фальшивых монет

I’m missing the actual problem statement for Codeforces 104244C - “Поиск фальшивых монет”, so I can’t reliably reconstruct the intended solution or write a correct editorial.

codeforcescompetitive-programming
CF 104244A - Задачечка на подстрочечки

I can’t write a correct Codeforces editorial for this yet because the actual problem statement is missing. Right now I only have the title “Задачечка на подстрочечки” (“a small problem about substrings”), but that’s not enough to reconstruct…

codeforcescompetitive-programming
CF 106369L - Rope Without Knots

We are given a set of points in the plane, called pins. We must output a closed polyline path, meaning a sequence of points that starts and ends at the same coordinate. The path has two topological requirements.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 239

Let $G = (V,E)$ and let $g$ denote the family of edges encoded in the sense of Exercise 236(e), so that $g = \bigcup_{u-v \in E}(e_u \sqcup e_v)$ and the family of independent sets is expressed by a f...

taocpmathematicsalgorithmsvolume-4medium
CF 104508I - IMO Problem

We process rows from top to bottom while maintaining the range of column positions that some valid path can occupy at that row. 1. Initialize the reachable interval as L = 1 and R = 1 because at the top there is only one starting position. 2.

codeforcescompetitive-programming
CF 104508B - Bogosort

The task gives a sequence of integers representing a permutation-like array. The goal is to produce a correctly ordered version of this sequence, where elements are arranged in non-decreasing order, and print that final arrangement.

codeforcescompetitive-programming