brain

tamnd's digital brain — notes, problems, research

41641 notes

CF 104872G - Not Everything Is So Ambiguous

We are dealing with a hidden pair of integers: a value $x$ in the range $1 le x le 10^9$, and a base $b$ in the range $2 le b le 2023$. We do not see either of them directly. Instead, we are initially told how many digits $x$ has when written in base $b$.

codeforcescompetitive-programming
CF 104872F - Magic Square

We are given an $n times n$ grid that initially contains a perfect permutation of numbers from $1$ to $n^2$. The defining property of the original grid is that every row sum equals the same value, and every column sum also equals that same value.

codeforcescompetitive-programming
CF 104872B - Cooperative Game on a Tree

We are given a rooted tree where every node has a single parent except the root. Two tokens start at the root: a blue token and a red token. The process unfolds in synchronized rounds.

codeforcescompetitive-programming
CF 104872E - Casino

Codeforces 104872E: Casino

codeforcescompetitive-programming
CF 104872D - a, ab, ba Strings

We are maintaining a binary string made only of characters a and b, with two operations applied online. The first operation flips a single position, turning a into b or b into a.

codeforcescompetitive-programming
CF 104872C - Driving License Exam

We are given a path of intersections arranged in a line, where each adjacent pair is connected by a road with a certain length. Each intersection also contains some amount of “ice resource”.

codeforcescompetitive-programming
CF 104873J - Joined Vessels

We are given a line of vessels connected in a chain. Between vessel i and i+1 there is a narrow connection that only starts behaving like a proper communicating tube once the water level reaches a fixed height hi.

codeforcescompetitive-programming
CF 104873E - Email Destruction

Each email belongs to a “thread” that evolves in a very rigid way. A thread starts from a base subject, which is a non-empty lowercase string. Every next email in the same thread is created by prepending the prefix "Re: " to the previous subject.

codeforcescompetitive-programming
CF 104873L - LED-led Paths

We are given a directed acyclic graph where vertices represent junctions in a city and edges represent one-way streets. The acyclic condition means there is no way to start at a junction and follow directed streets to eventually return to the same place.

codeforcescompetitive-programming
CF 104873K - Keyboard Consensus

We are given a set of n keyboards, each identified by an integer label. Two people, Kolya and Kostya, each rank all keyboards from most preferred to least preferred, and both rankings are known to both players. They play a deterministic elimination game.

codeforcescompetitive-programming
CF 104873I - Interactive Array Guessing

We are given several hidden arrays, each containing a small number of distinct integers. The arrays are ordered from 1 to n, and each query lets us pick a list of indices and receive the concatenation of those arrays in that order, but without any separators between elements.

codeforcescompetitive-programming
CF 104873H - Halves Not Equal

We are asked to split a fixed amount of gold among $n$ recipients, where each recipient $i$ has a declared maximum acceptable share $ai$. The total gold available is $s$, and it may be strictly smaller than the sum of all claims, so not everyone can receive what they want.

codeforcescompetitive-programming
CF 104873F - Forgotten Land

We are given a tree with $n$ cities. Each city has exactly one language label from $1$ to $k$. The cities are partitioned into several disjoint groups, called alliances, but the partition is arbitrary and not restricted by edges of the tree.

codeforcescompetitive-programming
CF 104873G - Generalized German Quotation

We are given a sequence made only of two kinds of quote tokens. Each token is either the left style written as << or the right style written as . The task is not to interpret them as fixed opening or closing brackets.

codeforcescompetitive-programming
CF 104873D - Distinct Substrings

We are given a short string p and a very large integer n. The actual string we work with is not arbitrary: it is formed by repeating p over and over and then cutting it after exactly n characters.

codeforcescompetitive-programming
CF 104873B - Building a Stair

We are asked to construct a particular shape made of unit cubes, drawn as a square grid. Each cell either contains a cube or is empty, and the occupied cells must form a “stair” shape.

