brain

tamnd's digital brain — notes, problems, research

41641 notes

CF 105297F - Carbon Neutral

We are given a directed graph where each edge represents a financial transaction between two companies. For every transaction, we must assign a value from the set {-1, 0, 1}.

codeforcescompetitive-programming
CF 105297A - Nauryz

There is a single music device that plays songs one after another. Each guest arrives at a specific time, selects a song with a fixed duration, and that song is normally appended to the end of the playback queue.

codeforcescompetitive-programming
CF 105307H - Final Quiz

We are asked to count how many length-n sequences we can build using k symbols, where each position is a quiz answer choice. The constraint forbids any run of four identical consecutive values.

codeforcescompetitive-programming
CF 105307A - Card Dealer Game

We are given a sequence of decks, each deck containing only two types of cards: red and blue. In each round, the current dealer chooses one unused deck, the deck is shuffled, and the other player picks one card uniformly at random.

codeforcescompetitive-programming
CF 105309H - Easy palindrome question

We are given a sequence of length $n$, where each position represents how many problems a friend solved on that day. Some values are already known, some are unknown and marked as $-1$, meaning they can be freely chosen. We are also given two types of constraints.

codeforcescompetitive-programming
CF 105309A - World's Hardest Math Problem II

We are asked to construct any number of a given length $n$, where $2 le n le 6$, such that two conditions hold simultaneously. First, the number must be rotationally symmetric under a 180-degree rotation.

codeforcescompetitive-programming
CF 105310H - Cereal Trees IV

We are given a rooted tree where node 1 is the root and every node carries a value that can be positive or negative. The tree does not change structurally, but the values at nodes change over time through updates.

codeforcescompetitive-programming
CF 105310C - Red Pandacakes

We are given a circular arrangement of stores, each store containing some number of pancakes. Two players, Lura and Oscar, will each end up visiting a contiguous segment of stores along the circle, but their segments are constrained by a key rule: neither of them is allowed to…

codeforcescompetitive-programming
CF 105314I - Ahmad and Gifting Syndrome

We are given several independent test cases. In each test case, there are $n$ intervals. From each interval $[li, ri]$, we must choose exactly one integer $xi$. After making all choices, we compute the sum of all selected values.

codeforcescompetitive-programming
CF 105314F - Ahmad and Swapping Syndrome

We are given several independent test cases. In each test case, there is a sequence of words arranged in a line. The task is to count how many pairs of positions $(i, j)$ with $i < j$ satisfy a simple visual condition: the two words at these positions “fascinate Ahmad” if…

codeforcescompetitive-programming
CF 105314A - Rama and Cats Syndrome

We are given several test cases. In each test case, there is an array of positive integers representing values of food bags. Rama must choose exactly $n-1$ of these bags and her “satisfaction” is defined as the bitwise OR of the chosen values.

codeforcescompetitive-programming
CF 105315J - Hamza's Birthday

Each test case describes a collection of dishes, where every dish belongs to a specific restaurant and has a numeric taste value. The key constraint is that you cannot mix restaurants. You must pick exactly one restaurant and take all dishes belonging to it.

codeforcescompetitive-programming
CF 105315F - Osama's Birthday

We are given several collections of flower types, where each collection (called a bouquet) is essentially a set of allowed flower labels drawn from a universe of size at most 60. For each test case, Osama chooses exactly one bouquet and then builds a garden of length $m$.

codeforcescompetitive-programming
CF 105315B - Noorhan's Birthday

We are given a number of independent queries. Each query provides an integer n, and we must output a single integer a, where a is the prime number closest to n. If two primes are equally close, the smaller one must be chosen.

codeforcescompetitive-programming
CF 105316K - Marks

Each test case describes a classroom snapshot. For every test case, we are given several students, and for each student we receive exactly eight integers representing their scores in eight different subjects.

codeforcescompetitive-programming
CF 105316G - Intersection Not Allowed

We are given multiple independent test cases. In each test case there are $n$ lockers and $q$ rental requests. Each request fixes one locker $x$ and a time interval $[l, r]$, meaning that locker $x$ is occupied throughout that entire interval.

