brain

tamnd's digital brain — notes, problems, research

41832 notes

CF 1967E2 - Again Counting Arrays (Hard Version)

We are asked to count arrays of integers that meet a very particular set of conditions. We have a starting number, $b0$, and we want to consider sequences $b0, b1, dots, bn$ where consecutive elements differ by exactly 1.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1942F - Farmer John's Favorite Function

We have an array $a$, and a recursively defined value: $$f(1)=sqrt{a1}, qquad f(i)=sqrt{f(i-1)+ai}.$$ After every point update $ak leftarrow x$, we need the integer part of $f(n)$. The first obstacle is that the recurrence uses real numbers.

codeforcescompetitive-programmingbrute-forcedata-structuresimplementationmath
CF 1945G - Cook and Porridge

We are simulating a queue of students where the front of the queue is repeatedly served for a limited number of minutes. Each student, once served, leaves to “process” their porridge for a fixed number of minutes, and then returns to the queue.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresimplementation
CF 1967B2 - Reverse Card (Hard Version)

We are asked to count ordered pairs of integers $(a, b)$ with $1 le a le n$ and $1 le b le m$ such that $b cdot gcd(a, b)$ is divisible by $a+b$. The inputs are multiple test cases, each specifying a pair of limits $n$ and $m$.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1945C - Left and Right Houses

We are given a village with n houses aligned in a row. Each resident has a preference for which side of a street they want to live on: left (0) or right (1).

codeforcescompetitive-programmingbrute-force
CF 1954A - Painting the Ribbon

We are asked to decide whether Alice can paint a ribbon of n parts using m colors such that Bob, who can repaint at most k parts into the same color, cannot make the entire ribbon monochromatic.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1975I - Mind Bloom

Codeforces 1975I: Mind Bloom

codeforcescompetitive-programmingdp
CF 483B - Friends and Presents

Codeforces 483B: Friends and Presents

codeforcescompetitive-programmingbinary-searchmath
CF 1942D - Learning to Paint

We are asked to help Elsie evaluate her paintings on a 1D canvas of n cells. Each cell can be painted or left empty, and the painting's beauty is determined by a 2D array a.

codeforcescompetitive-programmingbinary-searchdata-structuresdfs-and-similardpgreedyimplementationsortings
CF 1944A - Destroying Bridges

We are asked to consider a network of islands where initially every pair of islands is connected by a bridge. There are n islands, numbered from 1 to n, and Everule lives on island 1. Dominater can destroy up to k bridges to reduce the number of islands that Everule can reach.

codeforcescompetitive-programminggraphsgreedymath
HSK 4 Grammar Points

Comprehensive guide to HSK 4 grammar: complex comparisons, formal negation, pivotal constructions, topic-comment structures, and upper-intermediate patterns.

chinesehsk4grammarupper-intermediatehskb1
CF 1965F - Conference

We are given a collection of time intervals, each interval belonging to a different lecturer. Lecturer i is available on a continuous range of days from li to ri, and can be assigned to at most one conference day.

codeforcescompetitive-programmingdata-structuresflows
CF 1948C - Arrow Path

We have a 2-row grid with $n$ columns, and each cell contains an arrow pointing either left or right. The robot starts at the top-left corner, and each second it first moves to an adjacent cell (up, down, left, right) and then follows the arrow in the new cell.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similardpgraphsshortest-paths
CF 1967F - Next and Prev

We are given a permutation, and we observe it evolving over time by revealing its prefix. After revealing the first $q$ elements, we throw away all values greater than $q$, but keep the relative order of the remaining values.

codeforcescompetitive-programmingbrute-forcedata-structuresimplementation
CF 1958A - 1-3-5

We are asked to construct an exact sum using coins of values 1, 3, and 5. For each target amount n, we want to pay exactly n using any number of 3 and 5 coins, and we are only forced to use 1-coins when it becomes unavoidable.

codeforcescompetitive-programming*specialdp
CF 1973E - Cat, Fox and Swaps

