brain

tamnd's digital brain — notes, problems, research

41777 notes

CF 340E - Iahub and Permutations

We are given a permutation of the numbers from 1 to n, but some elements have been replaced with -1. The permutation has no fixed points, meaning no element is in its original position.

codeforcescompetitive-programmingcombinatoricsmath
CF 340D - Bubble Sort Graph

given a permutation of the Problem Understanding We are given a permutation of numbers from 1 to n. the numbers from 1 to n. ImagineImagine running bubble sort on this permutation running ordinary bubble sort on this.

codeforcescompetitive-programmingbinary-searchdata-structuresdp
CF 340A - The Wall

We are asked to count the number of bricks that get painted by both Iahub and Floyd in a specific range. The bricks are numbered with consecutive integers starting from 1.

codeforcescompetitive-programmingmath
CF 339A - Helpful Maths

The input is a string representing a sum where every number is either 1, 2, or 3, and the numbers are separated by plus signs. For example, the string 3+2+1+3 represents four summands. Xenia can only evaluate the expression if the numbers appear in non-decreasing order.

codeforcescompetitive-programminggreedyimplementationsortingsstrings
CF 339B - Xenia and Ringroad

We have a circular city with n houses arranged clockwise along a ringroad. Each house has a unique number from 1 to n, and traffic flows only clockwise. Xenia starts at house 1 and has m tasks to complete in a specific order, each task located at a house number a[i].

codeforcescompetitive-programmingimplementation
CF 339E - Three Swaps

We are given a row of n horses, initially numbered from 1 to n from left to right. Xenia performed at most three operations on the row.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargreedy
CF 339D - Xenia and Bit Operations

We start with an array whose length is exactly $2^n$. The final value is produced by repeatedly combining adjacent elements. The first level uses bitwise OR, the next level uses bitwise XOR, then OR again, then XOR again, alternating until only one number remains.

codeforcescompetitive-programmingdata-structurestrees
CF 339C - Xenia and Weights

Xenia has access to some subset of weights from 1 through 10 kilograms. For every weight type marked as available, she may use that weight any number of times. She places weights one at a time onto a balance scale.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardpgraphsgreedyshortest-paths
CF 316C2 - Tidying Up

We have an n × m grid. Every cell contains one shoe, and every shoe pair number appears exactly twice in the whole grid. A configuration is considered tidy when the two shoes belonging to every pair occupy adjacent cells. Adjacency is by a shared side, not a corner.

codeforcescompetitive-programmingflowsgraph-matchings
CF 316C1 - Tidying Up

We have a dressing room represented as a rectangular grid of size n by m, where each cell contains a single shoe. Every shoe belongs to a pair, and each pair appears exactly twice in the grid.

codeforcescompetitive-programmingflows
Kvant Math Problem 426

The figure describes a standard cyclic filling of an $n\times n$ table with the numbers $1,2,\dots,n$ in such a way that each row is a cyclic shift of the previous one.

kvantmathematicsolympiad
Kvant Math Problem 344

The 64 marked points are the centers of the squares of an $8\times 8$ grid, hence they can be identified as

kvantmathematicsolympiad
Kvant Math Problem 106

Let $f_1(x)=x^2+p_1x+q_1$ and $f_2(x)=x^2+p_2x+q_2$.

kvantmathematicsolympiad
Kvant Math Problem 945

Let

kvantmathematicsolympiad
Kvant Math Problem 926

The given conditions state that the vectors $(x,y)$ and $(u,v)$ both lie on the unit circle and are orthogonal with respect to the standard dot product since $xu+yv=0$.

kvantmathematicsolympiad
Kvant Math Problem 922

Let

kvantmathematicsolympiad
Kvant Math Problem 909

We seek an arithmetic progression

kvantmathematicsolympiad
Kvant Math Problem 899

Each number $x$ can be written uniquely as $x = \lfloor x \rfloor + t$, where $t \in (0,1)$.

kvantmathematicsolympiad
CF 316G2 - Good Substrings

