brain

tamnd's digital brain — notes, problems, research

41641 notes

CF 106136A - Golden Alleyway

We are given a small ICPC team and a record of how many medals the team wins in a contest. Each gold, silver, and bronze medal corresponds to a fixed prize pool: gold is worth 7500 yuan per team, silver is 3000 yuan per team, and bronze is 1500 yuan per team.

codeforcescompetitive-programming
CF 106136K - Clockwork

We are given an array of length $n$, initially all zeros, and we are allowed to overwrite parts of it using very structured “clock-like” operations. Each operation picks a position $k$ and then writes a distance pattern either to the left side or to the right side of $k$.

codeforcescompetitive-programming
CF 106136D - Mosaic Garden

We are working with a fixed string, ECUST, and the task is to generate every possible string that can be formed by independently choosing the case of each character while keeping the underlying letters unchanged.

codeforcescompetitive-programming
CF 106129L - Labour Laws

We are given a single number that represents the total time an employee was “at work” during a day, measured in minutes. This total includes both actual working time and break time, but the break time was not recorded separately.

codeforcescompetitive-programming
CF 106129G - Generating Cool Passwords Company

We need to construct a collection of passwords, with the number of passwords given as $n$, where $n le 1000$. Each password is a string over printable ASCII characters (from code 33 to 126), and each string must have length between 8 and 12 inclusive.

codeforcescompetitive-programming
CF 106125D - Dralinpome

We are given a single lowercase string and asked to decide whether its letters can be rearranged to form a palindrome. The task is not to construct the palindrome, only to determine whether such a rearrangement exists.

codeforcescompetitive-programming
CF 106114M - Road2

We are given an undirected weighted graph with up to 50,000 vertices and 200,000 edges. Each edge has a weight, and the key operation we care about is not shortest paths in the usual sense, but the bottleneck value along a path.

codeforcescompetitive-programming
CF 106114J - Palindrome

We are given a string and we are interested in its contiguous substrings. A substring is called valid if it avoids a very strong structural restriction: inside it, there must not exist any nontrivial contiguous palindrome of length at least two.

codeforcescompetitive-programming
CF 106114I - Sum

We are given a number $n$ and a bound $R$. For every base $k$ from 2 up to $R$, we write $n$ in base $k$, then compute the sum of its digits. Among all these bases, we want the minimum possible digit sum.

codeforcescompetitive-programming
CF 106114E - Ecosystem

We are given a small set of item types, each type having a fixed “weight” or “cost”. We also have several queries, and each query asks the same question: in how many ways can we build a total sum exactly equal to a given value if we are allowed to use these item types…

codeforcescompetitive-programming
CF 106107M - Roots of Exclusion

We are given an array of values assigned to nodes, and we must build a rooted tree on the same set of nodes so that each node’s value matches a very specific structural property of the tree: the value at node x must equal the mex of all values that appear in the subtree of x.

codeforcescompetitive-programming
CF 106107D - Toward Divisibility

We are given an array of integers and are allowed to perform at most one global modification of a very specific type. In that operation, we pick some subset of positions and add the same integer value to every element in that subset.

codeforcescompetitive-programming
CF 106107H - String Partition

We are given a string and we want to split it into contiguous pieces. Every piece must satisfy a very rigid internal structure: there exists a single integer $x$ (the same for all pieces in a test case) such that inside each piece, every character that appears does so exactly…

codeforcescompetitive-programming
CF 106089E - Просто песня

We are given two sequences of words. The first sequence is a large dictionary of words known to the user, and the second sequence is a song transcription consisting of m words. Every word in both sequences contains exactly one uppercase letter, which marks the stressed character.

codeforcescompetitive-programming
CF 106107C - DGeneral Hamilton's Cubes

We are building a large cube of size $n times n times n$ from $n^3$ identical unit cubes. Every small cube has its six faces permanently labeled with the numbers 1 through 6, one label per face.

codeforcescompetitive-programming
CF 106107K - Least Common Route

We are given a tree where each node carries a positive integer value. For any pair of nodes $u$ and $v$, we look at the unique simple path connecting them in the tree and collect all node values along that path. From these values we compute their LCM.

