brain

tamnd's digital brain — notes, problems, research

41230 notes

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
CF 104316L - Новое имя Юры

We are given a string built from only two characters, a caret and an underscore. We are allowed to insert additional characters anywhere in the string, but we are not allowed to delete or reorder existing ones.

codeforcescompetitive-programming
CF 104316J - Мясник

We are given a multiset of axis-aligned rectangles with fixed orientation. Each rectangle has a height and a width, and no rotation is allowed, meaning a rectangle (a, b) is distinct from (b, a) unless both coordinates are equal.

codeforcescompetitive-programming
CF 104316K - Миша и яблоки

We are given several independent scenarios. In each scenario there are n shops visited in order, and there are m possible apple types. Each shop may contain some subset of apple types.

codeforcescompetitive-programming
CF 104316I - Досмотр перед вылетом

We are given an array of integers and we want to compute the maximum possible subarray sum, but with one extra freedom: before choosing the subarray, we are allowed to reverse at most one contiguous segment of the array.

codeforcescompetitive-programming
CF 104316H - Дороги в Ельце

We are given an undirected multigraph with up to 2000 vertices and 2000 edges. Each edge has an identity from 1 to m. A hidden subset of these edges is “good” (repaired roads), and this subset is fixed for the entire interaction.

codeforcescompetitive-programming
CF 104316G - Конструктивная задача

We are given an array of nonnegative integers. We are allowed to perform exactly one operation: choose a contiguous segment of the array and overwrite every element in that segment with a single chosen nonnegative value.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 190

Let $Q(f)$ denote the number of nodes in a reduced ordered decision diagram when sharing identical subgraphs, where the model allows both kinds of decomposition used in the section: Shannon decomposit...

taocpmathematicsalgorithmsvolume-4medium
CF 104316F - Лисица и полный обход древа

We are given a tree, meaning a connected graph with no cycles. A fox starts at some vertex and can move in a single jump using an unusual rule: from a vertex v, it may jump to a vertex u either if there is an edge directly connecting them, or if there exists some intermediate…

codeforcescompetitive-programming
CF 104316E - Реклама

We have two rows of points aligned above and below a single horizontal street. At each integer position $i$ from 1 to $n$, there is a café on the upper side with weight $ai$ and a café on the lower side with weight $bi$.

codeforcescompetitive-programming
CF 104316D - Тяп-ляп, фигак, в релиз!

We are working with strings of fixed length n, but the real object of interest is not a single string. Instead, we maintain a dynamic set of strings over the alphabet {a, b, c, d}. Each update either inserts a string into the set or removes it.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 19

The reviewer correctly identifies that the previous argument failed because it treated $m_k$ as if it ranged over arbitrary subset sums without justifying how this arises from Algorithm B.

taocpmathematicsalgorithmsvolume-4medium
CF 104316C - Невероятные приключения ДжоДжо

We are given a binary string and we build a square matrix whose rows are all cyclic shifts of that string. Row zero is the string itself, row one is shifted right by one position, row two is shifted right by two positions, and so on until row n minus one.

codeforcescompetitive-programming
CF 104316A - Блинские перестановки...

We are given a system of $n$ positions, each initially holding a student. The initial arrangement is unknown and is represented by a permutation $b$.

codeforcescompetitive-programming
CF 104316B - Очередная задача про запросы на дереве

We are given a rooted tree with root fixed at vertex 1. Each vertex stores two attributes: a label t[v], which groups vertices into types, and a jump parameter d[v], which defines how far a token should move upward along the path to the root.

codeforcescompetitive-programming
CF 104317I - I like UNO !

Four players sit in a fixed order and repeatedly play cards against a shared discard pile whose current top card determines what is legal to play.

codeforcescompetitive-programming
CF 104317J - Juxtaposed brackets

We are given a recursively defined family of strings built from a single kind of primitive bracket structure. The base object is the simplest valid pair “()”.

codeforcescompetitive-programming
CF 104317H - How to know the function

The problem statement is missing from your prompt, so I don’t have enough information to write a correct editorial.

codeforcescompetitive-programming
CF 104317E - Eliminate suspicion

We are given two sets of points in a plane, each point also having a time coordinate. The first set represents people, where each person has a recorded position at a specific time. The second set represents crime events, each occurring at a position and time.

codeforcescompetitive-programming
CF 104317D - Deliver the string

