brain

tamnd's digital brain — notes, problems, research

41486 notes

CF 1048561 - Ферзь

I can’t reliably write a correct editorial for “Codeforces 1048561 - Ферзь” from just the title, because multiple different problems use that name (it simply means “Queen” in chess), and the solution depends entirely on the exact task.

codeforcescompetitive-programming
CF 104857L - Information Spread

We are given a directed graph where each vertex represents a student and each directed edge represents a possible way information can be passed from one student to another.

codeforcescompetitive-programming
CF 104857K - Campus Partition

We are given a tree representing a campus, where each node is a building and each building has a positive importance value. We must split the tree into several groups by removing some edges.

codeforcescompetitive-programming
CF 104857J - Takeout Delivering

We are given a connected undirected graph where each edge has a positive weight representing congestion. A path from node 1 to node n is not evaluated in the usual way. Instead of summing all edge weights, only the two largest edge weights along the path matter.

codeforcescompetitive-programming
CF 104857I - Linguistics Puzzle

We are given a strange “language system” where there are $n$ symbols and they behave like digits in a base-$n$ number system, but the mapping from digits to symbols is unknown.

codeforcescompetitive-programming
CF 104857H - Computational Complexity

We are given two mutually recursive functions that grow with the input size, but instead of depending on slightly smaller integers in a linear way, each function depends on the other function evaluated at a significantly smaller argument, specifically a halved version of the…

codeforcescompetitive-programming
CF 104857G - Streak Manipulation

We are given a binary string that represents attendance across a sequence of classes. A streak is a maximal contiguous segment of ones, meaning a block of consecutive attended classes that is bounded by zeros or by the ends of the string.

codeforcescompetitive-programming
CF 104857D - Balanced Array

We are given an array that grows one element at a time, and after each new element we must decide whether the current prefix has a certain structural property.

codeforcescompetitive-programming
CF 104857F - Colorful Balloons

We are given a sequence of balloon colors, where each balloon has a color represented by a short lowercase string. The task is to determine whether there exists a color that appears strictly more than half of the total number of balloons. If such a color exists, we output it.

codeforcescompetitive-programming
CF 104857E - Matrix Distances

We are given an $n times m$ grid where each cell contains an integer color. For every color, we look at all cells having that color and consider every ordered pair of such cells.

codeforcescompetitive-programming
CF 104857B - Queue Sorting

We are given a multiset of integers where values range from 1 to n, and each value i appears ai times. The task is to count how many distinct sequences b, which are permutations of this multiset, have a special property involving two queues.

codeforcescompetitive-programming
CF 104857C - Cyclic Substrings

We are given a circular string of digits. From this circle, every pair of indices defines a substring that can wrap around the end back to the beginning.

codeforcescompetitive-programming
CF 104857A - SQRT Problem

We are given three integers: a modulus $n$, and two residues $a$ and $b$, all positive, with $n$ odd and $gcd(a,n)=1$. The task is to recover a unique integer $x$ in the range $1 le x le n-1$ that satisfies two constraints at the same time.

codeforcescompetitive-programming
CF 104869M - Outro: True Love Waits

We are placed in an implicit graph whose vertices are all non-negative integers. Two vertices are connected if their binary representations differ in exactly one bit, and the edge is labeled by the position of that bit (counting from the least significant bit as position 1).

codeforcescompetitive-programming
CF 104869L - Rook Detection

We are working on an interactive system over an $n times n$ grid that contains an unknown set of rooks. The key constraint is not the usual chess interaction, but a visibility condition: every square is initially “controlled”, meaning it is either occupied by a rook or lies…

codeforcescompetitive-programming
CF 104869K - Maximum Rating

We are given an array of integers representing rating changes from several contest rounds. We are allowed to reorder these rounds arbitrarily. We then simulate starting from rating zero, adding values one by one.

codeforcescompetitive-programming
CF 104869J - Graft and Transplant