codeforcescompetitive-programming
CF 104873A - Accumulator Battery

A phone starts a journey fully charged and consumes battery while Anna travels. At some point during the journey, when the battery level hits a fixed threshold of 20 percent, the phone switches to a slower discharge mode.

codeforcescompetitive-programming
CF 104873C - Counting Stairs

We are asked to count a specific class of shapes built from unit cubes. Each valid configuration is a “stair-like” structure: columns of cubes arranged from left to right with heights that never increase as we move right.

codeforcescompetitive-programming
CF 104874C - Cross-Stitch

The problem statement is missing from your prompt, so I don’t have enough information to write a correct editorial.

codeforcescompetitive-programming
CF 104874M - Managing Difficulties

I can’t reliably reconstruct Codeforces 104874M (“Managing Difficulties”) from the title alone, and I don’t have the actual problem statement in your prompt.

codeforcescompetitive-programming
CF 104874L - Lengths and Periods

We are given a single long string over lowercase English letters, and we want to measure how “repetitive” it can be in its most extreme localized form.

codeforcescompetitive-programming
CF 104874I - Ideal Pyramid

We are given a set of vertical pillars placed on a plane, each located at an integer coordinate and having a required minimum height.

codeforcescompetitive-programming
CF 104874K - King's Children

We are given an $n times m$ grid where each cell is either empty or contains exactly one castle labeled by an uppercase letter. There is exactly one castle labeled ‘A’, which belongs to the favorite child.

codeforcescompetitive-programming
CF 104874J - Just the Last Digit

We are given a directed acyclic structure over $n$ ordered nodes, where edges only go from a smaller index to a larger index. Think of it as a downhill graph: from every spot $i$, you can only move to higher-indexed spots $j i$ if a trail exists.

codeforcescompetitive-programming
CF 104874H - High Load Database

We are given a fixed sequence of transactions, each transaction carrying a positive workload measured in queries. We are not allowed to reorder these transactions. Instead, we must partition the sequence into contiguous groups, which we will call batches.

codeforcescompetitive-programming
CF 104874G - Golf Time

I tried to locate “Codeforces 104874G - Golf Time”, but there is no accessible statement in the public Codeforces archive or mirrors indexed in standard problem listings.

codeforcescompetitive-programming
CF 104874F - Foreach

I can’t responsibly write a correct editorial for Codeforces 104874F - Foreach yet because the actual problem statement is missing, and I was not able to retrieve a reliable statement from available sources.

codeforcescompetitive-programming
CF 104874E - Equidistant

We are given a tree of cities connected by roads, where every road has equal travel time. A subset of these cities contains teams. The task is to choose a single city such that every team can reach it in exactly the same number of edges.

codeforcescompetitive-programming
CF 104874D - Double Palindrome

We are working with strings built from the first $k$ lowercase English letters, and we want to count how many such strings of length at most $n$ satisfy a structural property called “double palindrome”.

codeforcescompetitive-programming
CF 104874B - Bad Treap

We are given a deterministic treap definition where each node has a key and a priority derived from the key itself using a fixed function, namely $y = sin(x)$.

codeforcescompetitive-programming
CF 104874A - Accurate Movement

I don’t actually have the statement for Codeforces 104874A - Accurate Movement in your prompt, and I can’t reliably reconstruct it from the title alone without risking inventing details.

codeforcescompetitive-programming
CF 104875G - Going in Circles

We are placed on a cyclic structure of train carriages. Each carriage contains a binary light switch, either 0 or 1. We start in an unknown carriage, and we are allowed to move to adjacent carriages along the cycle or flip the switch in the current carriage.

codeforcescompetitive-programming
CF 104875D - Delft Distance

The city is a rectangular grid of size $h times w$. Each cell contains a building occupying most of a $10 times 10$ meter square footprint. Some cells are square buildings, others are circular towers whose footprint is a disk of diameter $10$, so radius $5$.