Codeforces 1973E: Cat, Fox and Swaps

codeforcescompetitive-programminggraphsmathsortings
CF 1958I - Equal Trees

We are given two rooted trees on the same labeled vertex set from 1 to n, both rooted at 1. Each tree is described by its parent array, so every node knows its immediate parent except the root.

codeforcescompetitive-programming*specialgraphsmeet-in-the-middle
CF 1975C - Chamo and Mocha's Array

Codeforces 1975C: Chamo and Mocha's Array

codeforcescompetitive-programmingbinary-searchbrute-forcegreedy
CF 493E - Vasya and Polynomial

We are asked to count the number of polynomials with non-negative integer coefficients that satisfy a very specific evaluation property.

codeforcescompetitive-programmingmath
CF 1943E1 - MEX Game 2 (Easy Version)

We are asked to simulate a two-player game on an array of integers, but with a compressed representation where we only know the frequencies of each integer.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedy
CF 1943D2 - Counting Is Fun (Hard Version)

We are asked to count certain arrays with bounded elements that satisfy a combinatorial property. Specifically, consider all arrays of length n where each element is between 0 and k.

codeforcescompetitive-programmingcombinatoricsdp
CF 1955D - Inaccurate Subsequence Search

We are asked to count subsegments of length m in an array a that are “good” relative to another array b of length m. A subsegment is considered good if, after rearranging its elements, at least k of them match elements from b.

codeforcescompetitive-programmingdata-structurestwo-pointers
HSK 7 Grammar Points

Comprehensive guide to HSK 7 grammar: academic research language, classical grammar in modern use, specialized register patterns, and C1+ mastery structures.

chinesehsk7grammarmasteryhskc1
CF 491B - New York Hotel

The city is a rectangular grid. Every hotel and every restaurant is located at an intersection with coordinates $(x,y)$.

codeforcescompetitive-programminggreedymath
CF 1951B - Battle Cows

We have a line of cows, each with a unique Cowdeforces rating, and they compete in a sequential tournament. The tournament begins with the first two cows, and each subsequent match is between the winner of the previous match and the next cow in line.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedy
CF 1943F - Minimum Hamming Distance

We are given two binary strings of equal length. The first string, call it the reference string, defines a constraint on how a valid target string must behave. The second string is the one we want to stay as close as possible to after we adjust it into a valid configuration.

codeforcescompetitive-programmingdp
CF 1967D - Long Way to be Non-decreasing

We are given an array where each position contains a value in the range $1$ to $m$, and a second array that defines a deterministic transformation on values: every value $x$ has a fixed replacement $bx$.

codeforcescompetitive-programmingbinary-searchdfs-and-similargraphsimplementationshortest-pathstwo-pointers
CF 1954E - Chain Reaction

We are given a line of monsters, each with some initial health. One operation consists of choosing a single monster as the starting point of a “chain lightning”.

codeforcescompetitive-programmingbinary-searchdata-structuresdsugreedyimplementationmathnumber-theory
CF 1958E - Yet Another Permutation Constructive

We are given a permutation, which is just an ordering of the numbers from 1 to n. We repeatedly apply a transformation that removes elements which are strictly smaller than at least one of their immediate neighbors.

codeforcescompetitive-programming*specialconstructive-algorithms
CF 1965D - Missing Subarray Sum

We are given a multiset that contains almost all subarray sums of an unknown array a, where a has two special properties: every element is strictly positive and the array reads the same forwards and backwards.

codeforcescompetitive-programmingconstructive-algorithms
CF 1956E1 - Nene vs. Monsters (Easy Version)

We are given a circle of n monsters, each with an initial energy level ai. They are numbered from 1 to n, and each monster attacks its clockwise neighbor simultaneously in a single round.

codeforcescompetitive-programmingbrute-forceimplementationmath
CF 1975D - Paint the Tree

Codeforces 1975D: Paint the Tree

codeforcescompetitive-programmingbrute-forcedfs-and-similardpgreedyshortest-pathstrees
CF 1942A - Farmer John's Challenge