We are given an unrooted tree with up to 50 vertices. Two players alternate turns, and in each turn they pick an edge $u-v$. The move is not a local swap of endpoints, but a structural “rewiring”: every neighbor of $u$ except $v$ gets detached from $u$ and reattached to $v$.

codeforcescompetitive-programming
CF 104869H - Line Graph Sequence

We are given an undirected simple graph and asked to repeatedly apply the line graph operation. Each application transforms the current graph into a new graph where every vertex represents an edge of the previous graph, and two vertices become adjacent if the original edges…

codeforcescompetitive-programming
CF 104869I - Three Rectangles

We are given a fixed axis-aligned rectangular board with dimensions $H times W$. Onto this board we must place exactly three smaller axis-aligned rectangles, each having fixed dimensions, without rotation.

codeforcescompetitive-programming
CF 104869G - Military Maneuver

We are given a rectangle on the plane. A point is chosen uniformly at random inside this rectangle. That point is the center of a beacon.

codeforcescompetitive-programming
CF 104869F - Ursa Minor

We are given a circular system of positions that represent continents with heights, all starting at zero. The only way to modify these heights is by repeatedly applying operations that choose a fixed segment length and then add an arbitrary real value to every position in some…

codeforcescompetitive-programming
CF 104869E - Sheep Eat Wolves

We are given a river-crossing scenario with two types of animals, sheep and wolves, and a boat controlled by a farmer. Initially, all sheep and wolves are on the left bank.

codeforcescompetitive-programming
CF 104869D - Dark LaTeX vs. Light LaTeX

We are given two strings, one representing a sequence from the “Dark LaTeX” system and one from “Light LaTeX”. From each string we are allowed to pick a contiguous substring. That gives us a pair of substrings, one from the first string and one from the second.

codeforcescompetitive-programming
CF 104869A - Intro: Dawn of a New Era

We are given several “scenes”. Each scene is described by a set of integers representing colors. For every scene, one special value is defined: its main color, which is simply the maximum value inside its set. We must arrange all scenes in a permutation.

codeforcescompetitive-programming
CF 104869C - Swiss Stage

We are tracking a team in a Swiss-system tournament where progress is determined purely by the difference between wins and losses.

codeforcescompetitive-programming
CF 104869B - Turning Permutation

We are working with permutations of the numbers from 1 to n, but only those permutations that satisfy a structural constraint defined through the positions of values rather than the values themselves. For each value i, let qi denote where i appears in the permutation.

codeforcescompetitive-programming
CF 104871A - Attendance

I can’t write a correct Codeforces editorial from that prompt because the actual problem statement is missing. Right now I only see: - Title: “Attendance” - A broken page excerpt (“Page 14 of 26”) - No definition of input, output, or task That’s not enough to…

codeforcescompetitive-programming
CF 104871L - Labelled Paths

We are given a directed acyclic graph where each edge carries a string label. A path’s label is formed by concatenating edge labels in traversal order.

codeforcescompetitive-programming
CF 104871I - Interactive Reconstruction

We are given a hidden tree with $N$ labelled vertices. The structure is unknown, but we are allowed to interrogate it using a special operation. In one query, we send a binary string of length $N$. This string assigns a value of 0 or 1 to each node.

codeforcescompetitive-programming
CF 104871K - Keys

We are given a graph whose vertices are rooms in a mansion and whose edges are doors. Each door connects two rooms and is labeled by a unique key index. To traverse a door, a person must currently hold its key.

codeforcescompetitive-programming
CF 104871J - Jumbled Stacks

We

codeforcescompetitive-programming
CF 104871H - Human Resources

We are given a company hierarchy that forms a rooted tree. Every employee except one has exactly one manager, and each manager has an ordered list of direct reports ranked from most to least preferred.

codeforcescompetitive-programming
CF 104871G - Going to the Moon

We are given two points in the plane, Alice at $A$ and Bob at $B$, and a circle representing the Moon with center $C$ and radius $r$.

