brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 346E - Doodle Jump

We are given a sequence of platform heights generated by a modular arithmetic rule. The x-th platform sits at height (a · x) mod p, where a and p are coprime and we only consider the first n such positions.

codeforcescompetitive-programmingmathnumber-theory
CF 346D - Robot Control

We are given a directed graph representing a map a robot can traverse. The robot starts at a vertex s and must reach a target vertex t.

codeforcescompetitive-programmingdpgraphsshortest-paths
CF 346B - Lucky Common Subsequence

We are asked to build a sequence that appears as a subsequence of two given strings while avoiding a third string as a contiguous pattern.

codeforcescompetitive-programmingdpstrings
CF 345G - Suffix Subgroup

We are given a list of strings, and the task is to find the largest possible subset of these strings such that all strings in the subset are suffixes of some single string. In other words, there should exist a string t that ends with every string in our chosen subset.

codeforcescompetitive-programming*specialstrings
Kvant Math Problem 715

The rule replaces one chip by two chips placed one step north and one step east, provided those target cells are empty.

kvantmathematicsolympiad
CF 345B - Triskaidekaphobia

We are given a number $n le 10^5$. For every integer base $b ge 2$, we write $n$ in base $b$, but instead of usual digit symbols we represent each digit as a decimal number and concatenate them without separators.

codeforcescompetitive-programming*special
Kvant Math Problem 687

We model the configuration as follows.

kvantmathematicsolympiad
Kvant Math Problem 659

For the Fibonacci sequence $f_1=1$, $f_2=2$, $f_{k+1}=f_k+f_{k-1}$, the first terms are

kvantmathematicsolympiad
Kvant Math Problem 599

Let $A=4^{5^6}+6^{5^4}$.

kvantmathematicsolympiad
CF 345E - Black Cat Rush

We are moving along a straight line from (0, 0) to (a, 0) at a constant speed v. Around us, there are n black cats, each starting at a point (xi, yi). Each cat can move in any direction at speed at most u.

codeforcescompetitive-programming*special
Kvant Math Problem 580

Let $G$ be the graph whose vertices are parliamentarians and edges represent mutual enmity.

kvantmathematicsolympiad
CF 345D - Chain Letter

We are given a network of people, where every pair of people either knows each other in both directions or does not know each other at all.

codeforcescompetitive-programming*specialdfs-and-similargraphs
Kvant Math Problem 570

Let the squares have side lengths $a_1, a_2, \dots, a_n$, so that

kvantmathematicsolympiad
CF 345A - Expecting Trouble

We are given a string representing Fridays the 13th across some period of time. Each character in the string can be "0" for a normal day, "1" for a particularly bad day, or "?" for a day the user cannot recall.

codeforcescompetitive-programming*specialprobabilities
CF 343A - Rational Resistance

We are asked to construct a resistor network using only unit resistors to achieve a specific rational resistance $frac{a}{b}$.

codeforcescompetitive-programmingmathnumber-theory
Kvant Math Problem 559

Let

kvantmathematicsolympiad
CF 343C - Read Time

We are asked to simulate multiple read heads moving along a linear hard drive to read a set of target tracks as quickly as possible. Each head starts at a given track, can move left, right, or stay in place, and multiple heads can occupy the same track.

codeforcescompetitive-programmingbinary-searchgreedytwo-pointers
Kvant Math Problem 498

Consider small values of $n$.

kvantmathematicsolympiad
CF 343E - Pumping Stations

We are asked to maximize the total amount of water Mike can pump across a network of stations in a sequence of days. Each station is a node in an undirected graph, and pipes between stations are edges with capacities.

codeforcescompetitive-programmingbrute-forcedfs-and-similardivide-and-conquerflowsgraphsgreedytrees
Kvant Math Problem 480

The recurrence is

kvantmathematicsolympiad
CF 343D - Water Tree

We are given a rooted tree where every node behaves like a reservoir that can either contain water or be empty. The root is fixed at node 1, and all edges are directed conceptually away from it.

codeforcescompetitive-programmingdata-structuresdfs-and-similargraphstrees
Kvant Math Problem 467

The triangle is equilateral, so placing it in a coordinate system with one side horizontal allows algebraic control over all distances and angles.

kvantmathematicsolympiad
CF 343B - Alternating Current

We are given a sequence that describes how two wires, one called “plus” and the other “minus”, overlap as they run from the left side to the right side of a device. At each position along the path, exactly one of the wires is physically above the other.

codeforcescompetitive-programmingdata-structuresgreedyimplementation
Kvant Math Problem 448

Let the quadrilateral have diagonals intersecting at a point $O$.

kvantmathematicsolympiad
CF 342C - Cupboard and Balloons

The task is to determine how many spherical balloons of radius 1 can fit inside a cupboard shaped like a semicircle on top of a rectangle. The cupboard has a semicircular top with radius r and vertical walls of height h, forming a depth also equal to r.

codeforcescompetitive-programminggeometry
Kvant Math Problem 420

The allowed operations on a fraction $\frac{a}{b}$ replace the integer pair $(a,b)$ by one of $(a-b,b)$, $(a+b,b)$, or $(b,a)$.

kvantmathematicsolympiad
CF 342B - Xenia and Spies

A note starts at one spy positioned at index s in a line of n spies. The note must eventually reach another spy at position f.

codeforcescompetitive-programmingbrute-forcegreedyimplementation
Kvant Math Problem 402

From the condition with $n=m=1$ we obtain

kvantmathematicsolympiad
Kvant Math Problem 367

For three consecutive natural numbers $n, n+1, n+2$, the key structural feature is that any two of them are coprime.

kvantmathematicsolympiad
CF 342E - Xenia and Tree

We are working with a tree where every node represents a point in a connected acyclic graph. Initially only node 1 is colored red, while every other node starts blue. Over time, we perform two kinds of operations.

codeforcescompetitive-programmingdata-structuresdivide-and-conquertrees
Kvant Math Problem 243

Let the two given lines be denoted $l_1$ and $l_2$.

kvantmathematicsolympiad
CF 342D - Xenia and Dominoes

We are given a 3×n grid representing a puzzle board. Each cell can be forbidden, free, or marked with a special circle. Dominoes, which are 1×2 or 2×1 tiles, must be placed to cover exactly two non-forbidden cells.

codeforcescompetitive-programmingbitmasksdfs-and-similardp
CF 342A - Xenia and Divisors

We are given a sequence of positive integers, all between 1 and 7, and the length of the sequence is divisible by three.

codeforcescompetitive-programminggreedyimplementation
Kvant Math Problem 196

Work in the unit circle centered at $O$.

kvantmathematicsolympiad
CF 341D - Iahub and Xors

We are given an $n times n$ matrix initially filled with zeros. The problem asks us to handle two types of operations efficiently: one that computes the xor of all elements inside a submatrix, and another that xors a given value into every element of a submatrix.

codeforcescompetitive-programmingdata-structures
CF 341E - Candies Game

We are given a set of boxes, each containing some number of candies. The objective is to redistribute candies such that exactly two boxes contain all the candies, and every other box is empty.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 340B - Maximal Area Quadrilateral

We are given a set of $n$ points in the 2D Cartesian plane, and we are asked to select four of these points to form a quadrilateral with the maximal area. The quadrilateral does not need to be convex, but it must have four vertices from the given points and cannot self-intersect.

codeforcescompetitive-programmingbrute-forcegeometry
CF 340C - Tourist Problem

We have several destinations located on a straight line at positions $a1,a2,dots,an$, all strictly positive and distinct. A route is simply a permutation of these destinations.

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