We are given two strings, $A$ and $B$. We start with an empty string $C$, and we are allowed to build $C$ by repeatedly copying a substring from $A$ and appending it to the end of $C$.

codeforcescompetitive-programming
CF 104317G - Golden jade matrix checker

I can’t write a correct Codeforces editorial without the actual problem statement. Right now the prompt only includes the template, so there’s no information about what the “golden jade matrix checker” is supposed to verify, what the input looks like, or what conditions…

codeforcescompetitive-programming
CF 104317F - Fill out the multiple choice questions

The problem statement is missing from the prompt, so there’s no way to correctly reconstruct the task, constraints, or intended solution.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 189

Let $B(f)$ and $Z(f)$ denote the reduced ordered BDD and reduced ordered ZDD of a Boolean function f(x_1,\ldots,x_n), constructed with the same variable ordering.

taocpmathematicsalgorithmsvolume-4medium
CF 104317B - Bespread with chequers

We are asked to count how many ways we can completely tile a board that has exactly two rows and $n$ columns. Each tile comes from a fixed set: a domino of size $1 times 2$, which can be placed horizontally or vertically, and a square block of size $2 times 2$.

codeforcescompetitive-programming
CF 104317A - Antiamuny wants to learn binary search

We are given a procedure that behaves exactly like a standard binary search, except instead of returning the position of a target value, it returns how many loop iterations are executed until the search finds the target element.

codeforcescompetitive-programming
CF 104317C - Converse the string

I don’t have the actual statement of Codeforces 104317C (“Converse the string”) available in your prompt, so I can’t safely reconstruct the correct editorial without risking inventing rules, which would defeat the purpose of a proper solution write-up.

codeforcescompetitive-programming
CF 104322M - 一元四次方程

We are asked to output five integers $a, b, c, d, e$ within the range $[-10, 10]$, with $a neq 0$, such that the quartic polynomial $$a x^4 + b x^3 + c x^2 + d x + e$$ has no real roots. In other words, no real number $x$ should make the expression equal to zero.

codeforcescompetitive-programming
CF 104322L - 投票

I don’t have the actual problem content for “Codeforces 104322L - 投票” in your prompt (the statement section is empty), so there’s nothing concrete to base an editorial on.

codeforcescompetitive-programming
CF 104322K - 卡片游戏

I don’t have enough information about Codeforces 104322K - 卡片游戏 to write a correct editorial. Right now the statement section is empty, so there is no way to reliably reconstruct: - what the cards represent, - what operations are allowed, - what the players or rules…

codeforcescompetitive-programming
CF 104322J - Bit Operation

I don’t have the actual statement of Codeforces 104322J - Bit Operation beyond the title, so I can’t reliably reconstruct the problem or derive a correct solution/editorial without guessing.

codeforcescompetitive-programming
CF 104322I - 海选

I can’t write a correct editorial for this problem yet because the statement you provided is effectively empty. Right now we only know the title “海选”, but there is no description of the input, output, constraints, or even what is being computed.

codeforcescompetitive-programming
CF 104322H - 距离

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 “距离” (“Distance”), but there are no definitions of the input, output, or constraints.

codeforcescompetitive-programming
CF 104322G - Among the Petals Dancing in the Wind

I can’t write a correct editorial here because the actual problem content is missing. Right now the “Problem Statement” section contains no description of the task, inputs, or outputs.

codeforcescompetitive-programming
CF 104322D - Tadokoro Flipping

We are given a line of cells, each cell containing a binary state that can be interpreted as a tile being either on or off. A move consists of selecting a position and flipping it in a way that affects the configuration of the line according to a fixed rule from the problem.

codeforcescompetitive-programming
CF 104322F - The Threshold of Masterpieces

I can’t reliably write a correct editorial yet because the actual problem statement content is missing. Right now we only have the title “The Threshold of Masterpieces”, but no description of what the input/output means, constraints, or operations.

codeforcescompetitive-programming
CF 104322E - Mabinogion

I can’t reliably write a correct editorial yet because the actual problem statement for Codeforces 104322E - Mabinogion isn’t included (only the title and empty input/output sections are present).

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 188

In the ZDD representation used in this section, a Boolean function is identified with the family of subsets on which it is true.

taocpmathematicsalgorithmsvolume-4medium
CF 104322B - Pure Hacking Attempt (ULL version)

I can’t write a correct editorial here because the actual problem content is missing. What you provided only contains the title and empty input/output sections, so there is no information about what is being computed, what the operations are, or what the constraints look like.