codeforcescompetitive-programming
CF 104871F - Phylogenetics

We are given a special graph construction. The base object is a tree, embedded in the plane, with its leaves arranged in circular order. After that, every pair of consecutive leaves in this circular order is additionally connected, forming a cycle on the leaves.

codeforcescompetitive-programming
CF 104871D - Drying Laundry

We are given a fixed collection of laundry items, each item having a physical width and a drying profile. Across multiple weeks, Harry has two parallel clotheslines of equal length, and in each week the available length changes.

codeforcescompetitive-programming
CF 104871E - Equal Schedules

We are given two complete schedules that describe continuous on-call coverage over a timeline that starts at time 0. Each schedule is a partition of the interval into consecutive, non-overlapping segments.

codeforcescompetitive-programming
CF 104871C - Cakes

We are given a bakery that can produce several types of cakes. Each cake recipe consumes some amount of ingredients and requires a set of reusable tools. Every ingredient and every tool has a cost, and each cake also has a selling price.

codeforcescompetitive-programming
CF 104871B - Ball Passing

I can’t write a correct editorial from this as-is because the actual problem statement for “104871B - Ball Passing” is missing.

codeforcescompetitive-programming
CF 104872A - Three Suitcases

We are given three separate suitcases, each contributing a fixed weight to a single combined baggage check-in. The airline does not charge per suitcase, but instead looks at the total weight after everything is combined.

codeforcescompetitive-programming
CF 104872J - Streets of Flatland

We are given a connected structure made of $n$ locations connected by exactly $n-1$ undirected roads, so the underlying graph is a tree.

codeforcescompetitive-programming
CF 104872M - Katya and the Broken Keyboard

Katya wants to type a fixed string, but some keyboard keys behave periodically in a broken way. For each broken letter key, pressing it does not reliably produce a character every time.

codeforcescompetitive-programming
CF 104872L - Count the Christmas Trees

We are asked to count a very structured family of rooted trees of height $n$. The tree is layered: the root is at layer 1, and each vertex at layer $i$ has children only in layer $i+1$.

codeforcescompetitive-programming
CF 104872K - Guess the String

We are given an unknown string of length $n$, made only of the characters a, b, and c. Our task is to reconstruct it by asking queries about adjacent positions. A single query targets a position $i$ and a two-character pattern $u1u2$.

codeforcescompetitive-programming
CF 104872I - Squares

We are working with an infinite integer grid where every operation adds or removes a fixed shape, namely a unit 2 by 2 block anchored at a lower-left coordinate $(x, y)$. Each query toggles the presence of such a block in a current set $S$.

codeforcescompetitive-programming
CF 104872H - Scooter Numbers

We are given a fixed integer $n$. The task is to consider every way of writing $n$ as a sum of positive integers where order does not matter, so each representation is a nondecreasing sequence. Each such representation is treated as a multiset of parts.

codeforcescompetitive-programming
CF 104872G - Not Everything Is So Ambiguous

We are dealing with a hidden pair of integers: a value $x$ in the range $1 le x le 10^9$, and a base $b$ in the range $2 le b le 2023$. We do not see either of them directly. Instead, we are initially told how many digits $x$ has when written in base $b$.

codeforcescompetitive-programming
CF 104872F - Magic Square

We are given an $n times n$ grid that initially contains a perfect permutation of numbers from $1$ to $n^2$. The defining property of the original grid is that every row sum equals the same value, and every column sum also equals that same value.

codeforcescompetitive-programming
CF 104872B - Cooperative Game on a Tree

We are given a rooted tree where every node has a single parent except the root. Two tokens start at the root: a blue token and a red token. The process unfolds in synchronized rounds.

codeforcescompetitive-programming
CF 104872E - Casino

Codeforces 104872E: Casino

codeforcescompetitive-programming
CF 104872D - a, ab, ba Strings

