brain

tamnd's digital brain — notes, problems, research

41641 notes

CF 106430H - Bessie and GCD

We are given a number $r$, and we want to compute a function built from counting pairs of positive integers under a constraint involving their sum and gcd structure.

codeforcescompetitive-programming
CF 106416G - GATA-CAT

We are asked to construct a short DNA-like string over the alphabet {C, G, A, T}. Each query gives two target values: the number of subsequences equal to C-A-T (CAT degree) and the number of subsequences equal to G-A-T-A (GATA degree), where subsequences preserve order but may…

codeforcescompetitive-programming
CF 106396D - 恶与饿

We are given a sequence of numbers and asked to compute a global value that depends on all increasing subsequences inside it.

codeforcescompetitive-programming
CF 106396E - 梦想

We are given two integer arrays of the same length. Each position contains a pair of numbers, and we are allowed to perform a specific reduction operation that, in essence, keeps replacing a larger value by subtracting the smaller one, similar to repeated Euclidean subtraction.

codeforcescompetitive-programming
CF 106170J - Good Pairs in Graph and Tree

We are given two different structures over the same set of vertices labeled from 1 to N. One structure is a tree, so between any two vertices there is exactly one simple path. The other structure is an arbitrary undirected simple graph.

codeforcescompetitive-programming
CF 106167H - Hectic Harbour II

We are given two stacks of crates. Each crate has a unique label from 1 to n, except one special crate labeled 0, which is “ours” and is not part of the loading order. The initial configuration is fixed: we are told the bottom-to-top order of each stack.

codeforcescompetitive-programming
CF 106164J - Joyeuse

We are given a list of $n$ guests, each carrying a numerical strength value. Every unordered pair of distinct guests forms a dancing duo, and each duo contributes a score equal to the square root of the sum of their two strengths.

codeforcescompetitive-programming
CF 106084L - Stapler

We are given a rectangular screen aligned with the coordinate axes. Its lower-left and upper-right corners define a fixed axis-aligned rectangle in the plane. Separately, we are given a line segment representing the path of a stapler pin, defined by two endpoints.

codeforcescompetitive-programming
CF 106084G - Gamer Bafuko

We are given a tree with weighted edges of weight 1, plus one additional special edge called a portal that connects two fixed vertices $x$ and $y$. The portal can be used any number of times, and every use has cost 0.

codeforcescompetitive-programming
CF 106084A - Take It or Double It

We are given a simple interactive story that reduces to a decision about whether a value should be accepted immediately or allowed to “grow” once more. A starting amount of money $x$ is offered to the first person.

codeforcescompetitive-programming
CF 106082C - Letter Frequency

We are given a text string consisting of letters, and the task is to compute how many times each distinct letter appears.

codeforcescompetitive-programming
CF 106082E - Word Tree

I can’t write a correct editorial yet because the actual problem statement for Codeforces 106082E - Word Tree isn’t included in your message (it looks truncated to just the title and placeholder text).

codeforcescompetitive-programming
CF 106073L - LLMs

We are given three ingredients: a dictionary of words where each word has a fixed 2D integer vector, a long text that acts as a reference corpus, and a set of queries.

codeforcescompetitive-programming
CF 106073G - Generating patterns

We are given a target binary string of length $N$, and we start from an all-zero array of the same length. We are allowed to perform an operation that picks a starting position $i$ and XORs a fixed 8-bit pattern $B$ onto the array, aligned so that $B[j]$ affects position $i+j$…

codeforcescompetitive-programming
CF 106073D - Dominoes

We are given a small collection of domino tiles, each tile labeled with two numbers from 1 to 6. A tile can be used in a sequence if one of its ends matches the currently exposed number at either the left or right end of an evolving chain.

codeforcescompetitive-programming
CF 106072L - Xor Mirror

We are working with a sequence of length $N$, where $N$ is a power of two and can be as large as $2^{18}$. The array supports two operations that both act on a segment $[l, r)$.

codeforcescompetitive-programming
CF 106072E - Zero

