brain

tamnd's digital brain — notes, problems, research

41230 notes

CF 104397B - Poker Number

We are given a range of numbers from 1 to $n$. Some of these numbers are “special”: they are called Poker Numbers if they can be written as a positive multiple of a triangular number of the form $Tx = frac{x(x+1)}{2}$, where $x ge 2$.

codeforcescompetitive-programming
CF 104397J - Billboard

We are given a ranked list of songs, where each song initially sits at a unique position from 1 to n. For every song, we receive exactly one consolidated opinion about whether its current position is acceptable or should be changed.

codeforcescompetitive-programming
CF 104397I - W-shaped Rail Fence Cipher

We are given a string that needs to be rearranged according to a fixed “W-shaped” writing path. Instead of writing characters left to right in a single line, we imagine placing them along a vertical pattern with multiple rows, then reading them row by row.

codeforcescompetitive-programming
CF 104397H - Morning ECO, Evening EMO

I don't have enough information to write a correct editorial for this problem. The prompt identifies Codeforces 104397H - Morning ECO, Evening EMO, but the essential parts are missing: - Problem statement - Input specification - Output specification - Constraints - Sample…

codeforcescompetitive-programming
CF 104397E - Course Selection

We are given a set of selected courses for a master’s program. Each course contributes a certain number of credits and belongs to exactly one category such as public foundational, professional foundational, elective variants, or compulsory sessions.

codeforcescompetitive-programming
CF 104397G - Josephus Problem 2

I don't have enough information to write a correct editorial. The problem statement describes the task, but it does not provide the full input/output specification needed to derive and verify the algorithm.

codeforcescompetitive-programming
CF 104397D - Binary Subsequence

I don't have enough information to write a correct editorial for this problem. The prompt includes the problem statement, but it does not include the key information needed to derive the algorithm, namely one of the following: 1. The original Codeforces editorial. 2.

codeforcescompetitive-programming
CF 104397A - Inverse Pairs of Binary Strings

We are given several binary strings and we are allowed to concatenate them in any order into a single long binary string. Once concatenated, we count inversions in the usual sense: a pair of positions where a 1 appears before a 0.

codeforcescompetitive-programming
CF 104397C - Delivery Robot

The problem statement is missing a critical piece of information. The Input section in your prompt is empty, and the sample input has also lost all whitespace: This is impossible to parse unambiguously. For example, it could mean: or many other interpretations.

codeforcescompetitive-programming
CF 104396K - Similarity (Hard Version)

We are given a directed graph on $n$ nodes where each node is supposed to end up with exactly one outgoing edge and exactly one incoming edge, so the final structure is a functional graph, which is equivalent to a permutation on $n$ nodes. Some edges are already fixed.

codeforcescompetitive-programming
CF 104396G - Moving Boxes

We are given a set of box transfers on a number line. Each box starts at a position $xi$ and must end at a position $yi$, and all starting and ending positions are globally distinct within their respective sets.

codeforcescompetitive-programming
CF 104396F - Timaeus

I don't have enough information to write a correct editorial. The problem statement describes the actions and probabilities, but it is missing the crucial detail that determines the dynamic programming state: What exactly happens after each synthesis?

codeforcescompetitive-programming
CF 104396C - GG and YY's Game

We are given several independent chains, where each chain is simply a path graph with a specified length. Two players take turns removing nodes from these chains.

codeforcescompetitive-programming
CF 104396D - Star Rail

We are given a set of points in the plane. Each point represents a star. For every star $i$, we imagine standing at that star and drawing a straight line that passes through it. This line is required not to pass through any other star.

codeforcescompetitive-programming
CF 104396A - Today's Word

I don't have enough information to write a correct editorial and solution for this problem because the problem statement as provided is corrupted. The recurrence defining $Sn$ contains broken indices: This expression is mathematically impossible.

codeforcescompetitive-programming
CF 104393J - Jane's Party Salad

We are given a fixed pantry of ingredients and a rule that Jane must pick exactly $K$ distinct ingredients to form a salad. Each friend has a personal list of ingredients they refuse to eat.

codeforcescompetitive-programming
CF 104393G - Getting the Real Weight