We are maintaining a binary string made only of characters a and b, with two operations applied online. The first operation flips a single position, turning a into b or b into a.

codeforcescompetitive-programming
CF 104872C - Driving License Exam

We are given a path of intersections arranged in a line, where each adjacent pair is connected by a road with a certain length. Each intersection also contains some amount of “ice resource”.

codeforcescompetitive-programming
CF 104873J - Joined Vessels

We are given a line of vessels connected in a chain. Between vessel i and i+1 there is a narrow connection that only starts behaving like a proper communicating tube once the water level reaches a fixed height hi.

codeforcescompetitive-programming
CF 104873E - Email Destruction

Each email belongs to a “thread” that evolves in a very rigid way. A thread starts from a base subject, which is a non-empty lowercase string. Every next email in the same thread is created by prepending the prefix "Re: " to the previous subject.

codeforcescompetitive-programming
CF 104873L - LED-led Paths

We are given a directed acyclic graph where vertices represent junctions in a city and edges represent one-way streets. The acyclic condition means there is no way to start at a junction and follow directed streets to eventually return to the same place.

codeforcescompetitive-programming
CF 104873K - Keyboard Consensus

We are given a set of n keyboards, each identified by an integer label. Two people, Kolya and Kostya, each rank all keyboards from most preferred to least preferred, and both rankings are known to both players. They play a deterministic elimination game.

codeforcescompetitive-programming
CF 104873I - Interactive Array Guessing

We are given several hidden arrays, each containing a small number of distinct integers. The arrays are ordered from 1 to n, and each query lets us pick a list of indices and receive the concatenation of those arrays in that order, but without any separators between elements.

codeforcescompetitive-programming
CF 104873H - Halves Not Equal

We are asked to split a fixed amount of gold among $n$ recipients, where each recipient $i$ has a declared maximum acceptable share $ai$. The total gold available is $s$, and it may be strictly smaller than the sum of all claims, so not everyone can receive what they want.

codeforcescompetitive-programming
CF 104873F - Forgotten Land

We are given a tree with $n$ cities. Each city has exactly one language label from $1$ to $k$. The cities are partitioned into several disjoint groups, called alliances, but the partition is arbitrary and not restricted by edges of the tree.

codeforcescompetitive-programming
CF 104873G - Generalized German Quotation

We are given a sequence made only of two kinds of quote tokens. Each token is either the left style written as << or the right style written as . The task is not to interpret them as fixed opening or closing brackets.

codeforcescompetitive-programming
CF 104873D - Distinct Substrings

We are given a short string p and a very large integer n. The actual string we work with is not arbitrary: it is formed by repeating p over and over and then cutting it after exactly n characters.

codeforcescompetitive-programming
CF 104873B - Building a Stair

We are asked to construct a particular shape made of unit cubes, drawn as a square grid. Each cell either contains a cube or is empty, and the occupied cells must form a “stair” shape.

codeforcescompetitive-programming
CF 104873A - Accumulator Battery

A phone starts a journey fully charged and consumes battery while Anna travels. At some point during the journey, when the battery level hits a fixed threshold of 20 percent, the phone switches to a slower discharge mode.

codeforcescompetitive-programming
CF 104873C - Counting Stairs

We are asked to count a specific class of shapes built from unit cubes. Each valid configuration is a “stair-like” structure: columns of cubes arranged from left to right with heights that never increase as we move right.

codeforcescompetitive-programming
CF 104874C - Cross-Stitch

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

codeforcescompetitive-programming
CF 104874M - Managing Difficulties

I can’t reliably reconstruct Codeforces 104874M (“Managing Difficulties”) from the title alone, and I don’t have the actual problem statement in your prompt.

codeforcescompetitive-programming
CF 104874L - Lengths and Periods

We are given a single long string over lowercase English letters, and we want to measure how “repetitive” it can be in its most extreme localized form.

codeforcescompetitive-programming
CF 104874I - Ideal Pyramid