We are asked to count sequences of length $n$, where each element is an integer in the range $[0, 2^m - 1]$. Two conditions must hold simultaneously. First, no two adjacent elements are allowed to be equal.

codeforcescompetitive-programming
CF 106072G - Square Permutation II

We are given two permutations of the same length, call them $p$ and $q$. Each position $i$ represents a paired state: one value from $p$ and one value from $q$.

codeforcescompetitive-programming
CF 106068L - Triangle hole

We start with a single equilateral triangle whose size is described by its height $H$. The process is iterative. In each operation, the triangle is subdivided into four congruent equilateral triangles, and only the central one is kept while the other three are discarded.

codeforcescompetitive-programming
CF 106068G - Fire Coverage

We are working on a rectangular city grid with $N$ rows and $M$ columns. You are allowed to place $K$ fire stations on arbitrary grid cells.

codeforcescompetitive-programming
CF 106068B - SCPC is Typing...

We are given a list of positions on a number line, each position representing where a person lives. The goal is to choose one of the given positions as a meeting point so that the sum of walking distances from all people to that chosen point is as small as possible.

codeforcescompetitive-programming
CF 106059K - Karl's Dormitory Allocation

We are given a list of numerical valuations, one per student, representing how much each student values a dormitory spot. Only the top m students by declared value will receive dormitory rights.

codeforcescompetitive-programming
CF 106059C - Chess Pieces

We are given three labeled points in the plane, and each point can be moved repeatedly. A single move picks one of the points and relocates it anywhere in the plane, but under a strict geometric constraint: the angle formed at the moved point by the segments to the other two…

codeforcescompetitive-programming
CF 106059E - Echoes on the Endless Line

We are given positions of enemies and positions of observers on a number line. For each observer, we care about enemies that lie within a specific distance band from them. Each observer at position b defines two radii.

codeforcescompetitive-programming
CF 106057D - Zero is not an option!

We are given a rectangular grid where each cell contains a non-negative integer. From each row, we must pick exactly one element. After selecting one number per row, we compute the bitwise AND of all chosen values.

codeforcescompetitive-programming
CF 105986M - Maximize the total of maximum

We are given a sequence and a constant threshold value. For every contiguous subarray, we compute its sum, then replace that sum by the larger of the sum and the constant. The value of the whole array is defined as the sum of these adjusted subarray values over all subarrays.

codeforcescompetitive-programming
CF 105986J - 莲的简单题

We are asked to construct an array a of length n, where each position i contains a positive integer not exceeding $10^9$.

codeforcescompetitive-programming
CF 105986I - 嘟咕噜之王

We are controlling a single creature whose “state” is an integer value from 0 up to n. We start at state 0 and want to eventually reach state n. There is a shop that sells helper creatures. Buying a helper of value i costs ai, and there is unlimited supply for every i.

codeforcescompetitive-programming
CF 105986F - Major

We are given a fully specified deterministic tournament between 16 teams. Every pair of teams has a fixed outcome encoded in the input: for any initial seed positions i and j, exactly one of them wins if they ever meet, and this result never changes.

codeforcescompetitive-programming
CF 105986E - 怯战蜥蜴 VI

We are given a tree with n nodes. Each node independently contains an enemy with probability pi, given as a fraction ai / bi modulo a large prime. For any choice of a target node x, the protagonist starts from some leaf node and walks along the unique simple path to x.

codeforcescompetitive-programming
CF 105986C - 总辖之愿

We are given a rectangular grid with dimensions $n times m$. On this grid, there are $k$ mineral fields. Each mineral field is defined by a center cell $(xi, yi)$ and a Chebyshev radius $disi$, meaning it occupies every grid cell whose row and column are both within $disi$ of…

codeforcescompetitive-programming
CF 105986A - 自动装配机自动装配自动机

We are building a small team with a limited number of slots, and we want to maximize total attack power. There are two types of units. One type is a basic unit, which always contributes a fixed attack value $a$.

codeforcescompetitive-programming
CF 105930L - Stella