We are given a source string s. We are interested only in substrings that appear inside s, and we count each distinct substring once, regardless of how many times it occurs. A substring is considered good if it satisfies every rule.

codeforcescompetitive-programmingstring-suffix-structures
Kvant Math Problem 888

Let $ab=cd$.

kvantmathematicsolympiad
CF 316F1 - Suns and Rays

The problem presents an image encoded as a 2D grid of integers where 0 represents the background and 1 represents a sun, including its rays. Each sun consists of a central ellipse (or circle) and a number of rays protruding from it.

codeforcescompetitive-programmingdfs-and-similarimplementation
CF 316E2 - Summer Homework

We are given an array of integers of size n, and a sequence of m operations of three possible types. The first type replaces a single element in the array with a new value. The second type queries the sum of a range where each element is weighted by Fibonacci numbers.

codeforcescompetitive-programmingdata-structuresmath
Kvant Math Problem 879

Work is carried out in the residue field $\mathbb{F}_p$, where $p$ is odd, so $2$ is invertible.

kvantmathematicsolympiad
CF 316D1 - PE Lesson

We have a line of n students, each holding a distinct ball numbered from 1 to n. Students can swap their balls with each other, but each student has a limit on the total number of throws they can participate in.

codeforcescompetitive-programmingbrute-forcedp
CF 316A2 - Special Task

We are given a pattern string describing a decimal code. Some positions already contain fixed digits. Some positions contain ?, meaning any digit may be placed there. Some positions contain letters from A to J. Each letter represents a digit, but with two constraints.

codeforcescompetitive-programmingmath
Kvant Math Problem 869

A number is powerful when every prime divisor appears with exponent at least $2$, so each such number has the form

kvantmathematicsolympiad
Kvant Math Problem 868

Let the tetrahedron be $ABCD$, where $ABC$ is the base.

kvantmathematicsolympiad
Kvant Math Problem 850

Let $A,B,C$ be a nondegenerate triangle with side lengths $BC=a$, $CA=b$, $AB=c$.

kvantmathematicsolympiad
Kvant Math Problem 840

The first expression can be expanded into a difference of two homogeneous cyclic sums:

kvantmathematicsolympiad
Kvant Math Problem 831

Introduce position vectors for the vertices $A,B,C,D$ in the plane.

kvantmathematicsolympiad
Kvant Math Problem 822

The initial stack is the periodic sequence of length $4n$ with pattern $G,R,B,Y$ repeating every four cards, so every consecutive block of four cards contains all four colors exactly once.

kvantmathematicsolympiad
Kvant Math Problem 819

We are given the complete graph on $n$ vertices with each edge oriented in exactly one direction.

kvantmathematicsolympiad
Kvant Math Problem 810

Let $M$ be a convex polygon with area $S$.

kvantmathematicsolympiad
Kvant Math Problem 799

Consider the first equation, $3^{x+1} + 100 = 7^{x-1}$.

kvantmathematicsolympiad
Kvant Math Problem 792

For the first two equations, small natural numbers $x$ and $y$ can be tested directly.

kvantmathematicsolympiad
Kvant Math Problem 780

The condition says that every point of the boundary of the square lies within distance $\tfrac12$ of the polygonal line $L$.

kvantmathematicsolympiad
Kvant Math Problem 756

Model the airline network as a connected undirected graph.

kvantmathematicsolympiad
Kvant Math Problem 752

Let the entries of the table be integers, and neighboring cells differ by at most $1$.

kvantmathematicsolympiad
Kvant Math Problem 741

Let

kvantmathematicsolympiad
Kvant Math Problem 729

The statement asks for a natural number with a specified property, not for all such numbers.

kvantmathematicsolympiad
Kvant Math Problem 718

The equation is

kvantmathematicsolympiad
Kvant Math Problem 708

Consider a convex quadrilateral $ABCD$ and construct squares externally on its sides $AB$, $BC$, $CD$, and $DA$, with centers $P$, $Q$, $R$, $T$ respectively.