We are given a set of vertical pillars placed on a plane, each located at an integer coordinate and having a required minimum height.

codeforcescompetitive-programming
CF 104874K - King's Children

We are given an $n times m$ grid where each cell is either empty or contains exactly one castle labeled by an uppercase letter. There is exactly one castle labeled ‘A’, which belongs to the favorite child.

codeforcescompetitive-programming
CF 104874J - Just the Last Digit

We are given a directed acyclic structure over $n$ ordered nodes, where edges only go from a smaller index to a larger index. Think of it as a downhill graph: from every spot $i$, you can only move to higher-indexed spots $j i$ if a trail exists.

codeforcescompetitive-programming
CF 104874H - High Load Database

We are given a fixed sequence of transactions, each transaction carrying a positive workload measured in queries. We are not allowed to reorder these transactions. Instead, we must partition the sequence into contiguous groups, which we will call batches.

codeforcescompetitive-programming
CF 104874G - Golf Time

I tried to locate “Codeforces 104874G - Golf Time”, but there is no accessible statement in the public Codeforces archive or mirrors indexed in standard problem listings.

codeforcescompetitive-programming
CF 104874F - Foreach

I can’t responsibly write a correct editorial for Codeforces 104874F - Foreach yet because the actual problem statement is missing, and I was not able to retrieve a reliable statement from available sources.

codeforcescompetitive-programming
CF 104874E - Equidistant

We are given a tree of cities connected by roads, where every road has equal travel time. A subset of these cities contains teams. The task is to choose a single city such that every team can reach it in exactly the same number of edges.

codeforcescompetitive-programming
CF 104874D - Double Palindrome

We are working with strings built from the first $k$ lowercase English letters, and we want to count how many such strings of length at most $n$ satisfy a structural property called “double palindrome”.

codeforcescompetitive-programming
CF 104874B - Bad Treap

We are given a deterministic treap definition where each node has a key and a priority derived from the key itself using a fixed function, namely $y = sin(x)$.

codeforcescompetitive-programming
CF 104874A - Accurate Movement

I don’t actually have the statement for Codeforces 104874A - Accurate Movement in your prompt, and I can’t reliably reconstruct it from the title alone without risking inventing details.

codeforcescompetitive-programming
CF 104875G - Going in Circles

We are placed on a cyclic structure of train carriages. Each carriage contains a binary light switch, either 0 or 1. We start in an unknown carriage, and we are allowed to move to adjacent carriages along the cycle or flip the switch in the current carriage.

codeforcescompetitive-programming
CF 104875D - Delft Distance

The city is a rectangular grid of size $h times w$. Each cell contains a building occupying most of a $10 times 10$ meter square footprint. Some cells are square buildings, others are circular towers whose footprint is a disk of diameter $10$, so radius $5$.

codeforcescompetitive-programming
CF 104875L - Last Guess

We are given a Wordle-like process where several guesses have already been made and each guess comes with full feedback using the usual green, yellow, and black rules, including correct handling of repeated letters.

codeforcescompetitive-programming
CF 104875K - Kebab Pizza

We are given a circular pizza split into $n$ slices. Each slice has exactly two toppings assigned by the customer who eats that slice. Across all slices there are $k$ possible topping types.

codeforcescompetitive-programming
CF 104875J - Justice Served

Each suspect corresponds to a time interval during which they were in the room. For suspect i, we are given an arrival time a and a duration t, which defines an interval from a to a + t.

codeforcescompetitive-programming
CF 104875I - Interview Question

We are given a slice of a FizzBuzz-like sequence, but instead of knowing the rules, we only see the output and must reconstruct the hidden parameters.

codeforcescompetitive-programming
CF 104875H - High-quality Tree

We are given an undirected tree rooted at node 1, where each node has at most two children once the root is fixed. The notion of balance is defined locally: for any node, consider the heights of its left and right subtrees.