codeforcescompetitive-programming
CF 104322A - Keep Marching on Instead of Running off

I can’t produce a correct editorial for this yet because the actual problem content is missing. Right now I only see the title (“Keep Marching on Instead of Running off”), but there is no statement, input/output format, or constraints.

codeforcescompetitive-programming
CF 104322C - If I Could Be a Constellation

I can’t write a correct editorial yet because the actual problem statement is missing. Right now you’ve only provided the title and empty Input/Output sections, so there is no way to know what the task is (data structures, graph, strings, etc.

codeforcescompetitive-programming
CF 104324K - Postal code

We are given a set of $n$ distinct postal codes, each written as a 5-digit string (leading zeros are allowed, so every code can be treated as a fixed-length string of length five over digits $0$ to $9$). Think of each postal code as a node in a graph.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 187

Fix variable order $x_1 < x_2$.

taocpmathematicsalgorithmsvolume-4medium
CF 104324L - Dream Team

We are trying to assemble a “team” from two pools of students. From the undergraduate pool we must choose exactly three distinct students, and the quality of this team is the sum of their strength values. From the graduate pool we choose exactly one student to act as a coach.

codeforcescompetitive-programming
CF 104324I - Broken sword

We are given a line of monsters, each with a strength value. Daniyar fights them using a sword that can remove a contiguous block of monsters in a single swing, but only up to a fixed length k in the current remaining lineup.

codeforcescompetitive-programming
CF 104324H - SDUcell

A user is walking through a city along a route made of straight street segments aligned with axes. Each segment is either purely horizontal or purely vertical, so at any moment the user’s position moves linearly in one coordinate while the other stays fixed.

codeforcescompetitive-programming
CF 104324J - Chef Coder

We are given a line of participants, each with two thresholds: a lower requirement $ai$, and a higher requirement $bi$, where $ai < bi$. Each participant becomes “satisfied” once they receive at least $ai$ steaks, and becomes “full” once they receive at least $bi$ steaks.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 186

In a ZDD, each level corresponds to a variable, and a node labeled $k$ represents a decision on $x_k$, where the low edge excludes the variable and the high edge includes it in the represented family...

taocpmathematicsalgorithmsvolume-4simple
CF 104324G - GCD Encryption

We are given a multiset of integers, originally arranged in some unknown order. The only structural clue about the original ordering is not about adjacency or sorting, but about a global arithmetic property tied to indices: if we take each element and add its position in the…

codeforcescompetitive-programming
CF 104324F - Lost in the Jungle

We are given a tree with n vertices, so there is exactly one simple path between any two nodes. Each vertex has a degree, and a traveler standing at a vertex chooses uniformly among its adjacent vertices and moves there in one step. This defines a simple random walk on the tree.

codeforcescompetitive-programming
CF 104324D - UFC

Two players independently choose an ordering of the same set of fighters numbered from 1 to n, where a larger number always represents a stronger fighter. They then play n rounds.

codeforcescompetitive-programming
CF 104324E - Cultural Dissonance

We are given a collection of $n$ toppings, each contributing a signed value to taste. A “dish” is defined by choosing any subset of these toppings, and its taste is simply the sum of values of the chosen elements.

codeforcescompetitive-programming
CF 104324A - SDU Open

We are asked to assign three types of medals to a fixed number of participants in a contest. Every participant can receive a medal, and medals come in a strict hierarchy: gold is best, then silver, then bronze. The rules do not directly give exact counts.

codeforcescompetitive-programming
CF 104324C - Serial Representative

We are given a binary string and a transformation that compresses it into maximal runs of equal characters. Each maximal run is called a “series”, so the string is decomposed into alternating blocks of consecutive zeros and ones.

codeforcescompetitive-programming
CF 104324B - From decreasing to increasing

We are given a permutation of size $n$ that initially appears in strictly decreasing order. The goal is to transform it into increasing order using a very specific operation: we may pick a starting position $s$ and a block length $k$, then swap two adjacent segments of equal…

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 185

Let $f(x_1,\dots,x_n)$ be symmetric, so its value depends only on the Hamming weight w = x_1 + \cdots + x_n.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104325L - YsaeSort

We are working with an array that changes over time, and we are asked to support two kinds of operations on it. One operation permanently sorts a contiguous segment of the array, physically rearranging the elements in that range.

codeforcescompetitive-programming