codeforcescompetitive-programming
CF 106107G - Count the squares

We are given several test cases. In each test case there is a collection of squares, each square having an integer side length.

codeforcescompetitive-programming
CF 106089G - Максимальный XOR

We are given an array of integers. We are allowed to perform exactly one operation: choose two different positions in the array, add a given value x to one chosen element and add another value y to the other chosen element.

codeforcescompetitive-programming
CF 106089B - Гонки

We are given an array of daily speeds. We must choose one contiguous segment of days whose length is at least k. For a segment [l, r], its quality is the arithmetic mean of all speeds inside that segment: $$frac{vl + v{l+1} + dots + vr}{r-l+1}$$ The task is to find any segment…

codeforcescompetitive-programming
CF 106089D - Бег с препятствиями

We have two infinite running tracks indexed by non-negative positions. The runner starts at position 0 and may choose either track initially. At every step, he tries to move forward by exactly one position.

codeforcescompetitive-programming
CF 106088F - Прохождение уровней

We are given a sequence of levels, processed strictly in order from left to right. Each level has a required number of items that must be available before attempting it.

codeforcescompetitive-programming
CF 106088A - Просмотр сериала

We have a sequence of episodes with durations t1, t2, ..., tn. Kolya watches them in order and spends exactly m units of time per day, except possibly on the final day when the series may end before he reaches m.

codeforcescompetitive-programming
CF 106088B - Скучный урок

We are given a rectangular grid of size $n times m$. From this grid, we choose a sub-rectangle aligned with the grid lines, meaning we pick a contiguous block of rows and columns.

codeforcescompetitive-programming
Kvant Physics Problem 375

Two blocks of masses $m_1$ and $m_2$ rest on a horizontal rough surface with coefficient of friction $k$, which acts as the coefficient of static friction limiting the onset of motion.

kvantphysics
CF 106088D - Два числа

We are given an array of even length. The process repeatedly transforms the array in a very specific way: every element shifts influence two positions forward, since each position is updated using the value two steps ahead, and then the last two elements are discarded.

codeforcescompetitive-programming
CF 106088G - Три грядки

We are given a weighted grid, where every cell of an $n times m$ board contains a positive value representing “yield”. The task is to place exactly three identical rectangular plots on this grid.

codeforcescompetitive-programming
CF 106088E - Аварийная дорога

We are given a weighted tree with $n$ cities. Every pair of cities is connected by exactly one simple path, and each road has a positive length. Two special cities $s$ and $t$ are fixed, and the main object of interest is the shortest path between them in this tree.

codeforcescompetitive-programming
CF 106088C - Парные браслеты

We are given two sequences of length n, representing numbers written on two bracelets. The goal is to make the two multisets of numbers identical, meaning that after reordering, both bracelets contain exactly the same values with the same multiplicities.

codeforcescompetitive-programming
CF 106089H - Фёдор и ферзи

We are given an n by n chessboard, where n is at most 16, and we must place exactly k queens. A queen behaves normally, attacking along its row, column, and both diagonals. A cell is considered protected if at least one queen attacks it or if a queen stands on it.

codeforcescompetitive-programming
CF 106089F - Достойное продолжение

We are given a set of distinct integers, each having at least two digits. For every ordered pair of different numbers, we want to check a simple digit condition: the last digit of the first number must match the first digit of the second number.

codeforcescompetitive-programming
CF 106089A - K-интересные подотрезки

We are given a sequence of elements and a parameter that controls what makes a subarray “interesting”. The task is to consider all contiguous subsegments of the array and determine how many of them satisfy a constraint based on how diverse their contents are.

codeforcescompetitive-programming
CF 106089C - Студент и электрички

We are given a railway line of cities arranged in a straight sequence. Each city has a platform with a fixed height. There are train routes, and each route connects an interval of cities. A train route also has two important parameters: a class and a floor height.

codeforcescompetitive-programming
CF 106107L - Integer Average