We need to construct an array of length n such that exactly k of its cyclic shifts are sorted in nondecreasing order. A cyclic shift chooses some position as the new beginning of the array and wraps the remaining elements around.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1951E - No Palindromes

We are given a string and we are allowed to cut it into contiguous pieces. The goal is to decide whether we can cut it so that every resulting piece is not a palindrome. If it is possible, we must also construct one such cut.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdivide-and-conquergreedyhashingimplementationmathstrings
CF 1974F - Cutting Game

Codeforces 1974F: Cutting Game

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresimplementationsortingstwo-pointers
HSK 9 Grammar Points

Comprehensive guide to HSK 9 grammar: native-level classical Chinese, literary production, oral defense mastery, and full C2+ control of written and spoken registers.

chinesehsk9grammarnativehskc2
CF 1954F - Unique Strings

We are given a binary string of length $n$ where the first $c$ characters are ones and the remaining $n - c$ characters are zeros. We are allowed to perform up to $k$ operations, where each operation flips a zero into a one.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1950G - Shuffling Songs

Each song has two attributes, a genre and a writer. After removing some songs, we are allowed to reorder the remaining songs arbitrarily.

codeforcescompetitive-programmingbitmasksdfs-and-similardpgraphshashingimplementationstrings
CF 1955A - Yogurt Sale

Maxim wants to buy exactly n yogurts from a store where a single yogurt costs a burles, but there is a promotion offering two yogurts for b burles. For each test case, we must calculate the minimum amount he can spend to buy exactly n yogurts.

codeforcescompetitive-programmingmath
CF 1954B - Make It Ugly

We are given an array of integers that is guaranteed to be "beautiful," which means that through a specific operation, all elements can eventually become the same.

codeforcescompetitive-programmingimplementationmath
CF 1956A - Nene's Game

We are given an increasing list of positions, and a process that repeatedly deletes players from a line. In each round, we look at the current lineup and try to remove the players standing at positions $a1, a2, ldots, ak$.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresgamesgreedy
CF 1945B - Fireworks

Two firework machines start at time zero and then keep launching fireworks periodically. The first machine fires at times that are multiples of a, and the second fires at multiples of b.

codeforcescompetitive-programmingmathnumber-theory
CF 1954D - Colored Balls

We are given a collection of balls, each assigned one of n distinct colors, where color i has ai balls. We are allowed to group these balls, but each group can have at most two balls, and no two balls in the same group can have the same color.

codeforcescompetitive-programmingcombinatoricsdpmathsortings
CF 1950C - Clock Conversion

We are given times expressed in the 24-hour clock format, for example 00:00 for midnight, 13:45 for one forty-five in the afternoon, or 23:59 for one minute before midnight. Our task is to convert each time into the 12-hour clock format, which uses the familiar AM and PM labels.

codeforcescompetitive-programmingimplementationmath
CF 1976A - Verify Password

Codeforces 1976A: Verify Password

codeforcescompetitive-programmingimplementationsortingsstrings
CF 1943D1 - Counting Is Fun (Easy Version)

We are looking at arrays of length n, where each position can hold an integer between 0 and k. Every such array is considered a candidate, so the total universe is (k+1)^n. The notion of “good” is defined through an operation that subtracts 1 from a contiguous segment.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpmath
CF 495A - Digital Counter

The elevator always displays a two-digit floor number from 00 to 99. Each digit is drawn using a seven-segment display. A segment can be broken. When a segment is broken, it cannot light up even if it should.

codeforcescompetitive-programmingimplementation
CF 1945H - GCD is Greater

We are given an array of integers, and two players split the array into two groups. Kirill is allowed to choose a subset that is neither too small nor too large, specifically at least two elements and at most $n-2$ elements. Those chosen elements form the red group.

codeforcescompetitive-programmingbrute-forcedata-structuresmathnumber-theory
CF 1942B - Bessie and MEX

