brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 104285L - Linear Classifers

We are given a set of points in the plane with integer coordinates, with the guarantees that no two points coincide and no three are collinear.

codeforcescompetitive-programming
CF 104285J - Jewelry Box

The grid is a rectangular board where some cells contain jewels and all other cells are empty. A key restriction is that no two jewels are adjacent by an edge, which already forces the jewels into a kind of sparse, checkerboard-compatible pattern.

codeforcescompetitive-programming
CF 104285K - K-restricted Induced Subgraphs

We are given an undirected graph where each vertex carries a numeric weight. From this graph, we want to select a set of vertices such that two conditions hold simultaneously. First, the chosen vertices must form a connected induced subgraph.

codeforcescompetitive-programming
CF 104285G - Genetic Sequence Searching

We are given two long strings over an arbitrary ASCII alphabet. One string is a pattern we want to search for, and the other is a text where we want to locate approximate matches of that pattern.

codeforcescompetitive-programming
CF 104285H - Heritage in the PCCA Kingdom

The input describes a triangular lattice made of $n$ layers. Each layer contains a row of small triangular regions, and every small triangle contributes three boundary segments. Some of these segments are already in a “charged” state, while others are still uncharged.

codeforcescompetitive-programming
CF 104285I - Interval Cover

We are maintaining a multiset of intervals on a fixed segment from 0 to some integer limit $l$. Each interval contributes coverage to points on the line, and overlap is allowed.

codeforcescompetitive-programming
CF 104285F - Formidable Team

We are given a matrix of size $n times m$, where each row represents a participant and each column represents a skill. We must choose exactly $m$ different participants and assign each of the $m$ skill positions to a distinct chosen participant.

codeforcescompetitive-programming
CF 104285E - Exterior

We are given a weighted undirected graph with up to 100,000 nodes and 100,000 roads. Each road connects two districts and has a travel time cost.

codeforcescompetitive-programming
CF 104285D - Duo of Magicians

We are given a permutation of numbers from 1 to n. The goal is to sort this permutation into increasing order, but we are not allowed to output swaps directly in the order they will be executed.

codeforcescompetitive-programming
CF 104285C - Colorful Pictures

We start with a tree whose vertices are numbered from 1 to n. Initially, each vertex i carries a distinct color i, so the configuration is just the identity permutation placed on the nodes.

codeforcescompetitive-programming
CF 104285B - Buying Mascots

Brian walks through a line of stalls. At each stall he faces a choice between converting cash into a limited storage of tokens, or immediately spending tokens to obtain mascots.

codeforcescompetitive-programming
CF 104285A - ATCG

We are given a DNA strand written as a string over the alphabet {A, T, C, G}. Biology gives us a precise transformation rule for constructing the complementary strand: first reverse the original sequence because the two strands run in opposite directions, then replace each…

codeforcescompetitive-programming
CF 104287Q - Another Floors Problem

We are given a fixed list of positive integers $a1, a2, dots, an$. For any real number $x$, we form a value by taking each $ai x$, rounding it down to the nearest integer, and summing all these values. This produces a function $F(x)$.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 206

Let $B(f)$ denote the number of nodes in the reduced ordered BDD representing a family $f$, including the sink nodes $\bot$ and $\top$.

taocpmathematicsalgorithmsvolume-4math-research
CF 104287R - Bingo

Each test gives us a collection of $5 times 5$ bingo boards, one per player. Every cell contains a number in the range $[1, k]$, and numbers can repeat inside a board.

codeforcescompetitive-programming
CF 104287P - In Another World With My Range Query Problems

We are maintaining an array that changes over time, and we must answer two kinds of operations efficiently. The first operation asks for a special aggregate over a subarray.

codeforcescompetitive-programming
CF 104287O - Prefix queries

We maintain a long array of integers that changes over time. Each operation adds a value to every element inside a contiguous segment, and these changes persist permanently.

codeforcescompetitive-programming
CF 104287N - The Tree Problem Is Done For

We are given a weighted tree, meaning there are $N$ nodes connected by $N-1$ edges with no cycles, and each edge has a non-negative weight. From this tree we must select two paths such that they do not share any node.

codeforcescompetitive-programming
CF 104287L - Stuck on Bricks

We are given a geometric construction that behaves like an infinite tiling of identical 1 by 2 rectangles. Each horizontal row is the same pattern as the previous row, but shifted one unit to the right, which creates a staggered brick layout.

codeforcescompetitive-programming
CF 104287M - Magic labyrinth

We are given a directed graph with up to 100 vertices. Each vertex has a value that represents how much gas the explorer inhales if he is at that vertex during a second. The process evolves over time for exactly $k$ seconds. Initially the explorer starts at vertex 1.