We are given several test cases. In each test case, there is an array of positive integers, and the task is to determine whether we can pick a subsequence of length at least two whose average value is an integer.

codeforcescompetitive-programming
CF 106107J - Down the rabbit hole we go!

We are simulating a population of rabbits that evolves over time with two independent behaviors. We start with two fully grown rabbits on day zero.

codeforcescompetitive-programming
CF 106107I - Binary Reverser

We are given an array of numbers and a binary string of the same length. We process indices from left to right. At position i, if the binary character is 1, we take the prefix of the array from 1 to i and reverse it in place; otherwise we do nothing.

codeforcescompetitive-programming
CF 106107F - A bitty problem

We are given an integer array, and we are allowed to modify its elements. The goal is to make the array follow a very rigid structure: every pair of adjacent elements must have the same XOR value.

codeforcescompetitive-programming
CF 106107E - Permutation XORpectation

We are given a length $n$, and we consider all permutations of the numbers from $1$ to $n$. For each permutation $p$, we define its score as the sum of bitwise XORs between adjacent elements, meaning we look at $p1 oplus p2 + p2 oplus p3 + dots + p{n-1} oplus pn$.

codeforcescompetitive-programming
CF 106107B - CoCo Count

We are given two arrays of the same length, and we want to count subarrays based on a relationship between values in the first array and values in the second array over the same segment.

codeforcescompetitive-programming
CF 106107A - Zigzag Parity

We are asked to construct a permutation of numbers from 1 to n such that consecutive triples behave in a very specific alternating way when viewed through parity of adjacent sums.

codeforcescompetitive-programming
CF 106114L - Larger or Smaller

We are working with permutations of the numbers from 1 to n. For any such permutation, we look at each position i and compare the value pi with its index i. Some positions satisfy pi < i, some satisfy pi i, and the remaining satisfy pi = i.

codeforcescompetitive-programming
CF 106114H - SYSU III

We are given a string over the alphabet {s, y, s, u} and we are interested in extracting as many disjoint subsequences equal to the pattern sysu as possible.

codeforcescompetitive-programming
CF 106114D - Perfect Life

We are given a string $S$ and a pattern string $T$. The operation allowed is to choose any substring of $S$ whose length equals $ A key way to reinterpret this is that we are not directly editing characters one by one.

codeforcescompetitive-programming
CF 106114A - Abacus

We are given a rectangular arrangement of cells with n rows and m columns. Each row i initially contains a block of ai stones packed on the left side, so in row i, columns 1 through ai are filled, and the remaining cells are empty.

codeforcescompetitive-programming
CF 106118M - Mine

We are working on a hidden grid of size $R times C$, where some unknown cells contain mines. The exact number of mines is not given, and their positions are completely hidden.

codeforcescompetitive-programming
CF 106118K - King of Tic-Tac-Toe

We are given a 3 × 3 Tic-Tac-Toe board. Each cell contains either X, O, or .. The board is not guaranteed to be a valid state from a normal game, so the counts of X and O do not matter. Nobita gets a special power: he may place two O marks consecutively on any two empty cells.

codeforcescompetitive-programming
CF 106118J - Jinglebell

We are given a graph of locations. There is a special node labeled 0, which represents Doraemon’s workshop, and there are n other nodes representing houses. Each house is marked as either good or bad.

codeforcescompetitive-programming
CF 106118I - Illuminated Ray Cast

We are given a sequence of vertical poles placed at integer coordinates on a line, where pole i sits at position x = i and has height h[i].

codeforcescompetitive-programming
CF 106118F - Flipping Pyramid

We are working on an infinite triangular grid where each cell is a location you can stand on, and each move corresponds to “flipping” a rigid tetrahedron from one cell to an adjacent cell.

codeforcescompetitive-programming
CF 106118E - Exotic Array

We are given an array of length $n$, where every entry must be an integer between $1$ and $m$. Among all such arrays, we are asked to count those that satisfy a very rigid structural constraint involving values of the array acting like a function on indices.

codeforcescompetitive-programming
CF 106118G - Graph Game