John is tracking his weight, but the new scale is broken in a very specific way. Instead of showing his true weight, the scale reports the square of his actual weight. He uses two consecutive mornings of measurements.

codeforcescompetitive-programming
CF 104393C - Counting Risk Factors

We are given a long string that represents a linear chemical strip. Each position on the strip is a lowercase letter. Some letters are marked as “risky”. For any substring of the strip, we can count how many risky characters it contains.

codeforcescompetitive-programming
CF 104395G - Lines

We are given a static array of integers, and for each query value $x$, we look at every adjacent pair in the array and evaluate a quadratic expression formed by shifting both endpoints by $x$. For a fixed pair $(i, i+1)$, the value is $(A[i] - x)(A[i+1] - x)$.

codeforcescompetitive-programming
CF 104395E - Vacation Planning

We are given a set of activities, each described by a duration in hours and a happiness value. Trotles has exactly three days of vacation, and each day he has 16 usable hours.

codeforcescompetitive-programming
CF 104395D - Reds and Blues

We are given an undirected weighted graph where each vertex represents a city and each edge represents a possible road with a construction cost. Every city is marked either red or blue.

codeforcescompetitive-programming
CF 104395B - Spilling the Juice

We are given an array where each position does not necessarily store a single fixed number. Some positions are known exactly, while others are uncertain and described as a closed interval.

codeforcescompetitive-programming
CF 104396L - Architect

We are given a large axis-aligned cuboid that spans from the origin to a fixed point $(W, H, L)$. Inside this container, someone has placed several smaller axis-aligned cuboids.

codeforcescompetitive-programming
CF 104396J - Similarity (Easy Version)

We are given several sets of place names, and for each set we want to compare every pair of names. The comparison between two names is defined by how long their longest shared contiguous block of characters is.

codeforcescompetitive-programming
CF 104396I - Elevator

There are n people inside an elevator, including yourself. Every person has selected a destination floor. Among all selected destinations, exactly m distinct floors appear.

codeforcescompetitive-programming
CF 104396H - Neil's Machine

We are given two strings of equal length. Think of them as two versions of a sequence of characters, where the first string is the starting configuration and the second string is the target configuration.

codeforcescompetitive-programming
CF 104396E - LCM Plus GCD

We are asked to count how many ways we can choose a set of exactly k distinct positive integers such that two aggregate values computed from the set satisfy a simple linear condition: the sum of the set’s LCM and GCD equals a given number x.

codeforcescompetitive-programming
CF 104396B - Honkai in TAIKULA

We are given a directed graph where each star is a node and each star rail is a directed edge with an integer cost, which may be negative.

codeforcescompetitive-programming
CF 104397F - ``Mode'' but ``Low Space''?

We are given a collection of cookie sizes, essentially an array of integers. From this array, we want to select a subset of cookies such that the chosen elements lie within a narrow value range: the largest selected value minus the smallest selected value must be at most k.

codeforcescompetitive-programming
CF 104400K - The Demon Jester

We are working on a tree where one player, Malphite, starts fixed at vertex 1 and continuously moves along shortest paths trying to reach a moving target controlled by Playf.

codeforcescompetitive-programming
CF 104400J - Sakuyalove and Latin Square

We are given a partially filled Latin square of size $n times n$. A Latin square is a grid where every row contains each number from $1$ to $n$ exactly once, and every column also contains each number from $1$ to $n$ exactly once.

codeforcescompetitive-programming
CF 104400I - Infinite recurring Decimal

We are given a positive integer $n$ that is guaranteed not to be divisible by 2 or 5. This condition ensures that the decimal expansion of $frac{1}{n}$ is purely repeating after the decimal point, with no terminating prefix.

codeforcescompetitive-programming
CF 104400G - XOR Segments

We are asked to count how many arrays of length $n$ exist where each element is an integer in $[0, 2^k)$, while also satisfying a set of XOR constraints on subsegments. Each constraint fixes the XOR of a contiguous interval $[li, ri]$ to a given value $xi$.

codeforcescompetitive-programming
CF 104400F - stone(hard version)

