brain

tamnd's digital brain — notes, problems, research

41641 notes

CF 104295H - Рыбалка

We are given a fishing session defined by a single time interval within one day. Alongside this, we have a large set of fish “activity intervals”, each labeled with a species name. During an activity interval of a species, that fish is actively biting.

codeforcescompetitive-programming
CF 104295G - Порадуй Тофслу

We are given a collection of tower heights. There are $n$ towers, where $n$ is guaranteed to be odd, and each tower has some initial height. We are also given $k$ extra unit cubes. Each cube can be added to exactly one tower, increasing its height by one.

codeforcescompetitive-programming
CF 104295F - Осторожные Хатифнатты

We are given two configurations of the same number of points on an integer grid. Think of them as two drawings of indistinguishable particles placed on lattice points. The particles can move, but only through a very specific collective operation.

codeforcescompetitive-programming
CF 104295E - Снусмумрик и Клипдассы

There are 30 independent positions, each associated with a weight equal to twice its index. Over a sequence of seconds, each position can experience at most one event per second: the occupant either enters its hole, leaves it, or stays unchanged.

codeforcescompetitive-programming
CF 104295D - Семья Мюмлы

We are given a fixed collection of existing family names, each written as a string of lowercase letters and hyphens. Then we are given several candidate names for a newborn. For each candidate, we must decide whether it is acceptable. A candidate is rejected in two situations.

codeforcescompetitive-programming
CF 104295B - Spring cleaning

We are given a line of houses, each with a fixed height. A resident who lives in house i wants to reach their own roof starting from the ground, but movement is constrained by a single ladder of fixed length. A ladder of length L allows two kinds of actions.

codeforcescompetitive-programming
CF 104295A - Пирог-часы

The problem describes a circular cake that behaves like a clock. The cake is first cut at noon, and then a sequence of people arrive at fixed integer hours between 12 and 24. Each arrival creates a cut at that hour, and the cake is divided into segments between consecutive cuts.

codeforcescompetitive-programming
CF 104295C - Ракушки Муми-мамы

We are given a list of flower beds, each associated with a number of shells. For the i-th bed, there are ai shells that must all be used to form a decorative border.

codeforcescompetitive-programming
CF 104301A - Reading Books

We are given multiple independent scenarios. In each scenario, a reader has a sequence of reading amounts over days and a list of book lengths. Each day contributes a certain number of pages that can be used to progress through books in order.

codeforcescompetitive-programming
CF 104301F - OR Pairs

We are counting ordered pairs of integers $(a, b)$ where $0 le a le b$, but not all pairs are valid. The restriction comes from a bitwise condition: when we take the bitwise OR of $a$ and $b$, the result must not exceed $n$.

codeforcescompetitive-programming
CF 104301E - Again Last Digit

