brain

tamnd's digital brain — notes, problems, research

41436 notes

CF 104782K - Blabla

We are given a static array and asked to count how many contiguous subarrays satisfy a geometric comparison between two different notions of “spread”.

codeforcescompetitive-programming
CF 104782I - KSumT

We are counting integer sequences of length $K$, all entries strictly positive, whose total sum is fixed to $S$. The extra constraint is structural: if you take any contiguous block of length $T$, every such block has exactly the same product.

codeforcescompetitive-programming
CF 104782H - AI Thoughts

We are given a set of points on an infinite grid, where each point represents a neuron and is tagged with a color. For each query, we are also given a sequence of colors.

codeforcescompetitive-programming
CF 104782G - Minimize Sum

We are playing a game on a sequence of numbers using a deque that starts with a single value, zero. At each step, we process the next array element and are forced to interact with one of the two ends of the deque.

codeforcescompetitive-programming
CF 104782F - Suceava

We are given a fixed tree of neighborhoods. Each road is initially controlled by some gang. Over time, roads change ownership: on each day, a specific road is taken over by another gang, meaning that from that day onward its controlling gang changes.

codeforcescompetitive-programming
CF 104782E - Fiboxor

We are given a sequence defined by a recurrence that mixes arithmetic difference, absolute value, and bitwise XOR. The first two values are both 1, and every next value is computed from the previous two using a deterministic rule.

codeforcescompetitive-programming
CF 104782B - The floor is lava!

We are given a rectangular grid where each cell has an integer height. Think of this grid as a terrain map. A number of people start at specified cells and can move one step per second in the four cardinal directions, or choose to stay still.

codeforcescompetitive-programming
CF 104782A - Maximum Distance

We are given two integer arrays of equal length and we are allowed to pick a contiguous segment from the first array and another contiguous segment from the second array. Both chosen segments must have the same length.

codeforcescompetitive-programming
CF 104783O - Organ-free Man

We are given a function defined on non-negative integers where each digit contributes independently through factorials, but with a twist: the function is defined recursively in terms of decimal digits. For a single digit number, the value is simply the factorial of that digit.

codeforcescompetitive-programming
CF 104783C - TomTom Cruise

We are given an undirected graph where each vertex has a cost and each edge also has a cost. A “trip” is any walk that starts at some vertex, traverses at least one edge, and is not allowed to revisit any vertex or reuse any edge.

codeforcescompetitive-programming
CF 104783W - Win Diesel

We are given a graph of cave rooms plus a special node representing the surface. Each room can potentially be connected to other rooms or directly to the surface through “diggable” edges.

codeforcescompetitive-programming
CF 104783T - Tone Banks

We are given a binary grid made of two symbols, and ., which is not just a picture but a recursive structure. Each maximal connected region of a single symbol forms what the problem calls a data blob.

codeforcescompetitive-programming
CF 104783S - Screamers in the Storm

We are asked to count how many valid sequences of length $N$ can be formed, where each element is an integer between $1$ and $K$. The restriction is on adjacent elements: any two neighbors must be coprime.

codeforcescompetitive-programming
CF 104783R - Cyanide Rivers

We are given a long row of communication towers represented by a binary string. Each character corresponds to one tower in order along a line. A 1 means the tower is on dry ground, either on a shore or an island, while a 0 means the tower sits inside a dangerous cyanide river.

codeforcescompetitive-programming
CF 104783P - Bread Pit

We are given a rooted tree that represents a system of tunnels. Each node is either a cave (a terminal node where bread finally ends up) or a gate (an internal node that forwards bread further downward).

codeforcescompetitive-programming
CF 104783I - Eidam-Sand Lair

We have a vertical building indexed by floors, where floor 0 is the surface and positive numbers represent increasing depth underground. A person starts at some floor and wants to reach the surface. There is also a lift starting at its own floor.

codeforcescompetitive-programming
CF 104783F - Burizon Fort

We are given a positive integer $m$. Think of $m$ as defining a set of “coins”, where each coin is a divisor of $m$. We are allowed to use each divisor at most once, and we try to form sums using these coins.

codeforcescompetitive-programming
CF 104783H - Terrace Hill

We are given a sequence of terrace heights laid out on a straight line. Each position represents a terrace of fixed width one, and adjacent positions are effectively contiguous in space. We want to build bridges between selected pairs of terraces.