We are given a row of stone piles. Players alternate turns, starting with Alice. On a single turn, a player performs a sequence of up to $k$ consecutive moves. Each move removes at least one stone from the current leftmost non-empty pile.

codeforcescompetitive-programming
CF 104400E - stone(easy version)

We are given a row of stone piles. The game proceeds in alternating turns starting with Alice. On each turn, the current player focuses only on the leftmost pile that still contains stones and removes at least one stone from it.

codeforcescompetitive-programming
CF 104400D - Sakuyalove and Fast FFT

We are given an array of length $n+1$, indexed from $0$ to $n$. From this array, two new arrays are constructed through a layered transformation that mixes factorial terms and alternating signs.

codeforcescompetitive-programming
CF 104400B - Color

We are given a sequence of colored objects arranged in a line, where each color is represented by an integer. The goal is to transform this sequence into a non-decreasing sequence using a special type of operation.

codeforcescompetitive-programming
CF 104400C - Construct A Permutation

We are asked to construct a permutation of numbers from 1 to n that maximizes a nested alternating absolute expression of the form where differences are repeatedly taken between consecutive elements with absolute value applied at each subtraction level.

codeforcescompetitive-programming
CF 104408E - Sixty Nine

We are given an array of integers and a very unusual way to modify it. Each move lets us pick either a prefix or a suffix and subtract 1 from every element in that chosen segment. We can repeat these moves any number of times, and we are allowed to drive values below zero.

codeforcescompetitive-programming
CF 104408D - Attack Plan

We are given an $n times n$ grid that contains exactly one soldier in every row and every column. This structure is equivalent to a permutation: in column $i$, the soldier is placed at row $pi$.

codeforcescompetitive-programming
CF 104408A - Cool Strings

Right now I can’t produce a correct editorial because the problem content is essentially missing. For Codeforces 104508B - Bogosort, you only provided: and empty input/output sections.

codeforcescompetitive-programming
CF 104408C - Binary Flip

We are given several binary strings, all of the same length. On each move, we pick one of these strings and choose a prefix starting at position 1, then flip every bit in that prefix. Flipping means turning 0 into 1 and 1 into 0.

codeforcescompetitive-programming
CF 104408B - Gaz Map

The city is drawn on a plane, but movement is restricted to a fixed network of streets. There are the two coordinate axes, meaning you can move freely along the x-axis and y-axis, and there are also infinitely many concentric circular roads centered at the origin, one for each…

codeforcescompetitive-programming
CF 104412L - ICPC Teams

We are given three people who can work in parallel, each having a different productivity rate. There is also a list of programming tasks, each with a base amount of work.

codeforcescompetitive-programming
CF 104412J - JP's List of Trips

We are given a connected undirected graph of up to one hundred thousand cities and roads. Each road can be used in both directions. On top of this network, we are given queries, each query asking about a pair of cities S and E.

codeforcescompetitive-programming
CF 104412K - Knockout Spell

We are given a square grid of size $N times N$, where each cell contains a digit from 0 to 9 representing terrain type. We are also given a fixed size $K$, and we need to examine every possible $K times K$ sub-square inside the grid.

codeforcescompetitive-programming
CF 104412G - Guessing Two Steps into the Multiverse

We are given a directed multigraph on n universes. Edges (called portals) appear one by one over time, and each portal is directed. After each new edge is added, we must maintain two values.

codeforcescompetitive-programming
CF 104412F - Fibonacci Fever

We are asked to evaluate a sum over Fibonacci numbers, but not the Fibonacci sequence itself directly. For each index from 1 up to a very large limit n, we take the corresponding Fibonacci number and raise it to a fixed power k, then add everything together under modulo $10^9…

codeforcescompetitive-programming
CF 104412D - Draconis Subarrays

We are given two integer arrays. The first array, call it the pattern array, has length $M$. The second array, call it the source array, has length $N$.

codeforcescompetitive-programming
CF 104412B - Bogo Sort Probability

The process described is a randomized sorting procedure that repeatedly shuffles the array until it happens to become sorted. A single “successful iteration” means that after one random shuffle, the resulting permutation is already sorted.

codeforcescompetitive-programming
CF 104414K - 摩天大楼