codeforcescompetitive-programming
CF 105316B - Omar's Magic Trick

We are given a deterministic process that starts with exactly three single-digit cards. Each card holds a value from 1 to 9. The process repeatedly transforms the whole collection: every card value is multiplied by 3, and then the result is split back into its decimal digits.

codeforcescompetitive-programming
CF 105317F - Maze Runner

We are given a very small grid, at most 10 by 10, where every cell contains a lowercase letter. From any cell we are allowed to move to any of its 8 neighbors, including diagonals, and we are allowed to revisit cells arbitrarily many times.

codeforcescompetitive-programming
CF 105317B - Paulo's Plan

We are given a very small set of distinct characters in a string $T$, and a much larger string $S$ that contains exactly the same multiset of characters as $T$, just in repeated quantities. We are allowed to permute both strings freely.

codeforcescompetitive-programming
CF 105336C - 种树

We are given a tree with $n$ nodes representing neighborhoods connected by roads. Some of these neighborhoods are already completed, while the rest still need work. Each day, a team of three workers chooses exactly three neighborhoods that form a connected subgraph in the tree.

codeforcescompetitive-programming
CF 105345J - Phantom Poker

We are given an array of $n$ cards laid out in a line, where each card carries a value from 1 to 13. Over time, the values change through updates, and we are also asked to answer range queries. A query of the first type changes a single position in the array to a new value.

codeforcescompetitive-programming
CF 105345D - Nightmare on 24th

We are given a line of buildings, each containing some number of students. Freddy always starts from the first building and moves strictly to the right. As he visits buildings in order, he accumulates the number of students he has seen so far.

codeforcescompetitive-programming
CF 105346H - Speedway Evacuation

We are given a line segment of integer positions from 0 to n. Several students stand on integer points between 1 and n−1, and multiple students may share the same position.

codeforcescompetitive-programming
CF 105346C - Spooky Hallway

We are given a binary string representing a line of lanterns, where each position is either lit or unlit. In one move, we are allowed to pick any contiguous segment and flip every bit inside it, turning zeros into ones and ones into zeros.

codeforcescompetitive-programming
CF 105348A - Try and Cry

We are given a round-robin tournament with $N$ teams where every pair plays exactly one match and every match produces a winner. A win gives 1 point, a loss gives 0 points. After all matches, teams are ranked by total points, and ties are resolved using run rate.

codeforcescompetitive-programming
CF 105350B - A Cool Pair Problem

We are given an upper bound $n$. From all pairs of integers $(a, b)$ such that both lie between 1 and $n$ and $a < b$, we are only allowed to consider those pairs where the bitwise AND of the two numbers is zero.

codeforcescompetitive-programming
CF 105358H - Points Selection

We are given a set of points on a grid, each point having an integer position and a weight. For any rectangle anchored at the origin and defined by coordinates $(a, b)$, we look at all points whose $x$-coordinate is at most $a$ and whose $y$-coordinate is at most $b$.

codeforcescompetitive-programming
CF 105358B - Mountain Booking

We are given a tree on $n$ nodes where each edge has a weight. Over time, the tree is modified in a very controlled way: each day removes exactly one existing edge and adds exactly one new edge, and the structure always remains a tree.

codeforcescompetitive-programming
CF 105363A - Hello!

We are given several short strings, and for each one we must decide whether it can be rearranged to form the word “hola”. Rearranging means we are allowed to permute the characters freely, but we cannot add or remove any character.

codeforcescompetitive-programming
CF 105364C - Numbers in the Grid

We are working with a rectangular grid that starts completely empty in the sense that every cell initially holds zero. Then we perform a sequence of operations.

codeforcescompetitive-programming
CF 105380D - Make It Good

We are given an array and we only care about its prefixes. For each prefix, we must decide whether it has a special property called “good”.

codeforcescompetitive-programming
CF 105381K - King's Challenge