Each input test case gives two stellar classifications written in a fixed format: a capital letter followed by a digit. The letter represents a coarse temperature class ordered from hottest to coldest as O, B, A, F, G, K, M.

codeforcescompetitive-programming
CF 105930I - Square Puzzle

We are given two configurations of a 3 by 3 grid, each cell containing a distinct digit from 1 to 9. So each grid is really a permutation of the numbers 1 through 9 arranged in row-major order.

codeforcescompetitive-programming
CF 105930G - Assembly Line

We are simulating a production pipeline with k workers arranged in a line. Each worker has a private inbox. Over time, n items arrive at specified workers at specified minutes. Once an item is in a worker’s inbox, it participates in a synchronized daily routine.

codeforcescompetitive-programming
CF 105930E - Greatest Common Divisor

We are given a list of positive integers, and we are allowed to perform exactly $k$ operations. Each operation picks a single position and increases that element by 1.

codeforcescompetitive-programming
CF 105930C - Bracket Integer

We are given a decimal integer $A$ with no leading zeros. Think of its digits as positions in a sequence. We want to construct another integer $B le A$ such that the digit sequence of $B$ can be interpreted as a valid weighted parenthesis system.

codeforcescompetitive-programming
CF 105930B - Pinball

We are simulating a point moving inside a vertical strip between two horizontal boundaries, at heights 0 and H. Inside this strip, there are point obstacles called boards. These boards are not intervals or segments, they are exact coordinates.

codeforcescompetitive-programming
CF 105928K - Pleasure of Hope

We are asked to construct an array of length $n$ consisting of distinct positive integers. The array is not arbitrary: every pair of adjacent elements must be coprime, meaning their gcd is exactly 1.

codeforcescompetitive-programming
CF 105928H - An AtCoder-style Problem

We are given a sequence of integers and we repeatedly look at its prefixes. For each prefix of length i, we must decide whether we can construct a permutation of positions and a permutation of values so that the prefix values appear as “window maxima” of a carefully chosen…

codeforcescompetitive-programming
CF 105928G - Navigation Compass

We are given a cyclic structure with $n$ rotating rings, each ring associated with a step size $ai$ and an initial position $bi$ on a regular $m$-gon.

codeforcescompetitive-programming
CF 105928B - Adventure for Black

We are maintaining a dynamic array that starts with an initial sequence and then grows over time by appending elements. Over this evolving array, we are asked to process two kinds of operations that are intentionally obfuscated so that each query depends on the previous answer.

codeforcescompetitive-programming
CF 105928D - Phaethon's Melody

We are given a set of weapon choices and a separate set of support sets. Each weapon has a base attack value and a bonus that contributes either to critical rate or critical damage depending on its type.

codeforcescompetitive-programming
CF 105925M - Spooky Movement at a Distance

We are given an array of integers placed on positions from 1 to N. A “path” is formed by picking any starting position and then repeatedly either stopping or jumping to a strictly larger index.

codeforcescompetitive-programming
CF 105925L - qPhones Production Line

We are given a classical memory size expressed in megabytes and asked how many qubits are needed in a quantum-style model so that it can represent every possible classical memory state of that size.

codeforcescompetitive-programming
CF 105925G - Grover and His Special Paths

We are given a tree where each vertex must be assigned a value from 1 to 5. The number of vertices assigned each value is fixed in advance, so exactly cnt1 vertices must get value 1, exactly cnt2 vertices must get value 2, and so on up to 5.

codeforcescompetitive-programming
CF 105925H - Binary Palindromic Harmony

We are given a single integer $X$. We need to find the largest integer $Y$ such that $Y le X$ and the binary representation of $Y$ is a palindrome.

codeforcescompetitive-programming
CF 105925B - Periodic Search

We are given a rooted tree where each node represents a state of a system, and each edge from a parent to a child is labeled with a lowercase letter.

codeforcescompetitive-programming
CF 105925D - Quantum Decoherence