We are given a one-dimensional street with $n$ positions, each position $i$ having a planned final height $hi$. Think of this as a skyline project where each index is a building site and the number $hi$ is how many “layers of construction” are required at that site.

codeforcescompetitive-programming
CF 104414I - 三分图

We are given multiple test cases. Each test case describes three groups of vertices, with sizes $a$, $b$, and $c$. We imagine all vertices are initially isolated, and we are allowed to add undirected edges between any pairs of distinct vertices.

codeforcescompetitive-programming
CF 104414A - 奇迹

We are given a grid of integers, and we are asked to count how many axis-aligned rectangles inside this grid satisfy a very specific condition based on their four corner values. For any rectangle, we pick two distinct rows and two distinct columns.

codeforcescompetitive-programming
CF 104414H - 蟹黄堡和海霸糊

We are given two hidden positive integers $x$ and $y$. What we actually see is only their sum $n = x + y$ and the least common multiple $k = mathrm{lcm}(x, y)$. The task is to reconstruct one valid pair $(x, y)$ such that the sum matches $n$, the lcm matches $k$, and $x le y$.

codeforcescompetitive-programming
CF 104414J - Aythsr 的彩票人生

We are given a connected undirected graph representing a city. Each road connects two intersections and may optionally contain a lottery machine. For each delivery request, a courier starts at a source node and wants to reach a target node along any walk in the graph.

codeforcescompetitive-programming
CF 104414G - 兄弟数

We are given a number $x$ and a value range $[L, R]$. We want to pick a positive integer $y$ such that when we multiply it with $x$, the product becomes a perfect square. At the same time, that product must stay inside the interval $[L, R]$.

codeforcescompetitive-programming
CF 104414F - 无产阶级万岁

We are given a tree with $n$ nodes. Only some nodes are leaves, and each leaf has a numeric value representing a “welfare expectation”. Internal nodes have value zero in the input, but they are structurally important because they define which leaves can communicate.

codeforcescompetitive-programming
CF 104414E - 来自 2020 的鲜花

We are working with a star shaped graph with $n$ nodes, where one node acts as the center and the remaining $n-1$ nodes are leaves. Each leaf is associated with a fixed “original paint color”, and there are exactly $n-1$ distinct colors, one per leaf.

codeforcescompetitive-programming
CF 104414B - 阶梯计数

We are given a staircase-shaped board of size $n$, where row $i$ contains exactly $i$ cells aligned to the left. So row 1 has 1 cell, row 2 has 2 cells, and so on up to row $n$ which has $n$ cells.

codeforcescompetitive-programming
CF 104414D - 账号 -1

There are $n$ student accounts labeled $1$ to $n$, plus a special teacher account labeled $-1$. We are also given a sequence of $t$ events.

codeforcescompetitive-programming
CF 104414C - 01感染

We are given a binary string where some positions contain 1 and others 0. Starting from the initial configuration (called day 1), the string evolves over time.

codeforcescompetitive-programming
CF 104415J - Jagged Roads

We are given a directed or undirected weighted graph depending on the statement’s interpretation, where each edge does not contribute additively to a path cost, but multiplicatively. A path’s total cost is the product of all edge weights along it.

codeforcescompetitive-programming
CF 104415I - Impressing the Captain

We are given a sequence of integers, and we process it from left to right. While scanning, we maintain how many times each value has already appeared.

codeforcescompetitive-programming
CF 104415H - How do you spell this?

We are given a fixed dictionary of strings. Each string can be thought of as a path in a character tree, where every character leads to the next branch. After building this structure, we are asked to answer multiple queries.

codeforcescompetitive-programming
CF 104415G - Graphical Nightmare

We are given an undirected weighted graph. From this graph, we are asked to construct a minimum spanning tree, and then consider the tree as an unrooted structure where distances are shortest-path distances along tree edges.

codeforcescompetitive-programming
CF 104415F - Frisbee Training

The task describes a simple physical situation where a frisbee is thrown from the origin and lands at a point $(x, y)$. A player named Asfora can catch it only if he is able to run far enough before it lands.

codeforcescompetitive-programming
CF 104415E - Elevator Crisis

