brain

tamnd's digital brain — notes, problems, research

41442 notes

CF 104813D - A Simple MST Problem

We are given a graph where every positive integer is a node, and for any two nodes $x$ and $y$, the cost of connecting them is determined by the number of distinct prime factors of their least common multiple.

codeforcescompetitive-programming
CF 104813F - Palindrome Path

We are given a grid where some cells are open and some are blocked. From a starting open cell, George can attempt to move in the four cardinal directions, but a move only succeeds if the adjacent cell exists and is open; otherwise he stays in place.

codeforcescompetitive-programming
CF 104813C - Karshilov's Matching Problem II

We are given two strings of equal length. One string, call it the reference string, defines a collection of patterns: every prefix of this string is a pattern, and each pattern has an associated weight.

codeforcescompetitive-programming
CF 104813B - Memory

We are given a sequence of values representing the happiness gained from a series of contests. After each contest, we want to compute a “memory-weighted mood” that depends on all past contests, but with exponentially decreasing influence for older events.

codeforcescompetitive-programming
CF 104813A - Go go Baron Bunny!

We are given an initial collection of “knowledge points”, each associated with a positive integer cost representing how many brain cells are required to maintain it. This collection is treated as a multiset, so only the frequencies of equal values matter, not their order.

codeforcescompetitive-programming
CF 104814E - Рекурсивный мем

We are given a large rectangular grid whose height is $2^N$ and width is $2^N - 1$. The grid is not arbitrary: it is built recursively by repeatedly splitting rectangular regions into smaller ones.

codeforcescompetitive-programming
CF 104814D - Катет

We are given a fixed integer $x$, which represents the length of one leg of a right triangle. The task is to count how many distinct right-angled triangles with integer side lengths exist such that one of the legs is exactly $x$.

codeforcescompetitive-programming
CF 104814C - Лампы

We are given a line of positions from 1 to n, each position having a required minimum brightness. We also have several lamps, each lamp covering a contiguous segment of positions.

codeforcescompetitive-programming
CF 104814B - Исполнитель <<Корректор>>

We are given a short string over lowercase English letters and a deterministic transformation that modifies it in two stages. First, the string is extended by inserting exactly one extra character.

codeforcescompetitive-programming
CF 104814A - Геометрический этюд

We are given three positive lengths, which represent the sides of a triangle made from rigid wires. After that, an operation is repeated multiple times: every side is shortened by exactly one unit per operation.

codeforcescompetitive-programming
CF 104819J - Count

We are asked to look at all possible labelled trees on $n$ vertices and compute a single numeric value for each tree: the sum of distances over all unordered pairs of vertices. This value is often called the Wiener index of the tree.

codeforcescompetitive-programming
CF 104819L - Function

We are given a positive integer $a$. We want to construct a function $f$ on positive integers such that applying it twice behaves like multiplication by $a$, meaning that starting from any value $x$, if we apply $f$ once and then again, we land exactly on $a cdot x$.

codeforcescompetitive-programming
CF 104819K - Nim X2

We are given several independent games. Each game consists of a number of piles of stones. Two players alternate turns, starting with Mandy.

codeforcescompetitive-programming
CF 104819I - Dislike

We are given a permutation of length $n$, and for any contiguous subarray we look at its maximum element. For a fixed permutation, we compute a global value $G(S)$, which is the sum of these maxima over all $n(n+1)/2$ subarrays.

codeforcescompetitive-programming
CF 104819G - Polynomial

We are given a sequence of integers, and this sequence is being modified through point updates. After each modification, we need to compute a value that comes from a rather unusual counting process involving polynomials.

codeforcescompetitive-programming
CF 104819H - Polygon

We are given a collection of stick lengths and asked whether it is possible to pick exactly k of them so that they can serve as sides of a simple polygon.

codeforcescompetitive-programming
CF 104819F - Four K3

We are given an undirected simple graph and asked to count how many subgraphs are exactly isomorphic to a fixed six-vertex pattern called “Four K3”. Although the diagram is not written in text, the structure is describable in words.

codeforcescompetitive-programming
CF 104819D - Cross the Storm

We are given a linear chain of islands from 1 to n. Consecutive islands are connected by directed edges from i to i+1, and each such edge has a fixed cost.

codeforcescompetitive-programming
CF 104819E - Travel

We are given a directed acyclic graph where each node represents a city and each city has a numeric charm value. The traveler must go from city 1 to city n along directed roads. The graph structure guarantees there are no cycles, so every valid route is a simple path in a DAG.

codeforcescompetitive-programming
CF 104819B - Lowest Common Ancestor