codeforcescompetitive-programming
CF 104875L - Last Guess

We are given a Wordle-like process where several guesses have already been made and each guess comes with full feedback using the usual green, yellow, and black rules, including correct handling of repeated letters.

codeforcescompetitive-programming
CF 104875K - Kebab Pizza

We are given a circular pizza split into $n$ slices. Each slice has exactly two toppings assigned by the customer who eats that slice. Across all slices there are $k$ possible topping types.

codeforcescompetitive-programming
CF 104875J - Justice Served

Each suspect corresponds to a time interval during which they were in the room. For suspect i, we are given an arrival time a and a duration t, which defines an interval from a to a + t.

codeforcescompetitive-programming
CF 104875I - Interview Question

We are given a slice of a FizzBuzz-like sequence, but instead of knowing the rules, we only see the output and must reconstruct the hidden parameters.

codeforcescompetitive-programming
CF 104875H - High-quality Tree

We are given an undirected tree rooted at node 1, where each node has at most two children once the root is fixed. The notion of balance is defined locally: for any node, consider the heights of its left and right subtrees.

codeforcescompetitive-programming
CF 104875F - Faster Than Light

We are given several axis-aligned rectangles in the plane. Each rectangle represents a “room” of a spaceship, and we are allowed to fire a single infinite straight line beam in any direction.

codeforcescompetitive-programming
CF 104875E - ETA

We are asked to construct an undirected connected graph where vertex 1 is treated as the exit. A player starts at a uniformly random vertex and then always moves optimally toward vertex 1, meaning the travel time from a node is simply its shortest-path distance to node 1.

codeforcescompetitive-programming
CF 104875C - Circular Caramel Cookie

We are given a configuration of unit squares laid out on an infinite grid. Think of the plane split by integer lattice lines into 1 by 1 cells.

codeforcescompetitive-programming
CF 104875A - Alternating Algorithm

We are given an array of length $n+1$, and we repeatedly apply a very specific parallel “adjacent swapping” procedure until the array becomes sorted in non-decreasing order.

codeforcescompetitive-programming
CF 104878B - Lockpicking

There are N switches, each representing a pin on a security system. Turning on a pin takes exactly one second, and each pin can only be activated once. The difficulty comes from the fact that each pin watches a fixed set of other pins.

codeforcescompetitive-programming
CF 104878A - Heist

We are given a city modeled as an undirected graph where intersections are nodes and streets are edges. Powder starts at node 1, the laboratory, and wants to reach node N, the hidden entrance to Zaun. Some intersections initially contain police officers.

codeforcescompetitive-programming
CF 104879D - Restore Permutation

We are given a hidden permutation of numbers from 1 to n. The interaction model is that we get some encoded information about this permutation, and in the second phase we receive another permutation that differs from the original in a very restricted way.

codeforcescompetitive-programming
CF 104879E - DequeQL

We are dealing with a dynamic system of nested deques. Each deque can contain other deques, forming a rooted structure that changes over time.

codeforcescompetitive-programming
CF 104879C - Public Transportation

We are given a grid of integers where each cell represents a value assigned to a point on a rectangular board. The task is to count certain geometric configurations formed by three cells, which we can think of as “triangles” aligned with the grid.

codeforcescompetitive-programming
CF 104879A - Coffee Cocktail

We are given several kinds of snacks, where each snack type can appear multiple times and each individual snack contributes some amount of caffeine.

codeforcescompetitive-programming
CF 104880G - 石子配对

We are given a multiset of stone types, where each type has a value and a quantity. Altogether there are exactly $2n$ stones, so every stone must be used exactly once in pairing. When we pair two stones with values $x$ and $y$, they contribute a score equal to $(x + y) bmod k$.

codeforcescompetitive-programming
CF 104880O - Toxel 与字符串匹配