kvantmathematicsolympiad
Kvant Math Problem 704

Consider a square $ABCD$ and a parallelogram $PQRS$ that circumscribes it, with each vertex of the square touching a different side of the parallelogram.

kvantmathematicsolympiad
Kvant Math Problem 694

The operation affects the two endpoints of an edge.

kvantmathematicsolympiad
Kvant Math Problem 682

Consider an arbitrary acute-angled triangle $\triangle ABC$.

kvantmathematicsolympiad
Kvant Math Problem 677

Consider a triangle $ABC$ and a point $M$ which is simultaneously the centroid, incenter, and orthocenter.

kvantmathematicsolympiad
Kvant Math Problem 668

Computing the first few terms of the sequence $(x_i)$ modulo small integers may reveal patterns.

kvantmathematicsolympiad
Kvant Math Problem 656

The statement concerns only the directions of the vectors, since scaling a nonzero vector does not change its angle with another vector.

kvantmathematicsolympiad
Kvant Math Problem 649

Let

kvantmathematicsolympiad
Kvant Math Problem 638

Consider small examples first.

kvantmathematicsolympiad
Kvant Math Problem 593

Consider first the simplest case, $n=2$, with two circles inside a larger circle $\mathit\Gamma$.

kvantmathematicsolympiad
Kvant Math Problem 591

Let

kvantmathematicsolympiad
Kvant Math Problem 582

Let the cyclic quadrilateral be $ABCD$, and let its diagonals $AC$ and $BD$ intersect at $P$.

kvantmathematicsolympiad
Kvant Math Problem 578

Introduce

kvantmathematicsolympiad
Kvant Math Problem 577

Place coordinates on the board by identifying each square with the pair $(i,j)$, where $1\le i,j\le n$.

kvantmathematicsolympiad
Kvant Math Problem 573

Let the lines through $O$ be $l_1,\dots,l_{1979}$.

kvantmathematicsolympiad
Kvant Math Problem 569

Starting from $0$ and $1$, the first new number that can be obtained is $\frac12$, since the mean of $0$ and $1$ is $\frac12$.

kvantmathematicsolympiad
Kvant Math Problem 568

Let

kvantmathematicsolympiad
Kvant Math Problem 564

Let $BC=a$, and place the triangle in coordinates

kvantmathematicsolympiad
CF 338E - Optimize!

We are given two arrays: one long array a of size up to 150,000, and a shorter array b of length up to 150,000 but used as a multiset that we may permute and temporarily “consume”. A threshold value h is also given.

codeforcescompetitive-programmingdata-structures
CF 336A - Vasily the Bear and Triangle

We are given a point at the origin and another point $(x, y)$ that defines a rectangle aligned with the coordinate axes.

codeforcescompetitive-programmingimplementationmath
CF 336C - Vasily the Bear and Sequence

We are given a strictly increasing sequence of positive integers. The task is to choose a subset of these numbers such that the beauty of the subset is maximized.

codeforcescompetitive-programmingbrute-forcegreedyimplementationnumber-theory
Kvant Math Problem 560

For a fixed position of the cover, let $C$ be the convex cover and let $H$ be the hole.

kvantmathematicsolympiad
CF 336E - Vasily the Bear and Painting Square

The problem presents a geometric pattern generated on a coordinate plane and asks for the number of ways to sequentially paint this pattern with a given number of colors. Instead of thinking about coordinates, we can abstract the problem into combinatorial structures.

codeforcescompetitive-programmingbitmaskscombinatoricsdpimplementation
Kvant Math Problem 543

The expression

kvantmathematicsolympiad
CF 336D - Vasily the Bear and Beautiful Strings

We are asked to count binary strings containing exactly n zeros and m ones that can be reduced to a single bit g after applying a sequence of specific "modifications." A modification takes the last two characters of a string and replaces them with a single new character.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 336B - Vasily the Bear and Fly

Vasily has painted two rows of circles on the plane, each row containing m circles of the same radius R. The first row lies on the line y = 0 and the second on y = 2R.