We are given an array a of length n, constructed from some unknown permutation p of the integers 0 through n-1. Each element of a satisfies the relation a[i] = MEX(p[1..i]) - p[i]. The task is to reconstruct any valid permutation p that produces this a.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1958F - Narrow Paths

We are working on a very constrained grid: only two rows and a large number of columns. The start is the top-left cell, and the goal is the bottom-right cell.

codeforcescompetitive-programming*specialcombinatorics
CF 1967E1 - Again Counting Arrays (Easy Version)

We are given a fixed starting height $b0$ and we imagine building an integer path $b0, b1, ldots, bn$ where each step moves by exactly $+1$ or $-1$, but the path is never allowed to go below zero. This is a standard “walk on the non-negative integers” with unit steps.

codeforcescompetitive-programmingcombinatoricsdpfftmath
CF 1949G - Scooter

Each building has two independent pieces of information. The first string describes what class is held there. A building may need a mathematics professor, a computer science professor, or no professor at all. The second string describes which professor is initially located there.

codeforcescompetitive-programminggraphsgreedy
CF 1956E2 - Nene vs. Monsters (Hard Version)

We are given a circle of monsters, each with an energy level. The monsters attack their neighbor in a fixed clockwise order: monster 1 attacks monster 2, monster 2 attacks monster 3, and so on, with the last monster attacking the first.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmath
CF 1952C - They Have Fooled

The input to this problem is a single integer $n$, with $0 le n le 12$. Despite how small this looks, the task is not about iterating or simulating anything directly from this number in a naive arithmetic sense.

codeforcescompetitive-programming*specialbrute-forceschedules
CF 1955C - Inhabitant of the Deep Sea

We are given a line of ships, each with some durability, and a fixed attack pattern that always targets the current leftmost surviving ship, then the current rightmost surviving ship, and repeats this alternation until a total of $k$ attacks have been made or all ships sink.

codeforcescompetitive-programminggreedyimplementationmath
CF 1973C - Cat, Fox and Double Maximum

Codeforces 1973C: Cat, Fox and Double Maximum

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmathsortings
CF 1975E - Chain Queries

Codeforces 1975E: Chain Queries

codeforcescompetitive-programmingbinary-searchdata-structuresdfs-and-similarimplementationtrees
CF 1974E - Money Buys Happiness

Codeforces 1974E: Money Buys Happiness

codeforcescompetitive-programmingdp
CF 485B - Valuable Resources

We are asked to build a square city on a 2D Cartesian map such that it encloses all given mines, represented as points with integer coordinates. The sides of the square must remain parallel to the axes, and our goal is to minimize the area of the square.

codeforcescompetitive-programmingbrute-forcegreedy
CF 488A - Giga Tower

We are standing at an integer floor number in a very large tower that extends far below zero and far above zero. From our current floor $a$, we are only allowed to move upward, meaning we repeatedly add positive integers.

codeforcescompetitive-programmingbrute-force
CF 1967A - Permutation Counting

We are given a set of cards, each labeled with a number from 1 to n. For each number i, we have ai cards of that type.

codeforcescompetitive-programmingbinary-searchgreedyimplementationmathsortings
CF 1950F - 0, 1, 2, Tree!

We are asked to construct a rooted tree with a specific number of vertices having 0, 1, or 2 children. The input gives three numbers: a vertices with 2 children, b vertices with 1 child, and c vertices that are leaves.

codeforcescompetitive-programmingbitmasksbrute-forcegreedyimplementationtrees
CF 1952B - Is it stated?

We are given a list of strings, each consisting of lowercase English letters, and for each string, we are asked to answer either "YES" or "NO" based on a hidden pattern.

codeforcescompetitive-programming*specialstrings
CF 488B - Candy Boxes

The task is to reconstruct a set of four integers representing candy counts in boxes such that three properties are equal: the arithmetic mean, the median, and the range. We are given some subset of these four numbers (0 to 4) in arbitrary order.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsmath
CF 493A - Vasya and Football