codeforcescompetitive-programming
CF 104783D - Mad Diamond

The maze is a network drawn on several concentric circular rings. Each ring contains up to 360 distinguished angular positions, called principal points, and these are the only places where the crystal can ever be located at the end of a phase.

codeforcescompetitive-programming
CF 104783A - Silver Star Stands Alone

The input gives a single prime number $P$, which represents the position of the final asteroid, called Silver Star, on a one-dimensional line starting from Mars.

codeforcescompetitive-programming
CF 104785N - Naming Wine Bottles

Each input line describes a wine bottle volume written as a decimal number followed by the letter L. Different lines may describe exactly the same quantity even if they look different syntactically, for example 1.0L and 1L represent the same value.

codeforcescompetitive-programming
CF 104785M - Mini-Tetris 3023

We are given a collection of small polyomino pieces that can be rotated freely and placed on a grid that is exactly 2 cells tall and infinitely long to the right, but in practice we only care about forming a finite 2 × n rectangle.

codeforcescompetitive-programming
CF 104785L - Last One Standing

Two players each control a single combat unit. Each unit repeatedly fires missiles at a fixed interval. A shot does not apply damage instantly, it lands half a second after being fired. Once a unit has fired, it must wait its reload time before it can fire again.

codeforcescompetitive-programming
CF 104785K - Kernel Scheduler

We are given a directed graph where each task is a vertex and each dependency is a directed edge. An edge a - b means task a must be executed before task b.

codeforcescompetitive-programming
CF 104785I - International Travel

We are given two rigid structures in the plane: a plug and a socket. Each structure consists of three circular pins or holes. Each circle has a center and a radius, and within each structure the three circles are pairwise disjoint.

codeforcescompetitive-programming
CF 104785H - History in Numbers

We are given a long sequence of integers representing an “urban development index” over time. This array is not static. Two types of operations happen online.

codeforcescompetitive-programming
CF 104785F - Fast Forward

We are given a circular playlist consisting of n songs, each with a fixed duration. Gry listens to the playlist starting from some chosen song i, moves forward through the circle, and stops after exactly n songs have been played.

codeforcescompetitive-programming
CF 104785E - Enchanted Fortress

We are given a set of symbols, each symbol appearing exactly once in a string. From these symbols we choose a subset, and the order of chosen symbols is irrelevant, only which ones are included matters.

codeforcescompetitive-programming
CF 104785D - Delivery Forces

We are given a company with $n$ couriers, where $n$ is guaranteed to be divisible by three. Each courier has a strength value, and we must partition all couriers into exactly $k = n/3$ groups, each group containing exactly three people.

codeforcescompetitive-programming
CF 104785C - Clearing Space

We are given a set of fixed positions on the boundary of a unit circular clearing, where each position is described by an angle in degrees. Think of these positions as allowed anchor points where fence posts may be installed.

codeforcescompetitive-programming
CF 104785B - Boat Commuter

We are simulating a tap-in tap-out transport system where each passenger uses a numbered travel card. Every event records a pier and a card ID, and events arrive in chronological order.

codeforcescompetitive-programming
CF 104786B - John and tree game

We are given a tree with (N) nodes. John wants to select disjoint pairs of nodes, with the restriction that a pair is valid only if the distance between the two nodes along the tree is even.

codeforcescompetitive-programming
CF 104786E - School

We are given a permutation of size $n$, meaning every integer from 1 to $n$ appears exactly once. For every pair of indices $(l, r)$, we look at the segment of the array from $l$ to $r$.

codeforcescompetitive-programming
CF 104786D - Many biscuits

We are given a rooted tree with root fixed at vertex 1. Every vertex initially contains exactly one biscuit. We will perform exactly k operations. In one operation we pick a vertex x and immediately eat every biscuit that still exists on the simple path from x up to the root.

codeforcescompetitive-programming
CF 104786C - John and Olaf

We are simulating two entities moving along a one-dimensional line of integer points from 1 to N. One of them, Olaf, moves deterministically: every minute he shifts one step to the right.

codeforcescompetitive-programming
CF 104786A - John and Möbius Convolution

We are given two arrays of integers, each of length $n$. Every value in both arrays is small, at most $10^3$, but the arrays themselves can be large, up to $2 cdot 10^5$ elements.

codeforcescompetitive-programming
CF 104787D - Yet Another Coffee