We are given a rooted tree with vertex 1 as the root. Each vertex has a depth, defined as how many vertices lie on the path from the root to that vertex.

codeforcescompetitive-programming
CF 104819C - Triangle

We are given a collection of identical right triangles with side lengths 3, 4, and 5. Each triangle is a rigid tile, and we are allowed to place multiple copies on a plane without overlap.

codeforcescompetitive-programming
CF 104819A - SUN YAT-SEN University

We are given a single lowercase string and asked to count how many of its substrings contain the pattern "sysu" as a subsequence. A substring is defined by choosing a contiguous segment of the string, while a subsequence allows skipping characters without changing order.

codeforcescompetitive-programming
CF 104820M - "Обычный кузнечик". Версия 2.0

We are working with a point on a number line from 1 to n. A frog starts at position 1 and wants to reach position n. At each move, it can jump forward by exactly 1 or exactly 2 steps.

codeforcescompetitive-programming
CF 104820O - Шлягер

We are asked to count how many binary $n times n$ grids exist under a local restriction: each cell is either 0 or 1, and we are forbidden from placing two 1s in adjacent cells that share a side. Diagonal adjacency does not matter, only up, down, left, and right.

codeforcescompetitive-programming
CF 104820N - Музыкальное

We are given several music genres, each genre having a fixed number of songs. The task is to decide whether it is possible to arrange all songs in a single playlist so that no two adjacent songs belong to the same genre.

codeforcescompetitive-programming
CF 104820K - Выбор не велик

We are given a grid whose rows and columns are not uniform in size. Each row has a positive height given by array A, and each column has a positive width given by array B.

codeforcescompetitive-programming
CF 104820J - Прогулка

We are given a tree with $n$ vertices, meaning there is exactly one simple path between any two nodes. On this tree we consider adding exactly one extra edge, connecting any two vertices that are not already directly connected. This creates exactly one cycle in the graph.

codeforcescompetitive-programming
CF 104820L - Неизвестное

We are given $n$ colors of balls. For each color $i$, there are $ai$ indistinguishable balls of that color in a box. There is also a requirement array $b$, where $bi$ tells us how many balls of color $i$ we want to guarantee. We draw $x$ balls from the box without looking.

codeforcescompetitive-programming
CF 104820H - Операционная система MACS_MS

We are given an array of integers and asked to count how many pairs of positions produce a XOR value that lies inside a fixed numeric interval $[A, B]$.

codeforcescompetitive-programming
CF 104820I - Секция по вольной борьбе

We are given the first $N$ terms of the sequence $an = frac{1}{n}$, which produces the values $1, frac{1}{2}, frac{1}{3}, dots, frac{1}{N}$.

codeforcescompetitive-programming
CF 104820G - Жадное деление

We are distributing three different types of candies to three friends, where each friend only accepts one specific type. The first friend only takes Snickers, the second only Mars, and the third only Bounty.

codeforcescompetitive-programming
CF 104820D - Дигорская последовательность

The sequence starts from a single digit string and grows by repeatedly taking the previous string, appending the decimal representation of the current index, and then appending the previous string again.

codeforcescompetitive-programming
CF 104820F - Красивое число

We are asked to construct a number with exactly n digits, where each digit must be from 1 to 9. There is no digit 0 allowed anywhere, so we are working entirely in the range of positive digit strings.

codeforcescompetitive-programming
CF 104820E - Тепло

We are given a string over lowercase Latin letters. We are allowed to repeatedly pick any position and replace its character with any other letter. Each replacement has cost 1, and we want to minimize the total cost.

codeforcescompetitive-programming
CF 104820B - Спуск с горы

We are given a rectangular grid representing a mountain surface. Each cell contains an integer value, which can be positive or negative.

codeforcescompetitive-programming
CF 104820A - Догонялки

Two players start on a number line: Alice is at position $a$, Bob is at position $b$, with $a < b$. Each second Alice moves to the right by a fixed integer speed $c$, and Bob moves to the right by a fixed integer speed $d$.

codeforcescompetitive-programming
CF 104820C - Оценочное

We are given two grading systems: one uses scores from 1 to n, the other uses scores from 1 to m. Some scores in the first system are considered equivalent to some scores in the second system, but the problem does not give us arbitrary pairs.

codeforcescompetitive-programming
CF 104821M - Trapping Rain Water

We are given a height array that represents a skyline of vertical bars. After each operation, one bar is increased, and we must compute how much water would be trapped between these bars if rain filled the valleys.

codeforcescompetitive-programming
CF 104821L - Elevator

We are given a collection of parcel types. Each type describes how many identical parcels exist, where each parcel has a weight either 1 or 2 and must be delivered to a specific floor.