We are given the names of the home and away teams, followed by a chronological list of card events during a football match. Each event specifies the minute, which team the player belongs to, the player's jersey number, and whether the referee gives a yellow card or a red card.

codeforcescompetitive-programmingimplementation
CF 1956C - Nene's Magical Matrix

We are given a square matrix of size $n times n$ initially filled with zeroes. Nene can perform two types of operations: either set an entire row to a permutation of $1$ through $n$ or set an entire column to such a permutation.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1976B - Increase/Decrease/Copy

Codeforces 1976B: Increase/Decrease/Copy

codeforcescompetitive-programminggreedyimplementation
CF 1975F - Set

Codeforces 1975F: Set

codeforcescompetitive-programmingbitmasksbrute-forcecombinatoricsdfs-and-similardivide-and-conquerdpmath
CF 1949A - Grove

Every tree is planted at an integer lattice point. Around that point we place a disk of radius r, representing the root system. Two conditions must hold. The entire disk must stay inside the square lawn.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpgeometryprobabilities
CF 1974B - Symmetric Encoding

Codeforces 1974B: Symmetric Encoding

codeforcescompetitive-programmingimplementationsortingsstrings
CF 495B - Modular Equations

Codeforces 495B: Modular Equations

codeforcescompetitive-programmingmathnumber-theory
CF 1951F - Inversion Composition

We are asked to construct a permutation q of size n such that the sum of inversions of q and the composition q ∘ p equals a given target k. The input permutation p is fixed, and inversions count how many pairs of indices are out of order.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 1955H - The Most Reckless Defense

We are given a grid where some cells form a fixed path from the top-left corner to the bottom-right corner. An enemy walks along this path one cell per second.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsdpflowsgraph-matchingsshortest-paths
CF 1958C - Firewood

Monocarp has a single log of wood that weighs exactly $2^n$ grams. He needs to split this log into pieces such that he can assemble exactly $k$ grams of wood for today's fireplace, leaving the remaining $2^n-k$ grams for tomorrow.

codeforcescompetitive-programming*special
CF 1942C2 - Bessie's Birthday Cake (Hard Version)

We have a regular polygon with n vertices arranged on a circle. Some x vertices are already available for use. We may additionally choose at most y more vertices.

codeforcescompetitive-programminggeometrygreedymath
CF 1952I - Dark Matter

The input describes a single arithmetic-style expression consisting of integers combined with the + operator. The key difference from standard arithmetic is that + does not mean numeric addition.

codeforcescompetitive-programming*specialbitmasksgeometry
CF 1955E - Long Inversions

We are given a binary string and an operation that flips a block of fixed length $k$, turning every 0 into 1 and every 1 into 0. We may apply this operation as many times as we want, but the chosen length $k$ is fixed for the entire process.

codeforcescompetitive-programmingbrute-forcegreedyimplementationsortings
CF 1951D - Buying Jewels

We are given a buyer who starts with a fixed number of coins. A shop is not fixed in advance; instead, we are allowed to design up to 60 sequential stalls. Each stall has an unlimited supply of jewels, and a fixed integer price per jewel.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1955F - Unfair Game

We are asked to maximize the number of games Bob can win in a repeated XOR game against Alice. The game is played on a multiset of integers containing only ones, twos, threes, and fours. Alice wins if the XOR of all remaining numbers is non-zero; otherwise, Bob wins.

codeforcescompetitive-programmingdpgamesgreedymathschedules
CF 1974A - Phone Desktop

Codeforces 1974A: Phone Desktop

codeforcescompetitive-programminggreedymath
CF 1949K - Make Triangle

We are given a multiset of positive integers and three required group sizes. Every number must belong to exactly one of the three groups, and each group must contain exactly the requested number of elements. After splitting the numbers, we look only at the three group sums.

codeforcescompetitive-programmingconstructive-algorithmsmath
Sindarin Vocabulary: Numbers

Complete Sindarin number system: cardinals 1–1000, ordinals 1st–10th, number compounds, duodecimal counting, and number words in place names.