We are given two strings of equal length representing the state of a collection of qubits. The first string describes an “isolated” configuration, where some positions are stable bits 0 or 1, and some positions are uncertain and marked as , meaning the qubit is in…

codeforcescompetitive-programming
CF 105924L - 澡堂

We are simulating a bathhouse that consists of a grid with 2m rows and n columns. Each cell can hold at most one person. Rows are naturally paired: row 1 faces row 2, row 3 faces row 4, and so on.

codeforcescompetitive-programming
CF 105924I - 王国------求策

We are given a graph with 2n cities split into two rows. The first row contains cities labeled from 1 to n, and the second row contains cities labeled from n+1 to 2n.

codeforcescompetitive-programming
CF 105924G - 加边

We are given an undirected graph with n vertices and m edges. The graph can already contain self-loops and multiple edges between the same pair of vertices.

codeforcescompetitive-programming
CF 105924C - 掼蛋

We are looking at a partially dealt hand from a two-deck card game. The full deck has 108 cards, meaning each rank-suit combination appears twice.

codeforcescompetitive-programming
CF 105924D - 保卫萝卜

We are given a one-dimensional world that behaves like a lane from position 0 to a large endpoint. Enemies spawn at the left end at specific times, each with an initial health value. Once spawned, every enemy moves right by one unit every second.

codeforcescompetitive-programming
CF 105922K - Maximum Profit

We are given a square assignment problem where there are as many employees as jobs. Each employee-job pair has a profit that comes from two parts: a structural part derived from the employee’s skill value and the job’s requirement value, and an optional bonus that applies…

codeforcescompetitive-programming
CF 105922H - Another Palindromes Problem

We are given a mutable integer array. Two types of operations are applied over time. One operation increases every element in a contiguous segment by the same value.

codeforcescompetitive-programming
CF 105922G - Rock-Paper-Scissors

We are given two players who each hold a multiset of Rock, Paper, and Scissors cards. Both players will play all their cards over n rounds, one card per round per player, and each round is evaluated by the usual Rock-Paper-Scissors rules.

codeforcescompetitive-programming
CF 105922D - Coprime

We are given two integers $x$ and $y$ such that there is at least one integer strictly between them. The task is to pick an integer $z$ that lies strictly inside the interval $(x, y)$, and at the same time is “compatible” with both endpoints in the sense that it shares no…

codeforcescompetitive-programming
CF 105922C - SSPPSPSP

We are given an array $a$ of length $n$, and a sequence of $k$ operators, each being either a sum operation or a product operation.

codeforcescompetitive-programming
CF 105920K - Painting the Tree

We are given a tree where each vertex starts with a color. Then we process a sequence of repaint operations, each of which overwrites colors on a specific set of vertices. The goal is to determine the final color of every vertex after all operations are applied in order.

codeforcescompetitive-programming
CF 105920L - Fyreflies

We are given several hidden positions on a number line from 1 to 100000. These positions represent locations of firefly groups. We do not know the positions, and multiple groups may exist at different points.

codeforcescompetitive-programming
CF 105920H - Simple XOR Problem

We are asked to evaluate a range expression over integers from $l$ to $r$. For each number $x$ in this interval, we take the bitwise XOR of $x$ with a fixed integer $y$, interpret the result as a value, and then aggregate those results over the entire range.

codeforcescompetitive-programming
CF 105920G - DSU

We are given a single array f of size n. This array is claimed to be the final state of a Disjoint Set Union structure that started from f[i] = i for every element and then had at most n calls to a merge(u, v) operation. The DSU implementation is slightly asymmetric.

codeforcescompetitive-programming
CF 105920D - Greedy Counting

We are given an array, and instead of computing a classical longest increasing subsequence, we apply a very specific greedy procedure to every contiguous subarray and sum the results.

codeforcescompetitive-programming
CF 105920B - Nabi Puzzle

We are asked to construct an integer array of length n, assigning a value to each position in a line of Nabis. The assignment must satisfy two sliding window constraints simultaneously. For every contiguous segment of length p, the sum of its elements must be strictly positive.