We are given a sequence of days, where each day has a base cost for buying a coffee. In addition, there are several coupons, and each coupon has a deadline day and a discount value.

codeforcescompetitive-programming
CF 104787M - Inverted

We start with a tree on n vertices. Then we process n − 1 operations in a fixed order given by a permutation of nodes, and after each operation we are asked to count the number of spanning trees in a graph that keeps evolving.

codeforcescompetitive-programming
CF 104787L - Yet Another Maximize Permutation Subarrays

We are given a permutation of size $n$, meaning it contains each number from 1 to $n$ exactly once. We are allowed to perform exactly one swap of any two positions, including the option of swapping a position with itself, which effectively means doing nothing.

codeforcescompetitive-programming
CF 104787K - Make SYSU Great Again II

We are given an $n times n$ grid, and each cell must be assigned an integer from the range $[0, 4n^2 - 1]$. The assignment is not arbitrary, because two conditions must simultaneously hold. First, no number is allowed to appear more than five times in the whole grid.

codeforcescompetitive-programming
CF 104787J - Keyi LIkes Reading

We are given a collection of words, but the only property that matters about each word is its length. Each day, Keyi chooses some words to study, and there is a special rule: if she decides to study a word of length $k$, then she must study all words of length $k$ that day.

codeforcescompetitive-programming
CF 104787I - Phony

We maintain a multiset of integers that changes over time, and we must support two kinds of operations efficiently.

codeforcescompetitive-programming
CF 104787H - Quake and Rebuild

We are given a rooted tree whose nodes are labeled from 1 to n, and every node except the root stores a pointer to its parent. The structure is initially static, but it changes over time through operations that modify these parent pointers. Two types of operations occur.

codeforcescompetitive-programming
CF 104787F - Mystery of Prime

We are given a sequence of positive integers and we are allowed to change values in it. The goal is to transform it so that every pair of adjacent elements sums to a prime number, while changing as few positions as possible.

codeforcescompetitive-programming
CF 104787E - Coloring Tape

We are given a grid with a small height but potentially long width. The grid has n rows and m columns. In the first column, every row already contains a distinct “brush” that starts coloring from that cell.

codeforcescompetitive-programming
CF 104787B - Yet Another Subsequence Problem

We are given two large integers, $A$ and $B$, which determine a binary string built by a deterministic greedy process. The process starts with zero occurrences of both symbols and repeatedly appends either a 0 or a 1 until exactly $A$ zeros and $B$ ones have been used.

codeforcescompetitive-programming
CF 104789E - Tree Trisection

We are given a perfect binary tree whose leaves are numbered in the usual heap style, so the leftmost leaf is 1 and every internal node corresponds to a contiguous segment of leaves. Each query specifies a segment of leaves $[l, r]$.

codeforcescompetitive-programming
CF 104789D - Hackathon

The process in this problem can be seen as a dynamic race between people and positions on a line of pizza pieces.

codeforcescompetitive-programming
CF 104789B - Work, Sleep, Repeat

We are given a repeating schedule that alternates between work days and rest days. One full pattern consists of a block of x work days followed by y rest days, and then it repeats forever. This means the entire timeline is periodic with period x + y.

codeforcescompetitive-programming
CF 104790K - King of the Hill

We are given an unknown grid of size $n times n$, where each cell contains a distinct integer height. The grid is not visible directly. Instead, we can only query individual coordinates and receive the height at that location.

codeforcescompetitive-programming
CF 104790L - Locking Doors

We are given a collection of rooms connected by doors. Each door can be traversed in both directions, so physically the layout is an undirected connected graph.

codeforcescompetitive-programming
CF 104790J - Jungle Job

We are given a rooted tree with $n$ vertices, numbered from $0$ to $n-1$. Each edge connects a node to its parent, so the input implicitly defines a rooted structure.

codeforcescompetitive-programming
CF 104790H - Hidden Art

We are given a finite rectangular pattern made of four colors, but this pattern is repeated infinitely in both horizontal and vertical directions, forming an infinite tiling of the plane.

codeforcescompetitive-programming
CF 104790G - Geometry Game

We are given four points in the plane, already arranged in clockwise order, and guaranteed to form a strictly convex quadrilateral. Our task is to classify the shape formed by connecting these points in order and closing the cycle. The classification is hierarchical.

codeforcescompetitive-programming
CF 104790F - Funicular Frenzy