sindarinvocabularynumberstolkien
CF 1975G - Zimpha Fan Club

Codeforces 1975G: Zimpha Fan Club

codeforcescompetitive-programmingfftgreedymathstrings
CF 1973A - Chess For Three

Codeforces 1973A: Chess For Three

codeforcescompetitive-programmingbrute-forcedpimplementationmath
CF 1950A - Stair, Peak, or Neither?

We are given three digits, a, b, and c, and must classify their relationship. A sequence is called a stair when the values strictly increase from left to right, meaning a < b < c.

codeforcescompetitive-programmingimplementation
CF 1958B - Clock in the Pool

The clock is not a normal continuous display, it behaves like a repeating cycle of three states. Every cycle has length $3k$ seconds.

codeforcescompetitive-programming*specialmath
CF 491A - Up the hill

Codeforces 491A: Up the hill

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1976C - Job Interview

Codeforces 1976C: Job Interview

codeforcescompetitive-programmingbinary-searchdpgreedyimplementationtwo-pointers
CF 1950B - Upscaling

We are asked to generate a checkerboard pattern that is made of larger $2 times 2$ tiles. Each tile is either fully filled with the character or fully filled with .. The size of the grid is determined by an input integer $n$, and the final grid has dimensions $2n times 2n.

codeforcescompetitive-programmingimplementation
CF 1951G - Clacking Balls

We are given a circle of baskets numbered from 1 to $m$, and $n$ balls initially placed in distinct baskets. Alice repeatedly chooses one of the balls uniformly at random and moves it clockwise to the next basket.

codeforcescompetitive-programmingcombinatoricsmathprobabilities
CF 1958J - Necromancer

We are simulating a very specific combat process on a fixed line of monsters, and answering many independent queries on subsegments of that line.

codeforcescompetitive-programming*special
CF 1975B - 378QAQ and Mocha's Array

Codeforces 1975B: 378QAQ and Mocha's Array

codeforcescompetitive-programmingbrute-forcegreedymathsortings
CF 1956F - Nene and the Passing Game

We are given a sequence of basketball players, each with a passing range expressed as an interval $[li, ri]$. The players are numbered from 1 to $n$.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdsugraphssortings
CF 1951A - Dual Trigger

We are given a row of lamps, all initially off. We can perform one type of operation any number of times: choose two lamps that are currently off and are not next to each other, and turn them both on simultaneously.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1949E - Damage per Second

We are asked to distribute a fixed number of skill points between two attributes: damage per hit and hits per second, in order to minimize the total time to kill a sequence of monsters.

codeforcescompetitive-programmingbrute-forcemath
CF 1958D - Staircase

We are given a line of staircase steps, each step either needing repair or already fine. If a step is fine, it behaves like a zero in the input. If it is broken, it carries a positive cost value that represents its repair difficulty. The repair process is constrained by days.

codeforcescompetitive-programming*special
CF 1943E2 - MEX Game 2 (Hard Version)

We are given a multiset of integers, but instead of listing it explicitly, we receive frequencies of each value from 0 up to some maximum m. Alice and Bob remove elements from this multiset until nothing remains.

codeforcescompetitive-programmingbinary-searchgreedytwo-pointers
CF 1942C1 - Bessie's Birthday Cake (Easy Version)

We are given a regular polygon with $n$ vertices representing a cake. Some vertices are already selected by Bessie as potential endpoints for drawing diagonals.

codeforcescompetitive-programminggeometrygreedymath
CF 1957A - Stickogon

We are given a collection of sticks, each with an integer length. The goal is to build as many regular polygons as possible using these sticks, with the restriction that each side of a polygon must be exactly one stick, and no stick can be reused.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1945D - Seraphim the Owl

We are given a queue of n people waiting to ask Seraphim the Owl a question. Kirill arrives at the end of the line and wants to move forward so that he is among the first m people.

codeforcescompetitive-programmingdpgreedy