We are given multiple queries. Each query describes two integers $n$ and $k$, and asks us to work with the number formed by selecting $k$ distinct elements from a set of size $n$, ordered, which is the falling factorial $$P(n,k) = n cdot (n-1) cdot dots cdot (n-k+1).

codeforcescompetitive-programming
CF 105381F - Destroying Monsters

We are given several test cases. Each test case describes a set of monsters placed on a number line and a set of weapons. Every monster sits at a single integer coordinate, and multiple monsters can share the same position.

codeforcescompetitive-programming
CF 105381A - Trip Counting I

We are working with a complete undirected graph on $n$ countries, but some edges have been destroyed. After these removals, we are left with a simple undirected graph.

codeforcescompetitive-programming
CF 105383J - Just Round Down

We are given a single positive real number written as a string with a decimal point. The task is to compute its floor, meaning the greatest integer that does not exceed the value, and output that integer without any decimal part.

codeforcescompetitive-programming
CF 105383G - Game of Rounding

We are given an array of non-negative values representing rewards earned at each level of a game. For any contiguous segment starting at position l and ending at r, the player’s performance score is computed as the rounded average of that segment: take the sum of values on…

codeforcescompetitive-programming
CF 105383E - Efficient Slabstones Rearrangement

We are given a one-dimensional garden represented as a line of m cells. Several existing slabs are already placed along this line, each occupying a continuous interval.

codeforcescompetitive-programming
CF 105383C - Cards

We are given a collection of cards, each card carrying two numbers: one written on its front side and one on its back side.

codeforcescompetitive-programming
CF 105383A - Animal Farm

We are given a collection of animals, each described by its species name and a numeric influence value. Among these animals, we must form a leadership council by selecting any subset, but the selection is constrained by a single special species called pigs.

codeforcescompetitive-programming
CF 105384I - Increasing Income

We are given a fixed permutation $p$ of size $n$. We are allowed to choose another permutation $q$ of the indices $1$ to $n$.

codeforcescompetitive-programming
CF 105384J - Jesse's Job

We are given a permutation of length $n$. Jesse is allowed to split the positions into two nonempty groups. One group is colored yellow, the other blue.

codeforcescompetitive-programming
CF 105384F - Formal Fring

We are given an integer X, and we consider all multisets made of powers of two such that their sum equals X. Each multiset is just a collection like {1, 1, 2, 8, 8} whose total sum is X. From each such multiset S, we imagine splitting its elements into two groups S1 and S2.

codeforcescompetitive-programming
CF 105384E - Equalizer Ehrmantraut

We are counting how many pairs of arrays $a$ and $b$, both of length $n$, can be formed using values from $1$ to $m$, such that a specific symmetry condition holds between every pair of positions. Pick any two indices $i < j$.

codeforcescompetitive-programming
CF 105384C - Chemistry Class

We are given an even number of students, specifically 2n, each with a numeric chemistry skill. The teacher must split them into n disjoint pairs, so every student belongs to exactly one pair.

codeforcescompetitive-programming
CF 105384B - Breaking Bad

We are given an $n times n$ grid where each cell contains a value between 0 and 4. We must choose exactly one cell from every row and every column, which means we are effectively selecting a permutation of columns for the rows.

codeforcescompetitive-programming
CF 105385L - Intersection of Paths

We are given a weighted tree with up to half a million vertices, and each edge carries a weight that can change temporarily during each query. For every query we first modify exactly one edge weight, and then we are allowed to choose $k$ simple paths in the tree.

codeforcescompetitive-programming
CF 105385M - Palindromic Polygon

We are given a convex polygon with vertices ordered counterclockwise. Each vertex carries a value, and we are allowed to pick any subset of vertices.

codeforcescompetitive-programming
CF 105385J - Colorful Spanning Tree

We are given several test cases. Each test case describes a complete graph, but the graph is not defined on individual vertices directly. Instead, vertices are grouped by colors. For each color i, there are ai identical vertices.

codeforcescompetitive-programming
CF 105385I - Left Shifting

We are given a string and we can rotate it cyclically to the left by some number of positions. A left shift by $d$ means taking the substring starting from position $d$ to the end and attaching the prefix $0 dots d-1$ at the end.