codeforcescompetitive-programming
CF 104287K - That Time I Got Reincarnated As A String Problem

We are given a string that contains lowercase letters and wildcard characters. Each wildcard can be replaced independently by any lowercase letter.

codeforcescompetitive-programming
CF 104287J - Two and Three

We are given several independent test cases. In each test case there is an array of positive integers. Two players alternate turns, starting with Nino.

codeforcescompetitive-programming
CF 104287G - Daggers

We are simulating a one-dimensional movement from coordinate 0 to coordinate $n$, where moving costs exactly one second per unit distance and the speed is fixed.

codeforcescompetitive-programming
CF 104287I - Mountain Climbing Hard

We are given a sequence of elevations along a linear mountain path. Each index represents a position, and each value represents its altitude.

codeforcescompetitive-programming
CF 104287H - A Certain Scientific Tree Problem

We are working with a complete binary tree of height $d$. The tree is labeled in the standard heap-style way: node $1$ is the root, and every node $u$ has children $2u$ and $2u+1$ as long as they exist.

codeforcescompetitive-programming
CF 104287E - Cyclic Shifts

We are given two arrays of equal length, and we are allowed to modify the first array until it becomes identical to the second one. The cost model has two parts.

codeforcescompetitive-programming
CF 104287F - Greatest Common Mutiple

Each test gives three integers. Think of the first two numbers as defining a rule for which integers are “valid”: a number is valid only if it is divisible by both of them. The third number acts like a modulus cap that we care about only through remainders.

codeforcescompetitive-programming
CF 104287D - Multiplication Table

We are given an $N times N$ multiplication table where each cell $(i, j)$ contains the product $i cdot j$. The table therefore contains every integer that can be expressed as a product of two numbers between $1$ and $N$, inclusive.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 205

We represent a family $f$ as a reduced ordered decision diagram over variables $x_1,x_2,\dots,x_n$, using the conventions of Section 7.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104287B - Mountain Climbing Easy

We are given a sequence of altitudes along a path, and we walk through it from left to right. The task is to count how many “mountain climbs” appear in this sequence.

codeforcescompetitive-programming
CF 104287A - Are you busy?

The problem is not really about computation in the usual competitive programming sense. The input gives a single integer, called a testcase number, but that value does not affect the answer.

codeforcescompetitive-programming
CF 104287C - No Sweep

We are looking at a sequence of $n$ independent rounds of a game. In each round exactly one player wins. One special player is Thomas, and there are $k$ other competitors, so every round has $k+1$ possible winners.

codeforcescompetitive-programming
CF 104288L - Where Am I?

We are given a finite rectangular map of an otherwise infinite grid. Some cells contain markers and all other cells are empty. A person is placed at an unknown starting cell, but we only consider starting positions inside the given rectangle.

codeforcescompetitive-programming
CF 104288K - Take On Meme

The input describes a rooted tree where leaves are initial memes represented as 2D points. Every internal node represents a “vote” that merges its children into a new meme. At a leaf, the meme is fixed as a point $(x, y)$.

codeforcescompetitive-programming
CF 104288I - Spider Walk

We are given a circular spiderweb with n radial strands, numbered in order around the center. Between adjacent strands, there are m “bridges”, each placed at a unique distance from the center. A bridge connects two neighboring strands at that fixed radius.

codeforcescompetitive-programming
CF 104288J - Splitstream

We are given a directed acyclic network where every node either splits a single incoming sequence into two alternating streams or merges two incoming sequences into one alternating stream.

codeforcescompetitive-programming
CF 104288G - Mosaic Browsing

We are given a small pattern grid, called a motif, and a larger grid, called a mosaic. Each cell contains a color value, except that in the motif some cells are empty and behave like wildcards.

codeforcescompetitive-programming
CF 104288H - Prehistoric Programs

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

codeforcescompetitive-programming
CF 104288F - Islands from the Sky

Each island is a simple polygon lying on the ground plane, and each flight path is a 3D line segment with a positive altitude. A plane flies along that segment, and a downward-facing camera observes a strip of ground directly under the aircraft.

codeforcescompetitive-programming
CF 104288E - Hand of the Free Marked

We are given a deck split into several marking categories. Each category contains a known number of distinct cards, and the total deck size can be extremely large. A random group of $k$ cards is selected, and one of these $k$ cards is hidden face down.

codeforcescompetitive-programming
CF 104288D - Guardians of the Gallery

We are given a simple polygon representing the floor plan of a gallery. Inside this polygon there are two points: one is the guard’s starting position and the other is the center of a small circular sculpture.

codeforcescompetitive-programming
CF 104288C - Fair Division