We are given a graph whose vertices are identified by unique integer labels. Some labels in the range from 1 up to a maximum value may not correspond to any actual vertex. The graph also contains undirected edges between these labeled vertices.

codeforcescompetitive-programming
CF 104415D - Daydreaming Strings

We are given several independent test cases. In each test case, there are two strings, and the task is to merge them into one string and then rearrange the characters of this merged string so that they appear in sorted order according to the standard lexicographic order of…

codeforcescompetitive-programming
CF 104415C - Candy Shop

We are given a list of numbers, each representing how many candies a student is willing to accept in a purchase. The shop is processing students in some order, but we are free to choose the order in which we satisfy them.

codeforcescompetitive-programming
CF 104415A - Attendance Points

We are given a sequence of attendance points for a series of classes that must be attended strictly from the first class onward, without skipping or starting from the middle.

codeforcescompetitive-programming
CF 104415B - Beached Cannons

We are given a quadratic curve that is known to pass through the origin and two additional points in the plane. In other words, the parabola is uniquely determined by three points, one of which is fixed at (0, 0), and the other two are provided in the input.

codeforcescompetitive-programming
CF 104417M - Computational Geometry

We are given a convex polygon whose vertices are listed in counterclockwise order. From this polygon we must choose three distinct vertices $a, b, c$, also in counterclockwise order, with an additional structural constraint: when walking along the boundary from $b$ to $c$ in…

codeforcescompetitive-programming
CF 104417L - Puzzle: Sashigane

We are given an n by n grid where exactly one cell is forbidden, and every other cell must be covered exactly once using L-shaped tiles.

codeforcescompetitive-programming
CF 104417K - Difficult Constructive Problem

We are given a partially specified binary string where some positions are fixed as 0 or 1 and some are unknown. Each unknown position can be replaced independently by either 0 or 1.

codeforcescompetitive-programming
CF 104417I - Three Dice

We are given three standard six-sided dice. Each face carries a number of pips from 1 to 6. Some faces are considered “red faces” and the rest “black faces”. Specifically, faces showing 1 and 4 are red, while faces showing 2, 3, 5, and 6 are black.

codeforcescompetitive-programming
CF 104417J - Not Another Path Query Problem

We are given an undirected weighted graph. Each edge carries a 60-bit weight. For any walk between two vertices, we compute a single value by taking the bitwise AND of all edge weights along that walk. A walk is considered good if this AND value is at least a given threshold V.

codeforcescompetitive-programming
CF 104417H - Be Careful 2

We are given a large axis-aligned rectangle from the origin to the point $(n, m)$. Inside this rectangle, there are a number of forbidden lattice points.

codeforcescompetitive-programming
CF 104417G - Matching

We are given an array of integers, and we use it to define a graph on indices. Every index is a vertex, and we connect two vertices i and j when a specific arithmetic condition between their indices and values holds.

codeforcescompetitive-programming
CF 104417F - Colorful Segments

We are given a collection of closed intervals on a number line. Each interval also has a binary label, red or blue. We want to count how many subsets of these intervals can be chosen such that no chosen red interval overlaps a chosen blue interval.

codeforcescompetitive-programming
CF 104417E - Math Problem

We start with a single integer and are allowed to transform it using two reversible-looking digit operations in base $k$. One operation appends a digit in base $k$, meaning we multiply the number by $k$ and add a chosen remainder less than $k$.

codeforcescompetitive-programming
CF 104417D - Fast and Fat

Each test case describes a team of people, where every person has a running speed and a weight. The team is allowed to form pairs where one person carries exactly one other person on their back, and a person can either be carrying someone, being carried, or doing nothing.

codeforcescompetitive-programming
CF 104417C - Trie

We are given a rooted tree with nodes labeled from 0 to n, where 0 is the root. Each edge currently has no label, but every node has at most 26 children, so in principle we can assign lowercase letters to outgoing edges from any node without conflict.

codeforcescompetitive-programming
CF 104417B - Building Company

We are given a company that starts with some employees of different occupations, where each occupation type has a current number of available workers. On top of this initial workforce, there are multiple building projects available.

codeforcescompetitive-programming
CF 104417A - Orders