I can't write a correct editorial and solution for this problem from the statement alone. The problem you provided is from a recent ICPC contest (Gym 106118G), and the key part needed for an editorial is deriving the actual accepted solution.

codeforcescompetitive-programming
CF 106118B - Balloon Trip

We are given a line of mountains, each with an initial height. A journey is defined as walking from index $l$ to $r$, always moving one step to the right, and paying the cost of each move as the absolute difference between consecutive heights.

codeforcescompetitive-programming
CF 106118A - Arranging Teams

We are given a fixed set of n players, each with a strength value. We must choose a single ordering of these players, and that ordering will be reused unchanged against m different opponent teams.

codeforcescompetitive-programming
CF 106124J - Jump

We are simulating a performer who repeatedly jumps in cycles whose duration depends on his current energy. Each jump lasts exactly $E$ milliseconds at the moment it starts, and the jumps are chained back to back as long as energy remains positive.

codeforcescompetitive-programming
CF 106124I - Instagraph

We are given a directed graph where each vertex represents a person and each directed edge represents a “follows” relationship. If there is an edge from $u$ to $v$, then person $u$ follows person $v$.

codeforcescompetitive-programming
CF 106124G - Gotta Trade Some of 'Em

We are given a social network of kids, represented as an undirected graph where vertices are kids and edges represent friendships. Each kid must be assigned exactly one game variant from a pool of k possible variants.

codeforcescompetitive-programming
CF 106124E - Egyptian Equality

The input describes a triangular “pyramid-shaped” subset of a rectangular grid. Each row is centered inside a fixed-width grid of size $2N-1$, and row $i$ contains exactly $2i-1$ usable cells forming a symmetric triangle.

codeforcescompetitive-programming
CF 106124B - Bohemian Bookshelf

We are given a set of books, each book having a spine height and a thickness. We need to place every book into exactly one of two groups: one group is placed upright on the shelf, and the other group is stacked horizontally into a single pile.

codeforcescompetitive-programming
CF 106124C - Crochet Competition

We are given two timestamps that describe when a crochet competition started and when it ended. Each timestamp contains a weekday together with a clock time in hours and minutes. The goal is to compute how long the competition lasted, measured in days, hours, and minutes.

codeforcescompetitive-programming
CF 106125L - Landgrave

We are given a set of points in the plane, each representing a tower placed at distinct coordinates. The task is to select some of these towers and connect them in a cycle so that they form a simple polygon, and this polygon must satisfy a geometric constraint: every interior…

codeforcescompetitive-programming
CF 106125J - Journal Publication

We are given a fixed sequence of authors, and each author comes with up to ten possible strings, each string being one part of their full name. We must choose exactly one string per author.

codeforcescompetitive-programming
CF 106125I - Ingredient Intervals

We are given a list of ingredients that appear on a product label. Some ingredients have a known percentage, and others are left unspecified.

codeforcescompetitive-programming
CF 106125H - Hidden Sequence

We are given three strings consisting of the characters 1, 2, and 3. The hidden object is the real sequence of game winners. If player 1 wins a game, then players 2 and 3 write down 1, but player 1 forgets to record that game.

codeforcescompetitive-programming
CF 106125E - Entropy Evasion

We are given a binary array of length $n le 1000$, initially all zeros. We do not directly set bits. Instead, we repeatedly choose a contiguous segment $[l, r]$, and the system “exposes” that segment to randomness, replacing every bit inside it with an independent fair coin…

codeforcescompetitive-programming
CF 106125F - Friendly Formation

We are given a group of $n$ players and a list of pairs of players who already know each other. The task is to divide all players into exactly two teams of equal size, and the constraint is that within each team every pair of players must already know each other.

codeforcescompetitive-programming
CF 106125C - Calculation Obfuscation

We are given a multiset of characters that originally formed a valid arithmetic expression, but all characters have been shuffled. Our task is to decide whether we can rearrange these characters into a syntactically valid expression, and if yes, output one such expression.

codeforcescompetitive-programming
CF 106125B - Bottle of New Port

We are given a bottle that initially contains two kinds of liquid: alcohol and everything else. Over time, both parts evaporate, but at different constant rates per day.