Let $f^{D}(x1,dots,xn)=overline{f(overline{x1},dots,overline{xn})}$ and $f^{R}(x1,dots,xn)=f(xn,dots,x1)$. Composition yields $$f^{DR}(x)=overline{f(overline{xn},dots,overline{x1})},qquad f^{RD}(x)=overline{f(overline{xn},dots,overline{x1})},$$ so $f^{DR}=f^{RD}$ follows from…

codeforcescompetitive-programming
CF 104288B - Dungeon Crawler

We are given a weighted tree. Every query describes a scenario where a player starts at one room, must collect a special key located at another room, and must avoid permanently failing by entering a trap room before the key has been collected.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 204

The solution answers all parts, but part (b) is incorrect and breaks subsequent reasoning.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104288A - Crystal Crosswind

We are given a rectangular grid of size $dx times dy$. Each cell $(x, y)$ can either contain a molecule or be empty. The true arrangement is unknown, but we are given several “wind experiments” that partially reveal it.

codeforcescompetitive-programming
CF 104289E - Non-decreasing Sequence

Let $f^{D}(x1,dots,xn)=overline{f(overline{x1},dots,overline{xn})}$ and $f^{R}(x1,dots,xn)=f(xn,dots,x1)$. Composition yields $$f^{DR}(x)=overline{f(overline{xn},dots,overline{x1})},qquad f^{RD}(x)=overline{f(overline{xn},dots,overline{x1})},$$ so $f^{DR}=f^{RD}$ follows from…

codeforcescompetitive-programming
CF 104289F - Pull Smaller

We are given an initial sequence and a target sequence, both permutations of the same multiset of values. We are allowed to repeatedly perform a very specific operation: pick two positions i and j with i < j where the value at i is larger than the value at j, and then take the…

codeforcescompetitive-programming
CF 104289C - Equal Digits

We are given a positive integer $n$, and we need to find the smallest integer $k$ such that $k ge n$ and every digit of $k$ is identical. Such numbers look like $1, 2, 3, dots, 9, 11, 22, 33, dots, 9999$, where a single digit is repeated some number of times.

codeforcescompetitive-programming
CF 104289B - OR-bitax

We are given a sequence of integers, and we are allowed to cut it into contiguous non-empty pieces. For each piece, we compute a value called its score, defined as the bitwise XOR of all elements inside that piece.

codeforcescompetitive-programming
CF 104289D - GCD in Median Land

Let $f^{D}(x1,dots,xn)=overline{f(overline{x1},dots,overline{xn})}$ and $f^{R}(x1,dots,xn)=f(xn,dots,x1)$. Composition yields $$f^{DR}(x)=overline{f(overline{xn},dots,overline{x1})},qquad f^{RD}(x)=overline{f(overline{xn},dots,overline{x1})},$$ so $f^{DR}=f^{RD}$ follows from…

codeforcescompetitive-programming
CF 104289A - String Removal

Connection interrupted. Waiting for the complete answer

codeforcescompetitive-programming
CF 1042904 - Ультра mex