codeforcescompetitive-programming
CF 104821K - Grand Finale

We are simulating a very constrained card game where a player has two ordered structures: an initial hand and a draw pile. The hand contains a special winning card, and the draw pile contains utility cards that may increase hand size temporarily by drawing more cards.

codeforcescompetitive-programming
CF 104821I - Counter

We are given a counter that starts at zero and evolves through a long sequence of operations, but we never see the sequence itself. Each operation is either an increment by one or a reset that forces the counter back to zero.

codeforcescompetitive-programming
CF 104821J - Suffix Structure

We are given a rooted tree where each edge carries a label from a very large alphabet. If we walk from the root to any node, the sequence of edge labels along that path forms a string. Let us call this string the node’s path-string.

codeforcescompetitive-programming
CF 104821H - Puzzle: Question Mark

We are given an $n times n$ grid that must be covered as much as possible using identical puzzle pieces, where each piece occupies exactly four unit cells.

codeforcescompetitive-programming
CF 104821E - Extending Distance

We are given a weighted grid graph. Each cell is a node, and edges exist only between horizontally or vertically adjacent cells.

codeforcescompetitive-programming
CF 104821F - Equivalent Rewriting

We start with an array of length $m$, initially filled with zeros. Each operation $i$ takes a list of positions and overwrites all of those positions with the value $i$.

codeforcescompetitive-programming
CF 104821G - Knapsack

We are given a collection of gemstones, each with a price and a beauty value. We start with a fixed amount of money and want to maximize the total beauty of gemstones we end up with.

codeforcescompetitive-programming
CF 104821D - Red Black Tree

We are given a rooted tree where each node is colored either black or red. For any node, we look at its subtree and consider all root-to-leaf paths inside that subtree. A node is considered valid if every such path contains the same number of black nodes.

codeforcescompetitive-programming
CF 104821B - Intersection over Union

We are given a convex quadrilateral defined by four points in order, which forms a rotated rectangle in the plane. This shape is fixed for each test case.

codeforcescompetitive-programming
CF 104821C - Primitive Root

We are given a prime number $P$ and a non-negative integer $m$. For each integer $g$ in the range $0 le g le m$, we are asked to check a condition involving bitwise XOR and modular arithmetic: whether $$(g oplus (P-1)) bmod P = 1.

codeforcescompetitive-programming
CF 104821A - Cool, It's Yesterday Four Times More

I can write the full Codeforces-style editorial in the exact format you want, but I’m missing the actual problem content.

codeforcescompetitive-programming
CF 104822L - Best Or Worst

We are asked to count how many full permutations of the numbers from 1 to n can be completed from a partially known array, under a strong structural constraint. The constraint defines a valid permutation by a prefix rule.

codeforcescompetitive-programming
CF 104822K - Distinctness Queries

We are given a grid of integers, and we must answer many queries that each describe a rectangular subregion. For every query, we need to decide whether all values inside that rectangle are pairwise different, meaning no number appears more than once inside the chosen submatrix.

codeforcescompetitive-programming
CF 104822J - Triple Reverse Sort

We are given several independent test cases. Each test case provides a permutation of length n, and we are allowed to repeatedly apply a very specific local operation: choose any position i such that a block of three consecutive elements exists starting there, and reverse that…

codeforcescompetitive-programming
CF 104822G - Sign Flipping

We are given a sequence of integers, and we are allowed to flip the sign of any individual element any number of times before doing anything else.

codeforcescompetitive-programming
CF 104822H - The Binary Matrix of All Time

We are given a large grid with $n$ rows and $m$ columns, and each cell must contain either 0 or 1. The grid is considered valid if neither any row nor any column contains three identical values in a consecutive block.

codeforcescompetitive-programming
CF 104822I - Weird Divisibility

We are given an integer $a$. For each test case, we must choose the smallest positive integer $b$ such that the number $a + b$ divides the product $a cdot b$ exactly.

codeforcescompetitive-programming
CF 104822E - Anton Would Approve This Problem