codeforcescompetitive-programming
CF 106129M - Mex Hex

We are given a sequence of spell values, each a non-negative integer, and a shield with a very specific usage pattern.

codeforcescompetitive-programming
CF 106129J - Jumbled Packets

We are given a system where a sender receives a binary string and must transmit it through a very unreliable channel. The channel does not preserve boundaries of the transmitted packet. Instead, what arrives is a cyclic shift of what was actually sent.

codeforcescompetitive-programming
Kvant Math Problem 1250

Once you provide it, I’ll write a complete, rigorous solution in the style typical of Kvant: clear structure, justified steps, and (when useful) a clean geometric or algebraic insight rather than just…

kvantmathematicsolympiad
CF 106129I - Island Urbanism

We are given a graph that is physically organized in a very rigid way. The junctions are split into villages, and these villages appear in a fixed circular order.

codeforcescompetitive-programming
CF 106129F - Fair and Square

We are given an $h times w$ grid representing a pizza that was originally fully filled with square unit pieces. Some cells are still present, marked as , while others have been eaten, marked as .. We are not allowed to move any remaining pieces, only to partition what remains.

codeforcescompetitive-programming
CF 106129E - Engineering Excellence

We are given a simple geometric structure: a convex polygon described by its vertices in counterclockwise order. The polygon is already well-behaved in a strong sense.

codeforcescompetitive-programming
CF 106129B - Bustling Busride

We are given a single bus line that starts at the university and goes through a sequence of stops in order until the city. There is a queue of passengers at the university, and each passenger has a fixed destination stop index.

codeforcescompetitive-programming
CF 106129A - Around the Table

We are simulating a very structured game involving two queues of players standing on opposite sides of a table. On the left side there are ℓ players arranged in a queue, and on the right side there are r players arranged in another queue.

codeforcescompetitive-programming
CF 106130N - 缩花

We are given a tree, and we are allowed to repeatedly perform a very specific restructuring operation. Each operation first picks a node as the temporary root, which defines parent and child relationships for that step. Then we choose a non-root node $u$.

codeforcescompetitive-programming
CF 106130M - 字符消消乐

We are given a lowercase string. Before the game starts, we may rearrange its characters in any order we like. A single elimination operation chooses a contiguous block consisting of the same character, and that block must have length at least 3.

codeforcescompetitive-programming
CF 106130L - 翻转硬币

We are given a binary string representing a row of coins. Each position is either 0 or 1, and the goal is to transform the entire string into all 1s. The only allowed operation is choosing two adjacent positions and flipping both coins simultaneously.

codeforcescompetitive-programming
CF 106130B - k-冲突数对

Thinking

codeforcescompetitive-programming
CF 106130J - 逃出生天

We are given a grid with $n+2$ rows and $m$ columns. The top row and the bottom row are safe, while the $n$ middle rows each contain exactly one stone statue. Each statue sits at a specific column in its row and faces either left or right.

codeforcescompetitive-programming
CF 106130G - 俄罗斯方块的博弈

We are playing a turn-based placement game on a fixed 4 by 4 board, so there are only 16 cells in total. Two kinds of tetromino pieces are available: T-shaped pieces and L-shaped pieces. We are given a limited supply, at most three of each type.

codeforcescompetitive-programming
CF 106130H - 我不吃水果

We have an $n times n$ cake represented as a grid. A cell contains either no fruit (0) or a fruit (1). The piece that Xiao Z cuts must come from the top-left corner of the cake.

codeforcescompetitive-programming
CF 106130E - 新田忌赛马

We are given two descendingly sorted arrays of horse speeds. One belongs to Tian Ji and the other to the King. A match is formed by pairing one unused horse from each side, and the outcome depends on a strict comparison: Tian Ji earns money only when his chosen horse is…

codeforcescompetitive-programming
CF 106130C - 序列重构(简单版)

We are interacting with a hidden permutation of size $n$. The permutation is fixed before any queries, and each query allows us to submit any length-$n$ array. The system responds with how many positions match exactly between our submitted array and the hidden permutation.