We are given two integer arrays, one of length n and another of length m. We imagine sliding the shorter array over the longer one in every possible relative alignment, including positions where they only partially overlap.

codeforcescompetitive-programming
CF 104880N - Purble Shop

We are interacting with a hidden array of length $n$, where each position represents an item of clothing and stores a color from $1$ to $n$.

codeforcescompetitive-programming
CF 104880M - Easy XOR problem

We are given a collection of binary strings, each of equal length. You can think of each string as a number written in base 2 with a fixed number of bits.

codeforcescompetitive-programming
CF 104880L - 数列计数

We are given a digit sequence of length $n$, and every contiguous segment $[l, r]$ is interpreted as a decimal number.

codeforcescompetitive-programming
CF 104880J - while (1) replace;

We are given an unknown string consisting only of the characters a, b, and c, with length at most 10. We are not allowed to read or query the string directly. Instead, we are allowed to apply a special operation replace(x, y) multiple times.

codeforcescompetitive-programming
CF 104880K - Power Shift

We are given an array of length n, and we need to support three kinds of operations applied over ranges or single positions. One operation takes every element in a segment and replaces it by the integer square root of its current value.

codeforcescompetitive-programming
CF 104880I - 坏掉的计数器

We are given a digit display built from seven-segment components, but some of the segments are broken and always stay off. The device shows an n-digit number, and each digit is rendered independently using the standard seven-segment encoding.

codeforcescompetitive-programming
CF 104880H - 矩阵乘法

We are counting how many 8-number configurations produce a very specific kind of “matrix identity”, but the real content of the problem is simpler than it first appears. Each configuration consists of eight integers, all chosen independently from the range 1 to 99.

codeforcescompetitive-programming
CF 104880F - 火柴棒等式

We are given a mathematical expression formed using matchstick digits, either in the form $a + b = c$ or $a - b = c$, where each number is written in a fixed 7-segment style and all digits lie in the range from 0 to 999.

codeforcescompetitive-programming
CF 104880D - 无声之歌

We are given a sequence of integers and we look at all possible contiguous subarrays. Each subarray has a sum, and among all of these sums there is a maximum value, which is the classical maximum subarray sum.

codeforcescompetitive-programming
CF 104880E - Serval 的树

We are given a tree with $n$ labeled nodes. We are allowed to repeatedly perform an operation where we pick a currently existing node, remove it, and delete all edges incident to it. Each such operation counts as one step.

codeforcescompetitive-programming
CF 104880B - 毕业合照

We are given a set of people moving along an infinite straight line. Each person starts at a position $xi$ and then moves with constant velocity $vi$. All motion begins at the same moment, so time $t = 0$ is shared.

codeforcescompetitive-programming
CF 104880C - 咒语计数

We are given a single string made of lowercase letters. The task is to count how many ways we can pick four positions in increasing order such that the characters at those positions form the pattern c, then v, then b, then b.

codeforcescompetitive-programming
CF 104880A - Well Rested

We are given a fixed schedule encoded as a binary string of length 24. Each position corresponds to one hour of a day, starting from hour 1 up to hour 24. A character 1 means you are working during that hour, while 0 means you are resting.

codeforcescompetitive-programming
CF 104882L - Line without beginning, line without end

We are trying to recover an unknown straight line in the plane, known to have the form $y = kx + b$, where both parameters are real numbers bounded between $-100$ and $100$.

codeforcescompetitive-programming
CF 104882J - Just a map editor

We are given an $n times m$ rectangular grid and must fill each cell with either 0 or 1. A cell belongs to a connected component if it is part of a maximal group of equal values where movement is allowed only between side-adjacent cells.

codeforcescompetitive-programming
CF 104882K - Key anagram

Codeforces 104882K: Key anagram

codeforcescompetitive-programming
CF 104882I - Ideal 2B

We are given a non-negative integer up to one trillion and we need to print a shortened representation of it. The goal is not just compression, but a very specific kind of approximation: we want a string no longer than four characters that represents a number which does not…