codeforcescompetitive-programming
CF 105385E - Sensors

We are given a line of positions indexed from 0 to n − 1. Initially every position is marked red. Over time, we repeatedly pick one position and permanently flip it to blue. After each flip, we look at a collection of intervals, called sensors.

codeforcescompetitive-programming
CF 105385F - Divide the Sequence

We are given an integer array and we are allowed to split it into exactly $k$ contiguous non-empty segments. Each segment contributes its sum, but the contribution is weighted by the segment’s position from the left.

codeforcescompetitive-programming
CF 105385B - Triangle

We are given several test cases. In each test case, we receive a list of strings. We need to count how many triples of indices $(a, b, c)$ with $a < b < c$ satisfy a special “triangle” condition defined using string concatenation and lexicographic comparison.

codeforcescompetitive-programming
CF 105385A - Printer

We are given several printing machines that run independently but contribute to the same shared goal: producing at least $k$ total copies of a document. Each printer does not work at a constant long-term rate in a simple linear way. Instead, it follows a cycle.

codeforcescompetitive-programming
CF 105386M - Italian Cuisine

We are given a convex polygon representing a pizza, and a circular region inside it representing a pineapple topping.

codeforcescompetitive-programming
CF 105386J - The Quest for El Dorado

We are given a graph of cities connected by undirected roads, where each road belongs to a company and has a length. The structure is fixed, but movement is constrained by a sequence of tickets that must be used in order.

codeforcescompetitive-programming
CF 105386I - Left Shifting 2

We are given a string and we are allowed to cyclically shift it. After choosing a shift, we look at the resulting string arranged in a circle, meaning the last character is considered adjacent to the first.

codeforcescompetitive-programming
CF 105386G - Be Positive

We are asked to build a permutation of numbers from 0 to n minus 1 such that when we read it from left to right, the XOR of every prefix is strictly positive.

codeforcescompetitive-programming
CF 105386F - Collect the Coins

We are given a sequence of events on a number line of integer cells. Each event is a coin that appears at a specific time and position, and it exists for exactly one second.

codeforcescompetitive-programming
CF 105386A - Two-star Contest

We are given several contests. Each contest has a “star rating” and a vector of properties. The score of a contest is simply the sum of all its properties. Some property values are already fixed, while others are missing and marked as unknown.

codeforcescompetitive-programming
CF 105386C - Stop the Castle 2

We are working on a very large grid, but only a sparse set of cells are relevant: some cells contain castles and some contain obstacles. Two castles can “see” each other if they lie in the same row or column and nothing important lies strictly between them.

codeforcescompetitive-programming
CF 105387L - Bee coloring book

We are given a rectangular board with $n$ rows and $m$ columns. Each cell is a hexagon in a honeycomb layout, which means every cell can touch up to six neighbors instead of the usual four in a grid.

codeforcescompetitive-programming
CF 105387K - Stroller

We are given two rectangles. One represents a car trunk with sides a and b, the other represents a folded stroller with sides c and d. The stroller can be rotated by 90 degrees, meaning we can swap its sides, but we cannot deform it.

codeforcescompetitive-programming
CF 105387H - Toys

We are given a deterministic sequence of integers generated by repeatedly multiplying the previous value by a fixed factor and then taking a modulo. The sequence starts from a given initial value and produces exactly $n$ numbers.

codeforcescompetitive-programming
CF 105387F - Questions pack

We are given a database of questions, each question having a computed difficulty score derived from how many teams answered incorrectly relative to attempts. After scaling by 10000 and flooring, each question becomes a single integer rating.

codeforcescompetitive-programming
CF 105387B - Destroy them all!

We are given a very large grid, but only a small number of cells inside it are marked. From this state, we are allowed to choose a single empty cell and pick one of four cardinal directions.

codeforcescompetitive-programming
CF 105387A - Dilation

We are given a binary grid that represents an image after a morphological operation called dilation has been applied. Each cell is either black () or white (.).

codeforcescompetitive-programming
CF 105388J - Non-Interactive Nim