codeforcescompetitive-programming
CF 104875F - Faster Than Light

We are given several axis-aligned rectangles in the plane. Each rectangle represents a “room” of a spaceship, and we are allowed to fire a single infinite straight line beam in any direction.

codeforcescompetitive-programming
CF 104875E - ETA

We are asked to construct an undirected connected graph where vertex 1 is treated as the exit. A player starts at a uniformly random vertex and then always moves optimally toward vertex 1, meaning the travel time from a node is simply its shortest-path distance to node 1.

codeforcescompetitive-programming
CF 104875C - Circular Caramel Cookie

We are given a configuration of unit squares laid out on an infinite grid. Think of the plane split by integer lattice lines into 1 by 1 cells.

codeforcescompetitive-programming
CF 104875A - Alternating Algorithm

We are given an array of length $n+1$, and we repeatedly apply a very specific parallel “adjacent swapping” procedure until the array becomes sorted in non-decreasing order.

codeforcescompetitive-programming
CF 104878B - Lockpicking

There are N switches, each representing a pin on a security system. Turning on a pin takes exactly one second, and each pin can only be activated once. The difficulty comes from the fact that each pin watches a fixed set of other pins.

codeforcescompetitive-programming
CF 104878A - Heist

We are given a city modeled as an undirected graph where intersections are nodes and streets are edges. Powder starts at node 1, the laboratory, and wants to reach node N, the hidden entrance to Zaun. Some intersections initially contain police officers.

codeforcescompetitive-programming
CF 104879D - Restore Permutation

We are given a hidden permutation of numbers from 1 to n. The interaction model is that we get some encoded information about this permutation, and in the second phase we receive another permutation that differs from the original in a very restricted way.

codeforcescompetitive-programming
CF 104879E - DequeQL

We are dealing with a dynamic system of nested deques. Each deque can contain other deques, forming a rooted structure that changes over time.

codeforcescompetitive-programming
CF 104879C - Public Transportation

We are given a grid of integers where each cell represents a value assigned to a point on a rectangular board. The task is to count certain geometric configurations formed by three cells, which we can think of as “triangles” aligned with the grid.

codeforcescompetitive-programming
CF 104879A - Coffee Cocktail

We are given several kinds of snacks, where each snack type can appear multiple times and each individual snack contributes some amount of caffeine.

codeforcescompetitive-programming
CF 104880G - 石子配对

We are given a multiset of stone types, where each type has a value and a quantity. Altogether there are exactly $2n$ stones, so every stone must be used exactly once in pairing. When we pair two stones with values $x$ and $y$, they contribute a score equal to $(x + y) bmod k$.

codeforcescompetitive-programming
CF 104880O - Toxel 与字符串匹配

We are given two integer arrays, one of length n and another of length m. We imagine sliding the shorter array over the longer one in every possible relative alignment, including positions where they only partially overlap.

codeforcescompetitive-programming
CF 104880N - Purble Shop

We are interacting with a hidden array of length $n$, where each position represents an item of clothing and stores a color from $1$ to $n$.

codeforcescompetitive-programming
CF 104880M - Easy XOR problem

We are given a collection of binary strings, each of equal length. You can think of each string as a number written in base 2 with a fixed number of bits.

codeforcescompetitive-programming
CF 104880L - 数列计数

We are given a digit sequence of length $n$, and every contiguous segment $[l, r]$ is interpreted as a decimal number.

codeforcescompetitive-programming
CF 104880J - while (1) replace;

We are given an unknown string consisting only of the characters a, b, and c, with length at most 10. We are not allowed to read or query the string directly. Instead, we are allowed to apply a special operation replace(x, y) multiple times.

codeforcescompetitive-programming
CF 104880K - Power Shift

We are given an array of length n, and we need to support three kinds of operations applied over ranges or single positions. One operation takes every element in a segment and replaces it by the integer square root of its current value.

codeforcescompetitive-programming