There is a queueing system in front of a funicular that runs for a fixed number of minutes during the day. Each minute, a known number of people arrive and join the queue, and immediately after those arrivals are processed, a carriage departs and removes up to a fixed number…

codeforcescompetitive-programming
CF 104790A - \texttt{apt upgrade}

We are given a collection of software packages, each with a known download size. At some moment during an upgrade process, we observe that exactly some number of packages have already fully completed downloading, while up to a fixed number of packages can be downloading at the…

codeforcescompetitive-programming
CF 104790C - Compressing Commands

We are given several absolute file paths in a Unix-like filesystem. We are allowed to choose a single working directory anywhere in the tree, but not inside a file.

codeforcescompetitive-programming
CF 104791C - Robot

Codeforces 104791C: Robot

codeforcescompetitive-programming
CF 104791A - Water

We are simulating a line of people using a water dispenser that is fed by identical buckets, each containing a fixed amount of water. Every person in the queue wants a certain number of liters. The dispenser starts with a full bucket, and people are served one after another.

codeforcescompetitive-programming
CF 104791B - 810975

We are counting binary sequences of length $n$, where each position represents either a win or a loss in a sequence of games. A 1 means a win, a 0 means a loss.

codeforcescompetitive-programming
CF 104797B - Building on the Moon

Codeforces 104797B: Building on the Moon

codeforcescompetitive-programming
CF 104797L - Systematic salesman

We are given a set of points on a plane, each representing a city. The salesman must produce a single path that visits every city exactly once. He is allowed to start anywhere and finish anywhere, so the result is simply a permutation of all cities.

codeforcescompetitive-programming
CF 104797K - Single-track railway

We are given a linear railway consisting of stations connected in a chain. Between each pair of neighboring stations there is a travel time. Two trains depart simultaneously: one starts at station 1 and moves right, the other starts at station n and moves left.

codeforcescompetitive-programming
CF 104797J - Repetitions

We are given a long string made only of lowercase letters and a small number of queries over substrings of this string. Each query focuses on a contiguous segment of the string, and asks us to find a very specific pattern inside that segment.

codeforcescompetitive-programming
CF 104797I - Regional development

We are given a directed graph of villages connected by roads. Each road connects two villages and comes with a prescribed direction in the input, but we are free to assign a final flow of merchants on each road either in the given direction or in the reverse direction.

codeforcescompetitive-programming
CF 104797G - Lines in a grid

We are given an integer grid formed by all lattice points $(i, j)$ where both coordinates range from $0$ to $n-1$. From this set of points, we consider all straight lines in the plane and we want to count how many distinct lines pass through at least two of these grid points.

codeforcescompetitive-programming
CF 104797H - Radar

We are given a radar system that produces a finite set of scanned points in the plane. Each scanned point is formed by choosing a direction and a distance from the origin, then going that distance along that direction.

codeforcescompetitive-programming
CF 104797F - Letters

We are given a rectangular grid that contains lowercase letters and empty cells. Over time, gravity acts on this grid, but not in a fixed direction.

codeforcescompetitive-programming
CF 104797D - DJ Darko

We are given a line of speakers, each speaker has an initial volume and a cost factor that tells us how much energy is needed to change its volume by one unit. Two kinds of operations are performed on contiguous segments of this line.

codeforcescompetitive-programming
CF 104797E - Fishing

We are given a sparse grid of

codeforcescompetitive-programming
CF 104797C - Cactus cutting

We are given an undirected connected graph that has a restricted structure: every edge belongs to at most one simple cycle, so cycles can overlap only at vertices, not through shared edges. This is the standard definition of a cactus graph.

codeforcescompetitive-programming
CF 104797A - Airline

We are given an undirected graph that is already a tree, meaning there are exactly n nodes and n−1 edges and there is exactly one simple path between any two nodes. The distance between two nodes is the number of edges on this unique path.

codeforcescompetitive-programming
CF 104804K - Печать

We are given a printing shop that splits paper lengths into a sequence of contiguous segments. Each segment represents a range of page counts, and every range has a fixed cost per page.

codeforcescompetitive-programming
CF 104804F - Good substring

We are given a string made of Latin uppercase letters and a parameter $k$. A substring is considered valid if it never contains a run of $k$ vowels in a row and never contains a run of $k$ consonants in a row.

codeforcescompetitive-programming
CF 104804B - Начало игры