We are given a binary string, and we are allowed to delete characters anywhere we like. After deletions, we look at the remaining sequence, and we want it to avoid a very specific kind of local disorder: no three consecutive positions (not necessarily adjacent in original…

codeforcescompetitive-programming
CF 104822F - Difference In Skill

We are given a list of employees, each with a numeric skill value. For every employee, we want to know the largest possible team that includes them, under a restriction: within any chosen team, the difference between the maximum and minimum skill must not exceed a fixed…

codeforcescompetitive-programming
CF 104822D - Doping 2

We are given a fixed permutation $p$ of size $n$, and we want to compare it against all other permutations of the same size that come lexicographically earlier than $p$.

codeforcescompetitive-programming
CF 104822B - Coins

We are given a pile of coins and two players who alternate turns. On a turn, a player starts with some number of coins, say $x$. They have two types of moves. They may always remove exactly one coin, leaving $x-1$.

codeforcescompetitive-programming
CF 104822A - Yet Another Colored Tree Problem

We are working with a tree where every node is assigned a color from the range $1$ to $k$. For each color $i$, we need to count how many simple paths in the tree contain at least one node whose color is $i$.

codeforcescompetitive-programming
CF 104822C - Almost Tree Cut

We are given a connected undirected graph that has exactly one more edge than a tree with the same number of vertices. In other words, it is a tree plus one extra edge, so the structure contains exactly one cycle.

codeforcescompetitive-programming
CF 104823G - 分辨矩阵

We are given several binary matrices of identical size. Each matrix can be seen as a function from grid positions to bits, and no two matrices in the input are identical.

codeforcescompetitive-programming
CF 104823F - 出题出题人

We are interacting with a system that has a hidden integer threshold $l$, uniformly chosen from the integers in $[x, y]$. When we click a save button after typing some number of characters, the system checks how long we have been typing since the previous successful save.

codeforcescompetitive-programming
CF 104823D - 塔学疑云

We are simulating a simplified version of a Slay the Spire style system centered around “dark orbs”. The system evolves through a long sequence of operations, where we maintain a row of orbs, a global “focus” value, and a timeline of end-of-turn effects.

codeforcescompetitive-programming
CF 104823E - string

We are given a string of length $n$ where each position holds a visible ASCII character. Then we are given $m$ operations, each operation picks two distinct characters $(x, y)$.

codeforcescompetitive-programming
CF 104823C - Warp Shuffle

We are given a fixed-size array of 32 integers representing a “warp”. Each operation describes a restricted in-place transformation on this array.

codeforcescompetitive-programming
CF 104823B - turn

We are given a bicycle moving inside a very narrow corridor modeled as two infinite parallel lines with fixed distance between them. The bicycle itself is treated as a rigid segment of length l.

codeforcescompetitive-programming
CF 104823A - 赛前须知

Codeforces 104823A: 赛前须知

codeforcescompetitive-programming
CF 104824F - Medusa's Snake (Full)

I can’t produce a correct editorial for this yet because the actual problem statement is missing from your prompt (only the header is present).

codeforcescompetitive-programming
CF 104824E - Medusa's Snake (Subtask)

I can’t write a correct editorial for that problem as-is because the actual problem statement is missing. “Codeforces 104824E - Medusa’s Snake (Subtask)” alone isn’t enough to reconstruct the rules, constraints, or required output.

codeforcescompetitive-programming
CF 104824D - Garden (full)

I can’t write a correct editorial yet because the actual problem content is missing. Right now the prompt only shows: - “Codeforces 104824D - Garden (full)” - but the Problem Statement, Input, and Output sections are empty Without the statement, any solution would be…

codeforcescompetitive-programming
CF 104824A - Honey Heist (Subtask)

I can’t write a correct Codeforces editorial here because the actual problem statement is missing. Right now we only have the title “Honey Heist (Subtask)”, but no definition of the input, output, or rules of the task.

codeforcescompetitive-programming
CF 104824B - Honey Heist (Full)

I can write the editorial in exactly that format, but I’m missing the actual problem statement. Right now, “Codeforces 104824B - Honey Heist (Full)” isn’t included in your message, and I don’t have enough information to safely reconstruct it.

codeforcescompetitive-programming
CF 104824C - Garden (subtask)

I can’t reliably write a correct Codeforces-style editorial without the actual problem statement. Right now the “Problem Statement / Input / Output” sections are empty, and for a Codeforces problem (especially something like a subtask), the solution structure depends…

codeforcescompetitive-programming
CF 104825M - 小H的糖果

We are given a row of candy, each candy labeled with a lowercase letter. From this row we will pick a starting position, and then eat that candy and everything to its right, producing a suffix string.

codeforcescompetitive-programming
CF 104825L - Equation

We are asked to find all integers $x$ in the range $0 le x < M$ such that a self-referential modular equation holds: the value $x^x$ and the value $x$ are congruent modulo $M$.

codeforcescompetitive-programming
CF 104825K - str进制

We are given a string that acts like a description of a positional numeral system, except it is not a fixed base like decimal or binary. Instead, each position has its own “carry rule”.

codeforcescompetitive-programming
CF 104825J - pass

We are given a very simplified model of a road that consists of a flat horizontal segment, followed immediately by a vertical wall, and then a horizontal top surface of that wall. A car tries to pass through this structure.

codeforcescompetitive-programming
CF 104825I - 星光指引前路

We are given a set of axis-aligned rectangles on a plane. Each rectangle has a weight. Then we are given several query points. For each query point, we look at all rectangles that contain that point and extract their weights.

codeforcescompetitive-programming
CF 104825H - LCA Determinant

We are given a rooted tree with vertices numbered from 1 to n, with vertex 1 acting as the root. Each vertex u carries a value a[u].

codeforcescompetitive-programming
CF 104825G - War

We are given a grid where each cell is either empty or contains a single enemy unit. Empty cells and the area outside the grid are already controlled by us. The grid starts with all enemy cells still alive, and the goal is to eliminate every enemy cell.

codeforcescompetitive-programming
CF 104825F - Harmini

We are given a tree with $n$ nodes, and each edge has an unknown integer weight. The tree structure is known in advance, but the weights are hidden.

codeforcescompetitive-programming
CF 104825E - MyGO!!!!!

We are given a sequence of integers and we want to cut it into contiguous non-empty segments. Every segment must satisfy a constraint on its bitwise XOR: the XOR of all elements inside the segment must be strictly greater than a given threshold $k$.

codeforcescompetitive-programming
CF 104825D - 小L的数学题

We are given a positive integer $n le 10^{12}$. For every integer $i$ from 1 to $n$, we define a value $f(i)$ based on the divisors of $i$. A divisor $d mid i$ is called valid if the complementary divisor $i/d$ shares no common prime factor with $d$.

codeforcescompetitive-programming
CF 104825B - 小L的围棋

We are given a one-dimensional array a of length n. Each value of this array defines weights over all intervals in a very specific way: every pair of indices (x, y) with x ≤ y corresponds to a grid point on a triangular board, and that point implicitly carries a value…

codeforcescompetitive-programming
CF 104825C - 小L的旅行

We are given a directed graph of n locations and m one-way roads. Traveling along any road costs exactly one minute.

codeforcescompetitive-programming
CF 104825A - 赛前须知

The task is intentionally trivial from a computational perspective. We are given a multiple-choice exam consisting of 10 independent questions. Each question has four options labeled A to D, and the correct output is simply a sequence of chosen options, one per line.

codeforcescompetitive-programming
CF 104828M - 猫猫虫虫虫

We are given two observed constraints about three consecutive segments on a line. Think of a point $x$ as the start of the first segment.

codeforcescompetitive-programming
CF 104828K - 数据结构基本功

We are given a rooted tree where each node initially holds a binary value, either 0 or 1. The tree is dynamic in the sense that two types of operations are applied over time. The first operation selects two nodes and treats them as endpoints of a simple path.

codeforcescompetitive-programming
CF 104828L - 数路径

We are given a rooted binary tree where each node has a color value. Every node has at most two children, and children are explicitly given as left and right pointers (or zero if absent). The root is node 1.

codeforcescompetitive-programming
CF 104828J - 圆神

We are working in a geometric setting where each enemy is represented by a circle in the plane, and the player is fixed at the origin. From the origin, a hook is fired along a straight ray in some direction.

codeforcescompetitive-programming
CF 104828G - 鲭鱼圣者

We are given a small battlefield with at most seven identical enemy minions. Each minion starts with a protective shield that blocks the first incoming damage entirely.

codeforcescompetitive-programming
CF 104828I - Guess Numbers

Two hidden integers are chosen at the start of each test case, and they never change during our interaction. Both numbers lie in a fixed range below $2^{60}$, so they are effectively 60-bit values.

codeforcescompetitive-programming
CF 104828H - 回文串分割

We are given multiple independent strings, and for each one we need to decide whether it can be decomposed into a sequence of substrings where every piece is a palindrome.

codeforcescompetitive-programming
CF 104828E - Before the deadline

We are given a metro system where stations are nodes and each metro line is a fixed path through some of these stations. Each line has a travel time for every adjacent pair of stations on the line.

codeforcescompetitive-programming
CF 104828F - 随机数破解程序

Working

codeforcescompetitive-programming
CF 104828B - 玩牌

We are given several stacks of cards. Each stack contains some distinct integers, and globally all card values form a permutation, so every value appears exactly once across all stacks. A game consists of multiple rounds.

codeforcescompetitive-programming
CF 104828D - 博弈

Working

codeforcescompetitive-programming
CF 104828A - 魔法练习

We are given a list of integers and a modulus value. The task is to compute the product of all numbers in the list and then output the remainder when that product is divided by the given modulus.

codeforcescompetitive-programming