Each order in this problem arrives with a deadline day and a required quantity of products. The factory produces a fixed number of products every day starting from day one, and there is no initial inventory.

codeforcescompetitive-programming
CF 104420E - Grid Walking+

We are working on a grid where every cell contains a value. A player moves through this grid and “collects” values from cells they visit. Movement is restricted: from any cell, you may move right, left, or down, but never up.

codeforcescompetitive-programming
CF 104420D - Increasing A and Decreasing B

We are asked to construct an integer sequence that starts from a fixed value and grows strictly. The twist is not in the growth itself, but in how the differences between consecutive elements behave under XOR.

codeforcescompetitive-programming
CF 104420C - Get the Long Binary Number

We are given a binary string $y$ and an integer $k$. We need to construct another binary string $x$ such that two conditions are satisfied simultaneously. First, $x$ must represent a binary number that is not smaller than $y$.

codeforcescompetitive-programming
CF 104420B - Mex Path

We are given a grid with exactly two rows and n columns. Each cell contains a non-negative integer. We must construct a walk that starts at the top-left cell (1,1) and ends at the bottom-right cell (2,n).

codeforcescompetitive-programming
CF 104420A - Infinite Grid

We are working on an infinite square grid where every cell starts out white. We then choose exactly n cells and repaint them red. The grid is considered as a graph where each cell connects to its four neighbors by unit edges.

codeforcescompetitive-programming
CF 104426K - Divisibility

We are given three integers for each query: a starting value a, a multiplier b, and a modulus target d. We are allowed to choose a non-negative integer k, and we want the smallest such k that makes two separate divisibility conditions true at the same time.

codeforcescompetitive-programming
CF 104426N - Ichthyophobia

We are given a sequence of independent observations, each representing a lake and the number of fish in it. For every lake, we must decide whether Kaitokid can safely visit it. Safety is defined in a very strict way: a lake is acceptable only when it contains no fish at all.

codeforcescompetitive-programming
CF 104426M - Kubernetes

We are given a set of machines, each with a fixed capacity, and a collection of applications where each application consists of several identical pods that must be placed onto these machines.

codeforcescompetitive-programming
CF 104426L - Protecting The Earth

We are placing points with integer coordinates on an infinite grid, and we want to fit at least $K$ distinct grid points inside or on the boundary of a circle centered at the origin.

codeforcescompetitive-programming
CF 104426J - Dyscalculia

We are dealing with sequences of length $n$ formed under a very specific rule. The sequence always starts at 1. At every next position, the value either continues the previous value plus one, or it resets back to 1.

codeforcescompetitive-programming
CF 104426H - Abo Abdo Smoothies

We are given two sequences of length $n$. The first sequence represents the smoothies Naseem actually bought, and the second sequence represents what each friend would ideally like to receive.

codeforcescompetitive-programming
CF 104426I - Yazan's game

We are given a rectangular grid of size $n times m$, where each cell contains either 0 or 1. In one move, we are allowed to choose exactly one cell that currently contains a 1. Once chosen, every cell that shares an edge or a corner with it becomes 1.

codeforcescompetitive-programming
CF 104426G - GCD of Strings

We are given a long decimal string and asked to cut it into several contiguous pieces. Every character of the string must belong to exactly one piece, and each piece is interpreted as a non-negative integer (leading zeros are allowed and the number is not normalized).

codeforcescompetitive-programming
CF 104426E - Stacked Pearls

We are working with an $n times n$ grid where each cell can either be empty or contain a pearl with an integer size. The grid is updated through a sequence of operations, where each operation either places a pearl in a cell, replaces an existing one, or removes it.

codeforcescompetitive-programming
CF 104426F - The Lazy Author

We are given a binary array and a fixed window size. In one move, we choose any contiguous segment of exactly $k$ elements and flip every value inside it, turning zeros into ones and ones into zeros.

codeforcescompetitive-programming
CF 104426D - Bubble Sort !!?

We are given a permutation p of size n. From this permutation we construct a large list of permutations: we take every permutation of 1..n that is lexicographically greater than or equal to p, sort them in lexicographic order, and concatenate them into a single sequence A.

codeforcescompetitive-programming