We are given several independent instances of a Nim game. Each instance consists of multiple piles, and a move consists of selecting one pile and removing a positive number of stones from it.

codeforcescompetitive-programming
CF 105388I - Geometry Hacking

We are given a very specific geometric bug to exploit. A point is fixed at the origin, and we are asked to construct simple lattice polygons that truly enclose this point strictly inside them. “Strictly inside” means the origin cannot lie on any edge or vertex.

codeforcescompetitive-programming
CF 105388G - Touching Grass

We are given a set of vertical line segments in the plane, each anchored on the x-axis and extending upward. Concretely, the i-th grass is a segment from $(xi, 0)$ to $(xi, yi)$, and all x-coordinates are distinct.

codeforcescompetitive-programming
CF 105388E - Sum of Squares

We are given a univariate polynomial $A(x)$ and we build a multivariate polynomial $D(x1, dots, xm)$ by taking two ingredients. The first is a copy of $A$ applied independently to each variable, so every variable contributes a factor $A(xi)$.

codeforcescompetitive-programming
CF 105388C - -is-this-bitset-

We are given a rooted binary tree with up to 300,000 nodes. Each node carries a weight a[i], and each node also has a target value b[i]. For every node i, we look only at the nodes on the path from the root to i, including i itself.

codeforcescompetitive-programming
CF 105388A - Coprime Array

We are given two integers, a target sum s and a constraint value x. The task is to construct an array whose elements add up exactly to s, while every element in the array must be coprime with x. Coprime here means that each element shares no common prime factor with x.

codeforcescompetitive-programming
CF 105390D - String From Another World

We are given a target string $s$ and a fixed number of seconds $m$. Starting from an empty string $t$, each second we apply exactly one operation.

codeforcescompetitive-programming
CF 105390B - Simple Update - II

We are given a binary string and a parameter $k$. For each value of $k$ from $1$ up to $lfloor n/2 rfloor$, we are allowed to repeatedly apply a transformation that acts on a window of length $2k$.

codeforcescompetitive-programming
CF 105394L - Laundry

We are given items that must be washed using one of three washing programs, A, B, or C. Each laundry load uses exactly one program and can contain at most $k$ items. Every item does not have a single fixed program, instead it comes with a set of allowed programs.

codeforcescompetitive-programming
CF 105394J - Jigsaw Present

We are given a collection of $n$ jigsaw puzzles. Each puzzle has two attributes: the number of pieces it contains and a difficulty value that can be positive or negative. A “gift” is defined as choosing any subset of these puzzles.

codeforcescompetitive-programming
CF 105394H - Headline Heat

We are given a collection of university names, a set of rivalries between some pairs of universities, and a sequence of news articles. For each article, we must decide whether it is “balanced enough” or whether it would anger at least one coach.

codeforcescompetitive-programming
CF 105394E - Even Odd Game

We are given a finite collection of cards, each card representing a unary operation on a shared integer state. Each move, a player picks an unused card and applies its operation to the current value. The players alternate until all cards are consumed.

codeforcescompetitive-programming
CF 105394D - Dark Alley

We are working on a one-dimensional alley of positions from 1 to n. At certain positions we may place or remove lamps, each lamp having a positive brightness value.

codeforcescompetitive-programming
CF 105394B - Bookshelf Bottleneck

We are given a collection of cuboid-shaped books, and each book can be freely rotated in 3D before being placed. All books must be placed upright on a shelf in a single horizontal row, meaning each book contributes exactly one rectangular footprint on the shelf surface, and…

codeforcescompetitive-programming
CF 105394A - Alien Attack 2

We are given a social network of people where friendships form an undirected graph. The aliens cannot abduct individuals independently.

codeforcescompetitive-programming
CF 105401K - Same Segment

We are given a line of positions from 1 to N, and we must assign each position a value between 0 and K. On top of this array, there are M constraints. Each constraint specifies a segment [l, r] and demands that the sum of values inside that segment is exactly K.

codeforcescompetitive-programming
CF 105401I - Mukjjippa