codeforcescompetitive-programming
CF 104882H - Have fun taking tests

We are dealing with an interactive multiple-choice test. The test contains $n$ questions, and each question has exactly two possible answers, where exactly one is correct. We do not know the correct answers in advance, and we cannot query them directly.

codeforcescompetitive-programming
CF 104882F - Fine arts museum

We are given up to eight “trees”, each defined by two parameters. Each tree consists of a vertical trunk and a triangular crown drawn with ASCII characters.

codeforcescompetitive-programming
CF 104882E - Efficient synchronization

We are maintaining a collection of k independent versions of the same array of size n. Initially, all k arrays are identical and equal to a given base array. Over time, we process two kinds of operations that are timestamped.

codeforcescompetitive-programming
CF 104882G - Grandma's Cubes

We are given a sequence of dice outcomes, one per throw. At each position Masha is allowed to announce any number from 1 to 6, independent of the real roll, and her score is the sum of all announced numbers. The twist is a “surveillance rule” tied to the value 6.

codeforcescompetitive-programming
CF 104882D - Delicious pies

We are given a row of pies indexed from left to right, where each pie is either cabbage or mushroom. Two children repeatedly take pies from this row according to a positional rule: one child targets every 3rd remaining pie, the other targets every 7th remaining pie.

codeforcescompetitive-programming
CF 104882C - Creative archery

We are building a square target made of unit blocks, where the side length is an even integer $x$. The square is not uniformly colored. Instead, it consists of concentric square “rings”.

codeforcescompetitive-programming
CF 104882B - Before contest

Two players assign a numeric score to the same problem using two different formulas. One takes the length of the statement and raises it to the power of the code length, while the other swaps the roles.

codeforcescompetitive-programming
CF 104882A - A+B?

We are counting integer pairs $(a, b)$ that satisfy a simple linear constraint: their sum is fixed to a given value $n$, and both numbers must lie inside a symmetric interval centered at zero.

codeforcescompetitive-programming
CF 104883E - 宝石合成

We are given a sequence of gemstones, each with an integer level. The only operation allowed is to take a contiguous block of at least two identical levels and merge it into a single gemstone whose level increases by one.

codeforcescompetitive-programming
CF 104883I - Would You Like Some Modulo?

We are given a sequence of large integers, and a range of values from L to R. For each integer x in this range, we repeatedly apply a modulo operation using the sequence A1, A2, ..., An in order.

codeforcescompetitive-programming
CF 104883H - Rolling Star

We are given a total number of credits and two aggregated statistics computed over a hidden list of courses. Each course has an integer credit value and an integer score between 60 and 100.

codeforcescompetitive-programming
CF 104883G - What if ...?

We are given a loop that runs over all integers from 1 to n. Inside the loop, there is a chained if-else structure with m conditions, producing m+1 possible branches.

codeforcescompetitive-programming
CF 104883F - 二分查找

We are dealing with a hidden permutation of length $n$, where every integer from $1$ to $n$ appears exactly once.

codeforcescompetitive-programming
CF 104883D - 生活在树上

This problem requires deriving and proving a constructive algorithm, together with a complete verified implementation.

codeforcescompetitive-programming
CF 104883C - 更小但是异或之后至少有 x 个 1

We are given a large integer a written as a binary string, and a nonnegative integer x. We must construct another integer b that does not exceed a, and among all such valid b, we want the maximum possible value of b.

codeforcescompetitive-programming
CF 104883B - 奥术之尘

Each account comes with a certain amount of “arcane dust”, and there is a fixed list of card decks, each requiring a specific dust cost to be fully crafted.

codeforcescompetitive-programming
CF 104883A - rnm,退钱!

We are given a chronological log of a player’s account balance in a virtual currency system. Each record changes their balance in one of three ways: they either receive currency by paying real money, spend currency in the game, or do something irrelevant that does not affect…