codeforcescompetitive-programming
CF 106132H - Prescription Dosage

A patient is given a weight in kilograms and a prescribed total drug dosage in milligrams. The drug has a safety guideline expressed per unit weight: every kilogram of body mass allows a safe dosage between 10 and 20 milligrams, inclusive.

codeforcescompetitive-programming
CF 106132F - LCS of DFS orders

We are working with a tree where each vertex can be chosen as a starting point for a preorder DFS traversal. In such a traversal, we visit a node, then recursively traverse its neighbors in some arbitrary order, producing a linear sequence of all vertices.

codeforcescompetitive-programming
CF 106132E - Expression Evaluation

We are given a single arithmetic expression written as a compact string. The expression contains only decimal digits, plus signs, and multiplication signs. Each digit is a standalone number, so there are no multi-digit integers and no parentheses.

codeforcescompetitive-programming
CF 106132A - Range Affine Update and Modulo Query

We are maintaining a very large array of integers, supporting two kinds of operations over it. The first operation applies an affine transformation to every element in a contiguous segment: each value a[i] is replaced by a[i] c + d.

codeforcescompetitive-programming
CF 106132B - Number of Inversions

We are given a static array of integers and many independent operations. Each operation describes a segment of the array, and we conceptually perform three actions for that segment: reverse the subarray inside the interval, compute how many inversions the whole array would…

codeforcescompetitive-programming
CF 106136O - Nelumbo

We are working with a tree where each node carries an integer weight. For every pair of distinct nodes, we look at the unique path between them and collect all node weights along that path.

codeforcescompetitive-programming
CF 106136M - FLOATING POINT

We are asked to construct a strictly increasing sequence of length $n$, where every element is a non-negative integer below $2^{30}$.

codeforcescompetitive-programming
CF 106136J - Attack from clone

We are given an initial multiset of integers that already has a very rigid structure: it is an arithmetic progression of length $n$, starting at $a1$ with common difference $d$. So the starting set is completely determined and sorted automatically.

codeforcescompetitive-programming
CF 106136I - Chromatic Complex

We are given a large grid where each cell is either land, water, or lava. Lava is forbidden, while land and water are traversable.

codeforcescompetitive-programming
CF 106136E - Fortress Fall

We are given a list of ingredient freshness values and two fixed recipe coefficients. Each day, Maddy must pick exactly two unused ingredients and assign them to the two recipes in any order.

codeforcescompetitive-programming
CF 106136F - The Tower(XVI)

We start with a decimal number written on a stone. Each time we press a mechanism, we transform the number by replacing every digit independently with the square of that digit, written in decimal, and then concatenating these squared values in the same order.

codeforcescompetitive-programming
CF 106136C - Time Trouble

We are given two small integers for each test case, and we must decide whether we can interpret them as the two fields of a valid 24-hour clock time in the format HH:MM.

codeforcescompetitive-programming
CF 106136B - Seeing is believing

We are given a small integer range defined by a starting point l. The hidden number a is guaranteed to lie somewhere in the interval from l up to l + 5, so at most six consecutive integers are possible candidates.

codeforcescompetitive-programming
CF 106139K - Character Walk

We are given a string, and we place integer markers on positions from 0 to n, where position i represents the boundary between characters.

codeforcescompetitive-programming
CF 106139D - Box

We have an initially empty n × m grid. An operation can be performed at any cell. A type 1 operation fills every cell in the chosen row and every cell in the chosen column. A type 2 operation fills every cell on the two diagonals passing through the chosen cell.

codeforcescompetitive-programming
CF 106139J - Triangles and Squares

I can’t write a correct editorial from “J” alone because there’s no problem content to reconstruct the logic, constraints, or even the task being solved. Anything I produce right now would be guesswork, and that would break the whole point of a Codeforces-style editorial.

codeforcescompetitive-programming
CF 106139I - Tearing Paper

The problem statement is missing from what you provided. All that appears is a single “I”, which isn’t enough to reconstruct the task, constraints, or required output.

codeforcescompetitive-programming