We are simulating a probabilistic turn-based game where two players repeatedly play rock-paper-scissors, but the outcome does not immediately determine the winner.

codeforcescompetitive-programming
CF 105401G - Make RUN Great Again

We have a set of $N$ clubs whose scores are already fixed, and one additional club called RUN whose score we are free to choose at the end.

codeforcescompetitive-programming
CF 105401C - Counting Regions

We start with an $N times N$ grid where every cell is initially white. The grid is then modified through a fixed sequence of operations, each operation recolors either an entire row or an entire column to black or white.

codeforcescompetitive-programming
CF 105401B - Construct a Coin Set

We are asked to construct a set of coin denominations that interact with the greedy change-making strategy in a very specific way. For any amount, the greedy strategy always picks the largest coin not exceeding the remaining sum.

codeforcescompetitive-programming
CF 105403B - Programming Contest

Each test case gives two arrays of scores, one belonging to Arturo and one belonging to Benito. For every index we have a pair of values, but the pairing is completely unknown: we are free to assign Arturo’s numbers and Benito’s numbers to different contest problems in any…

codeforcescompetitive-programming
CF 105403C - Painting Stones

We are given a line of stones, each stone having either a fixed color already assigned or being unpainted. Our task is to fill in all unpainted stones using a palette of c colors so that no two adjacent stones share the same color.

codeforcescompetitive-programming
CF 105404F - Painting Squares

We start with an empty grid of size $n times m$, where every cell is initially white. The only way to modify the grid is to choose whole rows or whole columns and paint them completely black.

codeforcescompetitive-programming
CF 105404B - Dividing

We are given several independent test cases. Each test case provides a list of positive integers. The task is to determine whether there exists at least one element in the list that can divide every element in the same list, including itself in a trivial way.

codeforcescompetitive-programming
CF 105404C - Games with Queta

We are given a segment on a line, marked by two fixed points. Inside this segment there are several objects, each placed at a distinct coordinate. Every object is initially facing either left toward the first mark or right toward the second mark.

codeforcescompetitive-programming
CF 105408G - GCDland Mystical Arrays

We are given a list of integers and asked to verify a very specific structural property: every pair of numbers in the list must share exactly the same greatest common divisor.

codeforcescompetitive-programming
CF 105416H - Chicken Farm

We are simulating a small economy that evolves over a fixed number of days. Alice starts with a single chicken that already produces eggs every day after it has finished its initial sleep requirement.

codeforcescompetitive-programming
CF 105416F - Incubation Line

We are given a set of positions on a number line where eggs are placed. We are also allowed to place a fixed number of heat lamps, each at an integer coordinate.

codeforcescompetitive-programming
CF 105416B - Hard Boiled

We are given a collection of eggs, where each egg requires a specific amount of time to be fully cooked. Jacob has a fixed total time budget and a single pot, which means he can only cook one egg at a time without overlap.

codeforcescompetitive-programming
CF 105416A - Which is up?

We are given a deterministic process that generates a sequence of egg orientations. Each egg has a state in the range from 0 to 5, and the sequence starts from a fixed initial state for the first egg.

codeforcescompetitive-programming
CF 105417I - Rolling Egg

We are looking at a dynamical system over the finite field $mathbb{F}p$. We pick a starting point $x0$, then repeatedly apply a randomly chosen polynomial function $f : mathbb{F}p to mathbb{F}p$.

codeforcescompetitive-programming
CF 105417H - Chicken Farm

We are given a system that evolves over a limited number of days. Initially there is exactly one chicken and a stock of eggs that starts at zero.

codeforcescompetitive-programming
CF 105417E - Yodel Yolk

We are given a one-dimensional landscape represented as an array of heights. Each index is a position in a mountain range, and the height value is the elevation at that position.

codeforcescompetitive-programming
CF 105417C - Egg Order

We are given a set of integers from 1 to n, each appearing exactly once, and we must arrange them in some order. From this arrangement, we look at contiguous segments and focus on those segments where values increase by exactly 1 at every step.

codeforcescompetitive-programming