We are asked to evaluate a large sum where each term combines Fibonacci numbers and factorial exponents, but we only care about the last digit of the result. For each test case, an integer $n$ is given. We conceptually build the value $$S = f0^{0!} + f1^{1!} + f2^{2!

codeforcescompetitive-programming
CF 104301D - Good Sets

We are given multiple independent test cases. In each test case, there is an array of integers and a threshold value $k$. We call a set of values “good” if the largest and smallest elements in that set differ by at most $k$.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 202

We restart the argument from the actual structure of Knuth’s swap-in-place algorithm (Exercise 147) and then isolate exactly what changes in the ZDD setting.

taocpmathematicsalgorithmsvolume-4medium
CF 104301B - Two Squares

We are given many independent queries. Each query provides a non-negative integer $n$, and we must count how many integers $x$ in the range from $0$ to $n$ can be written as the sum of two integer squares, meaning $x = a^2 + b^2$ for some integers $a$ and $b$.

codeforcescompetitive-programming
CF 104301C - Lucky Numbers

We are given a very large integer written in decimal form, and for each such number we need to count how many positive integers not exceeding it consist only of the digits 4 and 7.

codeforcescompetitive-programming
CF 104303J - 组队

We are given a pool of students, each student knows a subset of up to 60 topics. A valid team is any subset of students such that two conditions are simultaneously satisfied: every topic from 1 to p is covered by at least one team member, and for each topic, at most one team…

codeforcescompetitive-programming
CF 104303I - 小黑的鸡脚plus

We are given a binary string, where each position is either 0 or 1. We are allowed to change at most k zeros into ones.

codeforcescompetitive-programming
CF 104303E - 读中国数字

Let $x in [0,1)$ have ternary expansion $x = 0.x1 x2 x3 cdots quad (xj in {0,1,2}),$ where nonterminating representations are used. Define $omega = e^{2pi i/3}$, so $omega^3 = 1$ and $1 + omega + omega^2 = 0$.

codeforcescompetitive-programming
CF 104303H - 我爱XTU

We are given a string made only of the characters X, T, and U. For each test case, we need to count how many substrings have the property that the number of X, T, and U characters inside that substring are all equal.

codeforcescompetitive-programming
CF 104303G - 空气扑克

We are given a two-versus-two game where each round reduces to a comparison between two independent “targets” produced by the two main players, Mo and Larro. In each round, Mo and Larro each pick one number from their personal hand. These numbers become target sums.

codeforcescompetitive-programming
CF 104303F - 您有一封新邮件待接收

We are given a directed network of people where each person knows the addresses of some other people. When someone receives a message, they immediately forward it to everyone they know. The process starts from a specific person and repeats indefinitely.

codeforcescompetitive-programming
CF 104303D - "逆"天求和

For each query, we are given a prime number $p$. We look at all integers from $1$ to $p-1$, and for each such integer $a$, we compute its multiplicative inverse modulo $p$. That means we find a number $b$ in the range $[1, p-1]$ such that $a cdot b equiv 1 pmod p$.

codeforcescompetitive-programming
CF 104303B - 熙巨打票

We are given a ticket-printing system with two identical machines that can be used to generate reimbursement slips. Each machine can produce at most one ticket per operation, and after producing a ticket it becomes unavailable for a cooling period of a minutes.

codeforcescompetitive-programming
CF 104303C - 三元分配

We are given three groups of employees with sizes A, B, and C. Every employee must be placed into pairs, meaning each employee is matched with exactly one other employee, and no one is left unmatched.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 201

A projection function $x_j$ corresponds to the Boolean function that is $1$ exactly on those assignments where the $j$-th variable is $1$.

taocpmathematicsalgorithmsvolume-4medium
CF 104303A - 签到啦~

We are given multiple independent scenarios. In each scenario, a student starts with a fixed number of items that must be carried, and there are several checkpoints along a path.

codeforcescompetitive-programming
CF 104304H - Toxel 与帕底亚地区

We are given a directed graph with possibly multiple edges between the same pair of vertices and also self loops. Each directed edge represents a single-step move between cities.

codeforcescompetitive-programming
CF 104304I - Circle God

We are given a binary sequence arranged on a circle. Each position contains either 0 or 1, and indices wrap around so that position n−1 is adjacent to position 0.

codeforcescompetitive-programming
CF 104304G - Toxel 与二维回文串

We are given a rectangular grid of lowercase letters. From this grid, we can choose any sub-rectangle by selecting a contiguous block of rows and a contiguous block of columns.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 200

Let $F = \mathrm{MUX}(f,g,h)$ denote the Boolean function defined by selecting $g$ when $f=1$ and selecting $h$ when $f=0$, so that F = (f \wedge g)\ \vee\ (\neg f \wedge h).

taocpmathematicsalgorithmsvolume-4medium
CF 104304F - qaq

We are given a string composed only of the characters q and a. We are allowed to insert exactly x additional characters, each of which can independently be either q or a, at arbitrary positions in the string.

codeforcescompetitive-programming
CF 104304E - 区间匹配

We are given a collection of static segments on a number line, each segment having integer endpoints within a bounded universe up to $L$.

codeforcescompetitive-programming
CF 104304D - Oshwiciqwq 与氪金手游

We are given a sequence of $n$ independent “draws”. In the $i$-th draw, we choose an integer score $xi$ uniformly from the range $[0, ai]$, where $ai < k$. After each draw, we maintain a running prefix sum of all chosen values.

codeforcescompetitive-programming
CF 104304C - Toxel 与宝可梦野餐

We are asked to construct up to 20 distinct integer vectors in at most three dimensions. Each vector has non-negative coordinates up to 10^9. After constructing them, we look at the sum of all vectors.

codeforcescompetitive-programming
CF 104304A - 除奇致胜

We are given a lineup of enemy units, each with an integer attack value. A special effect card removes every unit whose attack is odd after all modifications are applied. Before using this card, we are allowed to cast a collection of single-use spells.

codeforcescompetitive-programming
CF 104304B - 异或与最大公因数

We are given two intervals of positive integers, one for a and one for b. We need to count how many pairs (a, b) can be formed such that a is chosen from the first interval and b from the second interval, and the pair satisfies a bitwise and arithmetic constraint: the XOR of a…

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 20

Let $t(m)$ denote the parity of the binary digit sum of $m$, so that $t(m)=0$ when $m$ has an even number of 1s in binary representation and $t(m)=1$ otherwise.

taocpmathematicsalgorithmsvolume-4simple
CF 104308K - An Incantation Long Remembered

We are given several “ability strings”, where each ability is made of distinct characters and no character appears in more than one ability.

codeforcescompetitive-programming
CF 104308J - Traveling Alien Masud

The earth map can be modeled as a directed graph where each city is a node and each one-way road is a directed edge.

codeforcescompetitive-programming
CF 104308I - Colorful Queries

We are given a vertical stack of items, where each item has a color. The top of the stack is position 1, and positions increase as we go downward. A sequence of queries is performed on this stack.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 199

A ZDD represents a family of finite sets over an ordered universe of items $x_1 < x_2 < \cdots$.

taocpmathematicsalgorithmsvolume-4medium
CF 104308H - Wonder Island

We are tracking how a quantity evolves over time when a deterministic growth rule starts applying only after a delay. Saimon begins with some number of identical units, specifically pairs of Emm coins.

codeforcescompetitive-programming
CF 104308G - Keyboard Warrior Roshid

We are given multiple test cases. Each test case contains a single lowercase string representing text Roshid wants to type. However, his keyboard has a hardware failure: a specific group of letters no longer works, corresponding to the bottom row of a standard keyboard layout.

codeforcescompetitive-programming
CF 104308F - Xored Pairs

We are asked to construct an array of length n where each value is a 30-bit non-negative integer. The construction must satisfy a set of constraints that relate elements either by inequality to a fixed value or by XOR relationships between pairs.

codeforcescompetitive-programming
CF 104308E - Unwanted Divisors Again

We are given an integer $m$ and an array $a$. The task is to look at every divisor $d$ of $m$, and decide whether $d$ is “safe” or “bad”. A divisor $d$ is considered bad if there exists at least one array element $ai$ such that $d$ divides $ai$. Otherwise, $d$ is safe.

codeforcescompetitive-programming
CF 104308D - Unwanted Divisors

We are given a sequence of integers and then a sequence of queries. For each query value $b$, we are interested in all positive divisors of $b$. Among those divisors, some may appear inside the given array, and others may not.

codeforcescompetitive-programming
CF 104308A - Rain Rain Go Away, Come Again Another Day!

The input describes several independent “landscapes” made of vertical stacks of unit-width bricks. Each landscape is an array where the value at position i represents how tall the wall is at that point. When rain falls, water can accumulate in the gaps between taller walls.

codeforcescompetitive-programming
CF 104308C - Optimal Pairing

We are given several test cases. In each test case, there is an even-length array. We must partition the array into disjoint pairs so that every element belongs to exactly one pair. For each pair, its contribution to the answer is the larger of the two values inside that pair.

codeforcescompetitive-programming
CF 104308B - Signature Nightmare

Each test case describes a process of completing identical forms, where each form requires collecting signatures from several offices. For every office i, a single form requires ai signatures from that office.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 198

Let $u$ and $v$ be ZDD nodes representing families of sets for Boolean variables ordered as $x_1 < x_2 < \cdots < x_n$.

taocpmathematicsalgorithmsvolume-4medium
CF 104311E - Pre-minimum Score

We are given a multiset of integers where value i appears exactly mi times. From this multiset we consider every possible permutation of the full expanded array.

codeforcescompetitive-programming
CF 104311F - Span Flip

We are given two binary grids of the same size, call them the starting grid and the target grid. The only allowed move is to choose a contiguous segment of length l either horizontally within a row or vertically within a column, and flip all bits in that segment.

codeforcescompetitive-programming
CF 104311D - Big Xor Sum

We are given an array of length n where the value at position i is i-1, so the array is fixed as [0, 1, 2, ..., n-1]. The task is to consider every contiguous subarray, compute the bitwise XOR of its elements, and sum all those XOR results.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 197

Let $f$ be a Boolean function on variables $x_1,\dots,x_n$, and let its BDD be given in the ordered and reduced form described in Section 7.

taocpmathematicsalgorithmsvolume-4medium
CF 104311B - Strange Shuffle

We start with an array that initially contains the numbers from 1 to n in order. Then we repeatedly apply a fixed sequence of operations until only one element remains.

codeforcescompetitive-programming
CF 104311C - c0=c1

We are given two binary arrays of equal length. From each array we are allowed to pick one contiguous segment, and the only restriction on each segment is that its length must fall inside a given range.

codeforcescompetitive-programming
CF 104311A - Maximum of n Integers

We are given several test cases. In each test case we receive an array of integers, and we are asked to analyze a faulty piece of code that tries to compute the maximum value of the array.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 196

Let variables $x_1,\dots,x_n$ be interpreted as characteristic bits of a subset $S \subseteq {1,\dots,n}$, where $x_i=1$ means $i \in S$.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104312L - 3 Reasons to Eat Potato Chips

We are given three piles of chips. On each turn, a player can either take chips from exactly one pile, choosing any positive number up to the size of that pile, or perform a global move where they take the same positive number of chips from all three piles simultaneously, but…

codeforcescompetitive-programming
CF 104312J - No Game No Life

We are given a base string s of length N, where each position has an associated weight ai. From this string, we are allowed to “erase” characters by choosing a subset of letters from the alphabet.

codeforcescompetitive-programming
CF 104312K - Monster-Slayer

We are given a line of monsters, each with a power value, positive or negative. Saitama can choose any consecutive segment of these monsters and defeat exactly that group.

codeforcescompetitive-programming
CF 104312I - Square Jutsu!

We are given a fixed $N times N$ grid of elevations. Every query gives an interval $[a, b]$, and we must find the largest axis-aligned square subgrid such that every cell inside it has elevation within that interval. The answer is the area of that square, not its side length.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 195

Let $M_2(x_1,x_2,x_3,x_4)$ denote the 4-way multiplexer.

taocpmathematicsalgorithmsvolume-4medium
CF 104312G - Anime Trading

We are given a multiset of cards, where each card has an integer label called a quirk number. From this initial collection, we want to end up with a very strict final collection: it must contain exactly one card of each quirk number from 1 up to some chosen value K, and…

codeforcescompetitive-programming
CF 104312H - My Hero Photographia

We are given a rectangular grid of integers representing pixel intensities. The grid behaves like a torus, meaning moving off any edge wraps around to the opposite side.

codeforcescompetitive-programming
CF 104312F - Dragon Ball

We are maintaining a dynamic collection of “habitats”, where each habitat stores multiple named dragons, and every dragon has a unique size value. The system supports two operations over time. One operation inserts a new dragon into a chosen habitat.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 194

Let $f(x_1,\ldots,x_n)$ have truth table $\tau$, and let $f^Z$ have truth table $\tau^Z$.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104312E - Attack on Titans

We are given three independent walls, each described as an array of section heights. Each array contains $n$ integers, where each integer represents the height of a segment in that wall.

codeforcescompetitive-programming
CF 104312D - Love is War

We are given a collection of short text messages, each independent from the others. For every message, we need to decide whether it represents a “battle” or just casual conversation.

codeforcescompetitive-programming
CF 104312B - Snack Time

We are given a tree of houses. Each house initially has a certain number of friends living there. Over time, two kinds of events happen.

codeforcescompetitive-programming
CF 104312A - Dojo Duel

We are given a list of students, where each student comes with a name and four numerical attributes: kicking skill, magic skill, speed, and demon slaying skill. The task is to produce a ranking of all students based on a strict multi-level priority system.

codeforcescompetitive-programming
CF 104312C - Milk Cow

The task is a pure transformation problem on text. We are given an ASCII picture of Bessie the cow, represented as multiple lines of characters. We must output what the picture looks like after being rotated 180 degrees.

codeforcescompetitive-programming
CF 104313O - Бюджетное путешествие

We are given an undirected connected graph representing cities and bidirectional roads. Some roads have a special property: if removing such a road would disconnect the graph, then that road is considered expensive.

codeforcescompetitive-programming
CF 104313N - Сокровище

We are given a hidden position on a one-dimensional strip of cells numbered from 1 to n, where n can be as large as 10^9. Exactly one cell contains a buried treasure. We can interact with the judge by choosing a cell i and effectively placing a detector there.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 193

Let $f(x_1,\ldots,x_n)$ have truth table $\tau$, and let $f^Z$ have truth table $\tau^Z$.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104313L - Почему карты в другом порядке?

We are given a final sequence of cards that appeared on a table during a game. In the game, the players start with a hidden initial deck, and repeatedly remove either the top or the bottom card of the deck.

codeforcescompetitive-programming
CF 104313M - Участок дороги

We are given a fixed 4×4 grid made of two types of cells: road cells represented by dots and fence cells represented by hashes. The grid encodes a small road junction.

codeforcescompetitive-programming
CF 104313K - Массив и степени двойки

We are given an array of integers, and we are allowed to modify it using a very specific operation. Each position in the array can be used at most once, and when we use position i, we multiply the value at that position by i.

codeforcescompetitive-programming
CF 104313J - MEX vs. MID

We are given a permutation of size $n$, meaning it contains every integer from $0$ to $n-1$ exactly once. For every contiguous subarray, we compute two values. The first value is the mex of the subarray, which is the smallest non-negative integer missing from that subarray.

codeforcescompetitive-programming
CF 104313I - Метро

We are given a collection of straight lines on the plane, each defined by an equation of the form $y = kx + b$. We are not asked to analyze intersections between arbitrary pairs of lines or to find a geometric intersection point.

codeforcescompetitive-programming
CF 104313H - Добавление и GCD

We are given an array of integers that is modified over time, and we must answer queries about its subarray GCD. Two operations happen online. The first operation adds a fixed value to every element in a prefix or a range.

codeforcescompetitive-programming
CF 104313G - Две цифры

We imagine a huge infinite tape formed by writing the integers from 1 up to 10¹⁰ in order, without any separators. So the string begins as 1234567891011121314... and continues by appending each next integer in decimal form.

codeforcescompetitive-programming
CF 104313F - Чётно-нечётные прибавления

We are given several independent test cases. In each test case there is an array of integers, and then a sequence of operations.

codeforcescompetitive-programming
CF 104313E - Урок физкультуры

We are given a group of $n$ students who must be split into exactly two teams. Both teams must be non-empty. There is also a lower bound $k$, meaning each team must contain at least $k$ students.

codeforcescompetitive-programming
CF 104313D - Делимые числа

We are given two disjoint integer intervals: one interval for x and one interval for y. Specifically, x must be chosen strictly greater than a and at most c, and y must be strictly greater than b and at most d.

codeforcescompetitive-programming
CF 104313B - Каштаны

We are given a group of n children who each collected some number of chestnuts and then placed them into a single pile. The first child in order, Sasha, puts his chestnuts into the pile first. Every next child contributes twice as many chestnuts as the previous child.

codeforcescompetitive-programming
CF 104313C - Я календарь

We are given a single month where the weekday of one specific day is known. That known anchor consists of a day number between 1 and 31 and a weekday name such as Monday or Sunday. Using this anchor, we must determine the weekday of another day in the same month.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 192

The Z-transform is defined recursively on binary strings with special behavior depending on whether the second argument is a block of zeros, identical to the first half, or a general concatenation cas...

taocpmathematicsalgorithmsvolume-4math-medium
CF 104313A - Ливси и <<Шашматы>>

The problem statement is not included in your message, so there isn’t enough information to reconstruct what needs to be solved.

codeforcescompetitive-programming
CF 104314J - Refactoring

We are given two non-negative integers, a and n. A program starts with a value b = 0 and then applies the same update step exactly n times: b := (b - a) & a Here subtraction and bitwise AND are done on 64-bit integers using two’s complement arithmetic.

codeforcescompetitive-programming
CF 104314I - Cutting a Chain

We are given a chain of $N$ numbered rings arranged in a line. The traveler wants to be able to pay exactly one ring per day for $N$ consecutive days, but he is allowed to cut the chain beforehand into separate usable pieces.

codeforcescompetitive-programming
CF 104314H - Game Case

We are given a small set of cards, each card showing a pair of integers. One of these cards is secretly the “prize” card. The first player sees only the left number of that card, the second player sees only the right number.

codeforcescompetitive-programming
CF 104314F - Fragment

We are repeatedly building a growing sum of very specific numbers. The k-th summand is a number made of a single digit 2 at both ends, with zeros filling the middle as the number grows, starting from 2, then 22, then 202, then 2002, and so on.

codeforcescompetitive-programming
CF 104314G - Unusual Calculator

We are given a state consisting of two integers, and we are allowed to transform this pair using exactly three reversible operations. One operation subtracts the second value from the first, another adds the second value to the first, and the third swaps the two coordinates.

codeforcescompetitive-programming
CF 104314D - Antique Clock

We are looking at a continuous analog clock where the hour and minute hands move smoothly rather than jumping once per minute. The minute hand completes a full circle in 60 minutes, while the hour hand completes a full circle in 12 hours.

codeforcescompetitive-programming
CF 104314E - Bridge Construction

We are given a grid that represents an archipelago. Each cell is either land, marked as 1, or water, marked as 0. Any two land cells that touch up, down, left, or right belong to the same island, so the grid naturally splits into multiple connected components of 1s.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 191

I can write the full editorial, but I need the actual problem statement in a clean, uncorrupted form first.

taocpmathematicsalgorithmsvolume-4hm-medium
CF 104314B - Inequalities

We are given a row that alternates between empty positions and fixed comparison symbols. There are $N+1$ positions that must be filled with distinct numbers from 1 to $N+1$, and between every two neighboring positions there is exactly one constraint, either “<” or “”…

codeforcescompetitive-programming
CF 104314A - Natasha and Cats

We are told that Natasha has cats, and each cat behaves in a very rigid way during the night. Every time a cat “acts”, it produces exactly the same effect: a fixed number of items fall, from level A down to level B, and Natasha hears a total of N falling events in total.

codeforcescompetitive-programming
CF 104314C - Regular expression

We are asked to construct a single regular expression over decimal digits that accepts exactly those integers whose digits can be rearranged to form a number divisible by 6. A number is divisible by 6 if and only if it is divisible by 2 and by 3.

codeforcescompetitive-programming