codeforcescompetitive-programming
CF 104885F - Очередная задача про запросы на перестановках

We are given a permutation of size $n$ and a set of range queries. Each query is defined by an interval $[l, r]$.

codeforcescompetitive-programming
CF 104885E - Хорошие-хорошие подотрезки

We are given an array and we work with its prefix sums. Let pref[i] denote the sum of the first i elements, with pref[0] = 0. A subarray [l, r] is called good when its sum is zero, which is equivalent to pref[r] - pref[l-1] = 0, or pref[r] = pref[l-1].

codeforcescompetitive-programming
CF 104885D - Время на марсе

We are given a time interval on a clock, written in hours and minutes, from a starting moment H1:M1 to an ending moment H2:M2.

codeforcescompetitive-programming
CF 104885B - Посчитай

The task describes a simple numerical construction based on repeatedly summing powers of an integer $k$. For each query, we are given a base value $k$ and a length $n$, and we must compute the value obtained by adding the first $n$ powers of $k$, starting from $k^1$.

codeforcescompetitive-programming
CF 104885C - Очередная задача на конструктив

We are building two sequences of decimal digits under a shared budget constraint. The process constructs both sequences in parallel, and at each step we spend part of a fixed total sum to append digits.

codeforcescompetitive-programming
CF 104885A - Детали и ресурсы

We are given a production setup with several workers. Each worker produces a fixed number of identical parts, and every part consumes a fixed amount of metal. All produced metal is then packed into containers, where each container can hold only a limited weight.

codeforcescompetitive-programming
CF 104886D - GCD Counting

We are given multiple test cases. In each one, we receive an array of positive integers bounded by a limit $m$. The task is not to construct anything, but to count.

codeforcescompetitive-programming
CF 104886F - Interval removal

The material you provided does not include the actual problem statement. The input and output sections are empty, and the core description of what “interval removal” is supposed to do is missing.

codeforcescompetitive-programming
CF 104886E - Random Tree Path Match

We are given a rooted tree with a weight on every vertex. For each query, we look at two nodes, take the unique simple path from the root to each of them, and then try to “align” these two root-to-node paths.

codeforcescompetitive-programming
CF 104886C - Fair Grading

We are given a list of professors, each of whom assigns a score to a student. The final score is computed in a very specific way: all scores are sorted, then the smallest and largest values are discarded, and the remaining values are summed. There is one allowed intervention.

codeforcescompetitive-programming
CF 104886A - Schedule Problem

The task is to determine whether a given time schedule is feasible by checking if all required time intervals can be satisfied simultaneously.

codeforcescompetitive-programming
CF 104886B - Easy Geometry

The brute-force view is to treat the river contact point as a variable point $P = (x, 0)$ and minimize the function $$f(x) = sqrt{(x-x1)^2 + y1^2} + sqrt{(x-x2)^2 + y2^2}.

codeforcescompetitive-programming
CF 104887N - Networks Make the Net Work

We are given an undirected graph where vertices are named computers and edges are cables between them. Each test case describes one such network. Originally, each of Alice, Bob, and Cindy started with a specific fixed structure on five computers.

codeforcescompetitive-programming
CF 104887L - LC BB ND CNDY

The transformation starts with a messy phrase containing letters, spaces, punctuation, and mixed casing, and reduces it to a sequence of consonants only.

codeforcescompetitive-programming
CF 104887J - Jolly Divisors

For every integer $n$, we are asked to look for divisors $d$ with a stronger-than-usual property: not only must $d$ divide $n$, but $d^k$ must also divide $n$. Among all such divisors, we take the largest one for each $n$.

codeforcescompetitive-programming
CF 104887K - Kyuuing Theory

We are given a fixed order of students in a queue. Each student needs a fixed amount of time to complete their exam, and there are $k$ instructors who can process students in parallel.

codeforcescompetitive-programming