We are simulating a very structured drafting process among four players sitting in a fixed cycle. Each round, every player takes exactly one knight token from a common pool until the pool is exhausted.

codeforcescompetitive-programming
CF 104804C - Моряки

We are simulating a very simple earning process over a sequence of items called sailors. There are $n$ sailors available in total, and in each of $k$ rounds Igor takes exactly one sailor from what remains.

codeforcescompetitive-programming
CF 104804A - Ресурсы

Each test case describes a collection of resource types gathered during a board game session. For every type, we are given how many units of that resource were collected and how many points a single unit is worth.

codeforcescompetitive-programming
CF 104805N - First words

We are given a small dictionary of words that Veronica knows, and then a single long string that represents what Igor wrote down as her spoken monologue.

codeforcescompetitive-programming
CF 104805M - Choosing a name

We are given four collections of names. Igor has a list of names he likes and a list of names he dislikes. Ira also has a list of names she likes and a list of names she dislikes. A name is considered usable only if both people like it and neither of them explicitly dislikes it.

codeforcescompetitive-programming
CF 104805L - Towers

We are given a sequence of tower heights placed in a row. Each tower has a numeric height, and we are allowed to pick some of them while preserving their left-to-right order.

codeforcescompetitive-programming
CF 104805K - Get the numbers

We are given a small collection of integers, each between 2 and 15. From this collection, we can repeatedly perform an operation that builds a new multiset by choosing elements from the original collection with repetition allowed.

codeforcescompetitive-programming
CF 104805H - Crawling

We are given a rectangular grid that represents a crawling mat. Each cell is either free space, an obstacle, a toy, or Veronica’s starting position. Veronica occupies exactly one cell and also has an initial facing direction indicated by the symbol at that cell.

codeforcescompetitive-programming
CF 104805G - Sleep

We are given a diary of how Veronica sleeps during a day. Each diary entry gives a start time when she falls asleep and an end time when she wakes up.

codeforcescompetitive-programming
CF 104805D - An abstract painting

We are given a single integer $n$, and we must decide whether it is possible to construct a square painting of some side length $k$, where $k le n$, under a very specific interpretation of “painting”. The painting is not just a uniform grid of cells.

codeforcescompetitive-programming
CF 104805A - Number System

We are given a single addition written in an unknown numeral system. Three strings represent two addends and their sum, but the base is not provided.

codeforcescompetitive-programming
CF 104805C - Fare

We are given a connected network of cities that forms a tree. Each road connects two cities and has a weight. For any two cities, there is exactly one simple path between them because there are no cycles.

codeforcescompetitive-programming
CF 104813M - Painter

We are working on an infinite 2D integer grid where every lattice point initially has the same default character ".". We are then given a sequence of painting operations that overwrite regions of this grid with new characters.

codeforcescompetitive-programming
CF 104813L - Palm Island

We are given two permutations of the numbers from 1 to n. The first permutation describes the initial order of a deck of cards from top to bottom, and the second permutation describes the target order we want to achieve.

codeforcescompetitive-programming
CF 104813I - Rolling For Days

We are given a large pool of cards split into a small number of types. Type $i$ contains $ai$ distinct cards, and we only care about collecting the first $bi$ distinct cards of that type. A single “refresh” draws one card uniformly from the entire pool.

codeforcescompetitive-programming
CF 104813J - Game on a Forest

We are given a graph that is a forest, so every connected component is a tree. The game starts with two players alternating moves, and each move modifies the graph in one of two ways.

codeforcescompetitive-programming
CF 104813K - Omniscia Spares None

I can’t write a correct Codeforces editorial for “104813K - Omniscia Spares None” without the actual problem statement.

codeforcescompetitive-programming
CF 104813G - The Only Way to the Destination

We are given a very large $n times m$ grid, but most of it is empty except for a set of $k$ “walls”. Each wall is a vertical segment: it blocks an entire column $y$ from row $x1$ to $x2$. All blocked cells are impassable, and the rest are free cells.

codeforcescompetitive-programming
CF 104813H - Energy Distribution

We are given a small weighted undirected graph with up to ten vertices. The weights describe how strongly each pair of planets interacts.

codeforcescompetitive-programming
CF 104813E - Revenge on My Boss

We are given a set of cities, each carrying three independent parameters: Alice can collect some amount of material when visiting, Bob can also collect material when visiting, and each city has a selling value multiplier.

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