brain

tamnd's digital brain — notes, problems, research

41641 notes

CF 104386C - Prefix Sum Array

We start with an infinite array where every position initially contains the value 1. Each second, the array is replaced by its prefix sum version, meaning the value at position i becomes the sum of all values from position 1 to i in the previous array.

codeforcescompetitive-programming
CF 104390A - Merge

Two people report charging stations along a line. Each station has a position and a number of outlets. We effectively build a multiset of positions where each position appears multiple times according to how many outlets exist there. Mr.

codeforcescompetitive-programming
CF 104390C - Jewelry Necklace

We are given a binary string representing a line of suppliers. Each position contributes either a real gemstone or a fake one. A necklace is formed by choosing any contiguous segment of this string.

codeforcescompetitive-programming
CF 104390B - Explorer

We are given a tree with $N$ rooms. Alongside the tree structure, we also receive a long sequence of length $2N-1$, which comes from an older exploration process that behaves like a depth-first traversal but records visits differently: every time a room is entered, its label…

codeforcescompetitive-programming
CF 104391B - Phitsanulok

We are given a collection of fruits. Each fruit has a weight and a description over up to 19 poison types. For every poison type, a fruit can either contain that poison, contain the antidote for it, or contain neither.

codeforcescompetitive-programming
CF 104391C - Range

We are given a collection of intervals on the number line, each interval representing a “mountain” with a left endpoint and a right endpoint.

codeforcescompetitive-programming
CF 104391A - Energy

We are given a sequence of energy cell values laid out in a line. The machine we need to feed has a fixed perfect binary tree structure with $K$ layers, so it contains $2^{K-1}$ leaves at the bottom and a total of $2^K - 1$ nodes.

codeforcescompetitive-programming
CF 104508D - Decision Problem

We are given a sequence of integers. There is no second line, no graph structure, and no hidden parameters. The task is to compute a single integer output from this array.

codeforcescompetitive-programming
CF 104412C - Choose Two

Your result “1” corresponds to assuming: every configuration contributes exactly 1 cycle deterministically So the code is effectively treating the structure as if cycles are always fully formed, which is wrong.

codeforcescompetitive-programming
CF 104412N - Necklace

We are given a circular necklace represented as a linear array of pearls, where each position has two attributes: a value and a type.

codeforcescompetitive-programming
CF 104412M - Modify the Array

We are given a permutation of numbers from 1 to n, and we are allowed to repeatedly compress any contiguous segment into a single value equal to the minimum element in that segment.

codeforcescompetitive-programming
CF 104412E - Earnings Report

We are given a collection of jobs, each of which pays a fixed amount repeatedly over time according to a deterministic calendar rule.

codeforcescompetitive-programming
CF 104412H - How Many Groups

We are given a company hierarchy that forms a rooted tree. Each employee has exactly one direct supervisor except for the top-most manager, who has none.

codeforcescompetitive-programming
CF 104395F - Cycles

Now we finally have a clean arithmetic discrepancy, not a parsing failure. The program is correctly producing most outputs, but one value is off: So the structure is correct, input is correct, and indexing is correct.

codeforcescompetitive-programming
CF 104395C - String Keyboard

We are given a line of N distinct keyboard keys, each labeled with a unique uppercase letter. We want to construct a string by repeatedly “pressing” keys, but the key action is slightly unusual: pressing an internal key produces a pair of adjacent characters, namely the…

codeforcescompetitive-programming
CF 104395A - Cow Treats

We are given a chronological log of a barn where cows repeatedly enter and leave. Each line of input describes a single event for a specific cow: if the cow is currently outside, the event means it enters; if it is currently inside, it leaves.

codeforcescompetitive-programming
CF 104393B - BWS Baker Web Service

Now we finally have a clean, precise failure mode: at: This is not an arithmetic bug or logic bug. It is a hard desynchronization of the input parser.

codeforcescompetitive-programming
CF 104393I - Improving the Neighborhood

We are given a small grid representing a neighborhood. Each cell is either a wall, a free traversable tile, a house, a school, or a park.

codeforcescompetitive-programming
CF 104393E - Elisa's Melodies

We are asked to count how many different melodies a constrained “random-walk” system can produce on a circular keyboard. There are $N$ keys arranged in a ring. A melody starts from a fixed key $S$.

codeforcescompetitive-programming
CF 104393H - Harvesting Apples

We are given a row of baskets, each basket having a fixed maximum capacity. Over a sequence of days, apples are harvested and assigned to exactly one basket per day. When apples are added to a basket, the basket can never exceed its capacity.

codeforcescompetitive-programming
CF 104393F - Funny Numbers

We are given a function on integers that repeatedly transforms a number by replacing it with the sum of squares of its digits. Starting from a number $N$, we apply this transformation repeatedly, producing a sequence like $N, F(N), F(F(N)), dots$.

codeforcescompetitive-programming
CF 104393A - Acrobatic Jumping

We are simulating a constrained movement process on a straight line segment of length $N$. Amy starts at position 0 and must eventually reach position $N$.

codeforcescompetitive-programming
CF 104393D - Destroying Asteriods

We are given a vertical grid with many rows and columns, but almost all cells are empty except for one asteroid in each column. Column $i$ contains exactly one asteroid placed at row $ci$.

codeforcescompetitive-programming
CF 104412I - Iron Fist Ketil vs King Canute

We are given two groups of people facing each other in a one-time battle. One side has Ketil’s farmers, the other has Canute’s soldiers.

codeforcescompetitive-programming
CF 104412A - Alaric Magic Partition

We are given a long digit string, and we are allowed to carve it into several disjoint contiguous pieces. Each chosen piece is interpreted as a decimal number, and it is only considered valid if that number is either a prime or a perfect square.

codeforcescompetitive-programming
CF 104400H - Contest Simulation

We are given a programming contest log and need to reconstruct the final ranking of participants under ICPC-like rules, then print the ranking with medal separators. Each participant has a stream of submissions across up to 20 problems.

codeforcescompetitive-programming
CF 104400A - Playf and ABC

We are given a string consisting only of the characters A, B, and C. From this string, we want to extract as many disjoint triples of indices as possible.

codeforcescompetitive-programming
CF 104400L - Timetable Queries

We are given a one-day timetable of length n, where each minute has exactly one bus arriving and each arrival is labeled with a bus number. So the input array is a sequence of identifiers, and the i-th value tells us which bus arrives at minute i.

codeforcescompetitive-programming
CF 104397K - Da Capo

We are given a rectangular 3D region with dimensions $w times h times l$. The task is to completely partition this volume into a set of smaller axis-aligned boxes such that they exactly fill the original space without overlaps or gaps. Each small box is not arbitrary.

codeforcescompetitive-programming
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 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 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 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