codeforcescompetitive-programming
CF 105911H - Bingo Game

Codeforces 105911H: Bingo Game

codeforcescompetitive-programming
CF 105911M - Divide coins

We start with $n$ identical coins, all initially showing heads. Another player secretly flips exactly $k$ of them to tails, and we do not know which subset was chosen.

codeforcescompetitive-programming
CF 105911L - Regnaissance

We are given a tree with nodes labeled from 1 to n. The structure of the tree is fixed. Each query provides three values l, r, and x, and asks for a single node: if we consider only the nodes in the contiguous label range from l to r, and treat x as the root of the tree, we…

codeforcescompetitive-programming
CF 105911K - Rotation

We are given a row of statues, each initially pointing in one of four directions arranged in a cycle: front, right, back, left, and then back to front again after a full rotation.

codeforcescompetitive-programming
CF 105911I - Dating Day

We are given a binary string representing a schedule over n time slots. Each position is either 1, meaning TreeQwQ is currently on a date, or 0, meaning free time.

codeforcescompetitive-programming
CF 105911G - Exploration

We are given a directed graph where each cave is a node and each one-way passage is a directed edge with a weight called difficulty. Alice starts at a specified node with an initial integer stamina.

codeforcescompetitive-programming
CF 105911B - LEGO-complete

We are given a grid where some cells are marked as occupied and all occupied cells form one connected region if we move in four directions.

codeforcescompetitive-programming
CF 105911D - Virtuous Pope

We are given several line segments inside a rectangular box aligned with the coordinate axes. Each segment has both endpoints on the surface of the box, so every segment “lives” entirely within or on the boundary of the cuboid.

codeforcescompetitive-programming
CF 105902H - Yet Another Tree Problem

We are given a sequence of tree heights. We must perform exactly $s$ operations, and each operation reduces the height of exactly one tree by one unit.

codeforcescompetitive-programming
CF 105902L - We Luv Stamina

We are given a binary grid with n rows and 4 columns. Each cell tells us whether a note exists at that time step (row) and lane (column). A 1 means a note must be played, and a 0 means empty space.

codeforcescompetitive-programming
CF 105902G - Still No Money?

We are given a two-player deterministic game played with a pile of skewers. At the start there are x skewers and a parameter k. Players alternate turns, with OC always moving first.

codeforcescompetitive-programming
CF 105902B - Uchiage Hanabi

We are given a line of positions from 1 to n. A player starts at one of the two endpoints and moves forward in time through m events.

codeforcescompetitive-programming
CF 105902C - Sequential Sequence

We are given an array that changes over time, and we must answer two kinds of queries on it. One query modifies a single position, and the other asks whether a chosen contiguous segment of the array has a very specific property. The property itself is defined indirectly.

codeforcescompetitive-programming
CF 105901L - Subsequence

We are given several integer arrays, and for each one we want to build a subsequence with a very specific structural property. Take any chosen subsequence and sort it.

codeforcescompetitive-programming
CF 105901K - Las Vegas

We are given several independent test cases. In each test case there are multiple casinos and several existing players. For every casino, each of the existing players has already committed a nonnegative number of dice.

codeforcescompetitive-programming
CF 105901G - Path Summing Problem

We are given a grid where each cell contains an integer value, and we consider all monotone paths from the top-left corner to the bottom-right corner, where each move is either right or down.

codeforcescompetitive-programming
CF 105901F - Knapsack

We are given several independent test cases. In each test case, there are multiple groups of identical items. Group i contains aᵢ items, and every item in that group has weight exactly 2^{bᵢ}. All items from all groups must be packed into m identical knapsacks.

codeforcescompetitive-programming
CF 105901A - Problem Setting

We are given a list of numeric attributes, where each attribute starts with an initial value. Alongside this, there are several constraints.

codeforcescompetitive-programming
CF 105901D - Odd and Even

We are given a very long integer sequence, but it is not provided explicitly. Instead, it is given in compressed form as runs of equal values. Each run says that a value v is repeated l times, and adjacent runs always have different values.