codeforcescompetitive-programmingmath
CF 335C - More Reclamation

We are dealing with a two-column grid of arbitrary height r, where each cell initially represents water. Two cities take turns reclaiming cells to turn them into land, but there is a restriction: reclaiming a cell blocks the three neighboring cells in the opposite column from…

codeforcescompetitive-programminggames
Kvant Math Problem 533

A heptagon has $7$ vertices and $14$ diagonals.

kvantmathematicsolympiad
CF 335B - Palindrome

We are given a single string made of lowercase letters. From this string, we are allowed to delete characters while keeping the remaining characters in order, and we are interested only in the resulting subsequences that are palindromes. The task is twofold.

codeforcescompetitive-programmingconstructive-algorithmsdp
Kvant Math Problem 506

Let $x=a^2,\; y=b^2,\; z=c^2,\; w=d^2$.

kvantmathematicsolympiad
CF 335F - Buy One, Get One Free

We are given a list of pies with positive prices and a store promotion: for each pie you pay full price for, you can take another pie that is strictly cheaper for free. The goal is to determine the minimum total amount you must spend to acquire all pies.

codeforcescompetitive-programmingdpgreedy
CF 335E - Counting Skyscrapers

We are asked to relate two counting schemes over a sequence of randomly sized skyscrapers. Imagine a row of skyscrapers with random heights, where the height of each building follows a geometric distribution with probability $2^{-i}$ for height $i$.

codeforcescompetitive-programmingdpmathprobabilities
CF 335D - Rectangles and Square

We are given a collection of axis-aligned rectangles with integer coordinates, and we are allowed to pick any subset of them.

codeforcescompetitive-programmingbrute-forcedp
CF 335A - Banana

We are asked to help Piegirl buy sheets of stickers to construct a target string s. Each sheet contains exactly n stickers, and all stickers on a sheet are predetermined by the string we choose for that sheet.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedy
Kvant Math Problem 494

Let the square be partitioned into a regular grid of $n \times n$ congruent squares, each of side length $1/n$.

kvantmathematicsolympiad
CF 333A - Secrets

We are asked to analyze a situation with coins of denominations that are powers of three: 1, 3, 9, 27, and so on. A buyer wants to pay an exact amount n but cannot do so because he lacks the right combination of coins.

codeforcescompetitive-programminggreedy
CF 333B - Chips

We are given an $n times n$ grid with some blocked cells. Gerald is allowed to place chips only on the boundary cells, but corners are forbidden starting positions.

codeforcescompetitive-programminggreedy
Kvant Math Problem 493

The expression

kvantmathematicsolympiad
CF 333E - Summer Earnings

We are given a set of candidate points in the plane, and we must choose exactly three of them to serve as centers of three identical circles. All three circles must have the same radius, and they are allowed to touch but not overlap in their interiors.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcegeometrysortings
CF 333D - Characteristics of Rectangles

We are given a rectangular grid of numbers with $n$ rows and $m$ columns. Each cell contains a non-negative integer. The "property" of the table is defined as the minimum value among the four corner cells.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forceimplementationsortings
Kvant Math Problem 484

A dissection of a convex polygon into regular polygons means that every piece is an equilateral triangle, a square, or a regular polygon of higher order, all glued edge-to-edge without overlap.

kvantmathematicsolympiad
CF 333C - Lucky Tickets

We are asked to construct a large collection of 8-digit strings, where each string is a “ticket”. Each ticket is considered valid if it is possible to insert arithmetic operations between its digits and fully parenthesize the resulting expression so that the final value…

codeforcescompetitive-programmingbrute-forceconstructive-algorithms
CF 332B - Maximum Absurdity

We are given a list of numbers placed on a line, where each position represents a law and its value represents how “useful” or “valuable” it is. We must select exactly two contiguous blocks of fixed length k.

codeforcescompetitive-programmingdata-structuresdpimplementation
Kvant Math Problem 477

The sequence is defined by iteration of an integer polynomial $P$ satisfying $P(x)>x$ for all natural $x$.