I’m missing the actual problem statement for Codeforces 1042904 - “Ультра mex”. Right now only the title is provided, but the editorial you’re asking for depends completely on the formal rules of the task (what the input is, what operations are allowed, what…

codeforcescompetitive-programming
CF 1042902 - Тайное послание

I can’t write a correct editorial yet because the actual problem statement for Codeforces 1042902 - “Тайное послание” is not included in your prompt, and it also does not appear in the retrieved references.

codeforcescompetitive-programming
CF 1042903 - Рекорды и антирекорды

The problem statement section is empty, so there isn’t enough information to derive the actual task for “Codeforces 1042903 - Рекорды и антирекорды”.

codeforcescompetitive-programming
CF 1042901 - Видеонаблюдение

I can’t write a correct editorial yet because the actual problem statement for Codeforces 1042901 - “Видеонаблюдение” is missing from your prompt.

codeforcescompetitive-programming
CF 1042918 - Выполнить план, но не перевыполнить

I can write the full editorial in your required format, but I’m missing the actual problem statement for Codeforces 1042918 - “Выполнить план, но не перевыполнить”.

codeforcescompetitive-programming
CF 1042916 - Конференция

I can’t produce a correct Codeforces-style editorial for “1042916 - Конференция” without the actual problem statement.

codeforcescompetitive-programming
CF 1042915 - Улитка на склоне

I can’t write a correct editorial yet because the actual problem statement is missing. Right now I only see the title “Улитка на склоне”, but no description of the grid/array rules, input format, or what is being computed.

codeforcescompetitive-programming
CF 1042917 - Яблоки по корзинам

I can absolutely write this editorial in the requested style, but I’m missing the one thing that makes it possible to be correct: the actual problem statement for Codeforces 1042917 - “Яблоки по корзинам”.

codeforcescompetitive-programming
CF 104294N - Portal Investigation

We are given a directed graph where cities are nodes and magical portals are directed edges. Each portal represents a one-way travel route. Misaka wants to “investigate” as many portals as possible using multiple independent agents called clones.

codeforcescompetitive-programming
CF 104294L - My Hero Photographia

We are given a rectangular grid of integers representing an image. Each cell is a pixel, and its value is an intensity. The grid is not just a flat array, but a torus: moving off the right edge brings you back to the left, moving off the top brings you back to the bottom.

codeforcescompetitive-programming
CF 104294M - Who Is a Titan?

We are given a collection of entities, each initially isolated, and a sequence of historical statements describing pairwise interactions between them.

codeforcescompetitive-programming
CF 104294K - Anime Trading

We are given a multiset of anime trading cards, where each card has an integer label called a quirk number. Midoriya wants to end up with a very specific final collection: it must contain exactly one copy of each integer from 1 up to some value K, with no gaps and no extras.

codeforcescompetitive-programming
CF 104294J - 3 Reasons to Eat Potato Chips

We are given three piles of chips. On each move, a player can either take chips from exactly one pile, choosing any positive number up to what remains in that pile, or take chips from all three piles simultaneously, choosing a positive number up to the smallest current pile…

codeforcescompetitive-programming
CF 104294I - Snack Time

We are given a tree of houses, where each house initially contains a certain number of friends. The roads form a connected acyclic structure, so between any two houses there is exactly one simple path. There are two types of events.

codeforcescompetitive-programming
CF 104294H - Beyblade Battle

We are simulating a point moving in the plane under mirror reflections, and we care about two things: how close the moving point ever gets to the origin, and how many times it reflects off two fixed lines passing through the origin. The geometry is completely deterministic.

codeforcescompetitive-programming
CF 104294D - No Game No Life

We are given a string s of length N, where each position also carries a weight ai. We are allowed to choose any subset of alphabet characters (both lowercase and uppercase).

codeforcescompetitive-programming
CF 104294F - Karuta Memories

Each leaf behaves like an object that falls straight down while being pushed horizontally by a time dependent wind. The wind at second t is a linear function of a global parameter k, so every second contributes a term of the form at + k dt.

codeforcescompetitive-programming
CF 104294G - Howl's Moving Castle

We are given a tree with $N$ rooms connected by $N-1$ hallways. Each hallway is either usable or blocked, and blocking hallways partitions the tree into several connected components.

codeforcescompetitive-programming
CF 104294E - Monster-Slayer

We are given a line of monsters, each with an integer power value. We want to choose a contiguous block of these monsters and compute the sum of their powers. Among all possible contiguous blocks, we need the one whose sum is as large as possible, and we output that sum.

codeforcescompetitive-programming
CF 104294B - Angel Beats

We are given several independent groups of angels. Each group contains a multiset of combat powers, and whenever a defense is formed, exactly one angel must be chosen from each group. The defense power is the sum of the chosen angels’ powers.

codeforcescompetitive-programming
CF 104294A - Square Jutsu!

We are given an $N times N$ grid representing terrain heights. Each cell has an integer elevation, and the grid has a structural monotonic property: every cell is no higher than its right, bottom, and bottom-right neighbors.

codeforcescompetitive-programming
CF 104294C - Attack on Titans

We are given three separate sequences, each representing the section heights of a wall. Every wall has the same number of sections, but the ordering is irrelevant for the task. What matters is only which heights appear in each wall at least once.

codeforcescompetitive-programming
CF 104295L - Карта-лягушка

We are given an undirected simple graph, and we need to decide whether its structure can be interpreted as a very specific “frog shape”. This shape consists of a simple cycle that represents the body. From this cycle, exactly four attachment points are chosen.

codeforcescompetitive-programming
CF 104295K - Снорк и порядок в кладовой

We are given a tree with n rooms. Each room initially contains a distinct number written on it. The rooms are connected by corridors, so the structure is a single connected acyclic graph. We must choose exactly x rooms that will remain in use.

codeforcescompetitive-programming
CF 104295J - Flowers

We are given a rectangular wall represented as a grid of lowercase Latin letters with $n$ rows and $m$ columns. Inside this grid we want to place a square frame of fixed size $k times k$.

codeforcescompetitive-programming
CF 104295I - Moomin Adventures

We are given a runner moving through a long 3-lane track, where each row is a step in time and each of the three columns represents a lane. Each cell can either be empty, contain a coin, contain an obstacle, or contain a trampoline. The runner starts at row 1 in the middle lane.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 203

Given f=\{\emptyset,\{1,2\},\{1,3\}\}, \quad g=\{\{1,2\},\{3\}\}.

taocpmathematicsalgorithmsvolume-4math-medium
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