codeforcescompetitive-programming
CF 105900L - Lagrange's Legacy

We are given three small integers $A$, $B$, and $C$, and then a list of up to 1000 query values $X1, X2, dots, XQ$. For each query value, we must evaluate a fixed cubic expression, take its absolute value, and finally combine all results using bitwise XOR.

codeforcescompetitive-programming
CF 105900M - Minimum Path

We are given a directed weighted graph where nodes represent gas stations and edges represent one-way roads with travel distances. We start at node 1 and must reach node N. Every valid route from 1 to N has two competing criteria.

codeforcescompetitive-programming
CF 105900H - High-Speed Collision

Two moving objects are given on a 2D plane, each one represented as a rigid triangle. Each triangle is described by three fixed vertices at time zero, and then the entire triangle translates with a constant velocity vector.

codeforcescompetitive-programming
CF 105900G - Graph of Love

Each person chooses exactly one other person as their “true love”. From this we build a directed graph on $N$ vertices where every vertex has exactly one outgoing edge, possibly to itself.

codeforcescompetitive-programming
CF 105900B - Boundless Deck

We are given an infinite collection of cards where each card is labeled by a power of a fixed integer $n$. The first card has value $n^0$, the second $n^1$, the third $n^2$, and so on.

codeforcescompetitive-programming
CF 105900D - Delirium at Unballoon

We are comparing two containers filled with ice cream: a cylindrical bottle and a cone with an extra dome on top. The bottle is a simple cylinder with radius rL and height hL, completely filled. Its capacity is just the usual cylinder volume.

codeforcescompetitive-programming
CF 105895B - Royale Bataille

Codeforces 105895B: Royale Bataille

codeforcescompetitive-programming
CF 105895N - 混沌数字

We are given a noisy black-and-white image represented as an $n times m$ grid of characters. Each cell is either 0 or 1, where 1 corresponds to a white pixel and 0 corresponds to a black pixel.

codeforcescompetitive-programming
CF 105895M - 猫娘部署

We are given a small grid, up to 8 by 8, where each cell is either allowed or forbidden. Allowed cells contain a cat and are marked with a character like Y, while forbidden cells are marked with N.

codeforcescompetitive-programming
CF 105895L - LRU is Best? (Hard Version)

We process a sequence of events where each event reveals a value and a profit structure. Alongside this sequence, we maintain a cache with limited capacity.

codeforcescompetitive-programming
CF 105895J - MEX Should Be Same

We are given a square grid of size $n times n$, where each cell contains an integer between $0$ and $n$. We are allowed to modify at most half of the cells in the grid, rounding down. Each modification replaces the current value with any integer in the same range.

codeforcescompetitive-programming
CF 105895I - So Far Away

We are given a fully connected graph on $n$ vertices, but the edge weights are not arbitrary. Each vertex $i$ has a value $ai$, and the weight of the edge between $i$ and $j$ is defined as $min(ai, aj)$.

codeforcescompetitive-programming
CF 105895H - Syl 和美丽树

We are asked to construct a tree on nodes labeled from 1 to n. The tree must be rooted at node 1, and the only thing that matters in all constraints is the distance from node 1 to every other node in that tree.

codeforcescompetitive-programming
CF 105895G - Syl 和序列操作

We are given a sequence of integers, and the goal is to make all elements equal using a specific operation. Each operation is performed by choosing an index $i$, and then choosing one of three effects. The first effect changes only $ai$ by increasing or decreasing it by 1.

codeforcescompetitive-programming
CF 105895E - 十六行诗

We are given a sequence of integers representing rhyme labels of poems generated line by line. We are allowed to delete any number of lines, but we are not allowed to reorder the remaining ones.

codeforcescompetitive-programming
CF 105895D - Kings Game (Hard Version)

We are given an array of positive integers. Each query focuses on a contiguous segment of this array, and for that segment we are allowed to pick any subsequence (not necessarily contiguous, but preserving order) to form a “game array”.

codeforcescompetitive-programming