kvantmathematicsolympiad
CF 332C - Students' Revenge

We are given a collection of orders. From these, we must select exactly $p$ orders that will be enforced. Each chosen order has two effects: if the chairperson complies with it, it contributes some amount of “damage” measured by $ai$, and if she refuses, it causes…

codeforcescompetitive-programmingdata-structuresgreedysortings
CF 332E - Binary Key

We are given a string p, which acts as a container, and a target message s that we want to extract. To do this, we must construct a binary key q of length k.

codeforcescompetitive-programmingdpgreedyimplementation
CF 332D - Theft of Blueprints

We are asked to analyze a network of missile silos connected by underground passages, each guarded by a certain number of droids. The silos form a highly structured network: for any subset of silos of size k, there is exactly one silo connected directly to all of them.

codeforcescompetitive-programminggraphsmath
CF 332A - Down the Hatch!

The game can be thought of as a circle of n players taking turns performing one of two actions, denoted by 'a' for elbow and 'b' for nod. Vasya, at index 0, wants to maximize the number of times he can drink a glass of juice.

codeforcescompetitive-programmingimplementation
CF 331B1 - Shave Beaver!

We are given a permutation of the numbers from 1 to n, but the permutation is not just data, it defines a fixed ordering of “beavers in a line”. Each number appears exactly once, but the position of each value changes over time due to swaps.

codeforcescompetitive-programmingimplementation
Kvant Math Problem 471

Two intersecting circles partition the plane into exactly three bounded regions: the common lens $R_0$, the two asymmetric caps $R_1$ and $R_2$ lying respectively in the first and second circle but ou…

kvantmathematicsolympiad
CF 331A1 - Oh Sweet Beaverette

We are given a linear sequence of trees, each carrying an integer value that represents how aesthetically pleasing that tree is. We are allowed to remove any subset of these trees, keeping the remaining ones in their original order.

codeforcescompetitive-programmingbrute-forceimplementation
CF 331E2 - Deja Vu

The problem gives a directed graph where vertices represent locations and edges represent streets between them. Every street has two pieces of information: where it goes, and a fixed sequence of “visions”, which is just a list of vertices.

codeforcescompetitive-programmingconstructive-algorithmsdp
CF 331E1 - Deja Vu

We are asked to model Neo's “deja vu” experiences as paths in a directed graph. The graph nodes represent shops, and directed edges represent streets. Each edge carries a sequence of visions, which is a list of shop indices that Neo sees when traveling that edge.

codeforcescompetitive-programmingconstructive-algorithmsgraphsimplementation
CF 331D3 - Escaping on Beaveractor

We are asked to simulate the movement of a vehicle, the Beaveractor, inside a square campus. The campus is a grid from (0,0) to (b,b).

codeforcescompetitive-programmingdata-structuresimplementationtrees
Kvant Math Problem 465

A ticket is a length-$k$ word over the alphabet ${0,1,\dots,9}$.

kvantmathematicsolympiad
CF 331D2 - Escaping on Beaveractor

We are asked to simulate the movement of a “Beaveractor” on a square campus of size b×b. The campus contains several arrows that act like teleportation instructions: whenever the Beaveractor reaches an arrow, it immediately changes its direction to match the arrow and…

codeforcescompetitive-programminggraphs
CF 331D1 - Escaping on Beaveractor

We are asked to simulate the motion of a "Beaveractor" on a square campus of size $b times b$. The campus contains a set of directional arrows, each either horizontal or vertical, which force the Beaveractor to change its motion direction when it crosses them.

codeforcescompetitive-programmingdfs-and-similarimplementation
CF 331C3 - The Great Julya Calendar

We are asked to reduce a positive integer to zero by repeatedly subtracting one of its digits. On each step, you must choose any digit that is present in the current number and subtract it. The goal is to minimize the number of subtraction operations needed to reach zero.

codeforcescompetitive-programmingdp
Kvant Math Problem 460

We begin with small values of $n$ to understand the structure.

kvantmathematicsolympiad