brain

tamnd's digital brain — notes, problems, research

41777 notes

CF 331C2 - The Great Julya Calendar

We are given a positive integer n representing a "magic number" from the Julya calendar. The Smart Beaver can reduce n to zero by repeatedly subtracting one of its digits. For instance, if n = 24, the Beaver could subtract 2 or 4, producing 22 or 20 respectively.

codeforcescompetitive-programmingdp
CF 331C1 - The Great Julya Calendar

We start with a non-negative integer n. In one operation, we look at the decimal representation of the current number, choose any digit that appears in it, and subtract that digit from the number.

codeforcescompetitive-programmingdp
CF 331B2 - Shave Beaver!

We are given a permutation of n beavers, each with a unique ID from 1 to n. A high-tech machine can shave beavers in consecutive ID intervals, but only if the permutation contains all IDs in that interval in increasing order, not necessarily consecutively in positions.

codeforcescompetitive-programmingdata-structures
CF 331A2 - Oh Sweet Beaverette

We are given a linear sequence of trees, each with an integer esthetic appeal. The task is to remove some trees so that three conditions hold. First, the sum of the remaining trees' appeals is maximized.

codeforcescompetitive-programmingdata-structuressortings
CF 330A - Cakeminator

We are given a small rectangular grid representing a cake. Each cell is either an ordinary cake cell (.) or contains a strawberry (S).

codeforcescompetitive-programmingbrute-forceimplementation
Kvant Math Problem 453

Let $S$ be a subset of ${a_1,\dots,a_n}$ and write $s(S)$ for its sum.

kvantmathematicsolympiad
CF 330B - Road Construction

We have a graph with n cities and no roads initially. Some pairs of cities are forbidden, meaning we are not allowed to build a road directly between them. We must add the smallest possible number of roads so that two conditions hold.

codeforcescompetitive-programmingconstructive-algorithmsgraphs
CF 329B - Biridian Forest

We are given a rectangular grid representing the forest. Some cells are blocked by trees, one cell contains our starting position S, one cell contains the exit E, and some cells contain digits. A digit cell represents that many other breeders standing there initially.

codeforcescompetitive-programmingdfs-and-similarshortest-paths
Kvant Math Problem 442

For small primes the structure is very rigid.

kvantmathematicsolympiad
CF 329C - Graph Reconstruction

The original graph is very restricted. Every vertex has degree at most two, which means every connected component is either a simple path or a simple cycle. We must build another graph on the same set of vertices.

codeforcescompetitive-programmingconstructive-algorithms
Kvant Math Problem 433

The configuration imposes five independent parallelism relations between each side of a convex pentagon and a diagonal.

kvantmathematicsolympiad
CF 329D - The Evil Temple and the Moving Rocks

We are asked to design a placement of rocks on an n × n grid such that activating a single rock produces at least x sounds. Each rock has a fixed movement direction - up, down, left, or right - and rocks move until they hit either a wall or another rock.

codeforcescompetitive-programmingconstructive-algorithms
Kvant Math Problem 429

Write $x=n+t$ with $n=[x]\in\mathbb{Z}$ and $t={x}\in[0,1)$.

kvantmathematicsolympiad
CF 329A - Purification

We have an n × n grid. Some cells are usable (.), while some cells are forbidden (E). A spell may only be cast on a usable cell. When we cast a spell on cell (r, c), every cell in row r and every cell in column c becomes purified.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 327B - Hungry Sequence

We need to construct an increasing sequence of n positive integers such that no later element is divisible by any earlier element. The input contains a single number n. We must output any sequence of length n satisfying two conditions.

codeforcescompetitive-programmingmath
Kvant Math Problem 424

Let $ABCD$ be a tetrahedron.

kvantmathematicsolympiad
CF 327C - Magic Five

We are given a digit string a and an integer k. The actual plate is not a itself, but the string obtained by concatenating a with itself k times. From this long string, we may delete any subset of positions, except that we are not allowed to delete every digit.

codeforcescompetitive-programmingcombinatoricsmath
CF 327E - Axis Walking

We have n positive segment lengths. Their total sum is d, which is also the destination point on the number line. A route is simply an ordering of these lengths. While following a route, we keep a running prefix sum.

codeforcescompetitive-programmingbitmaskscombinatoricsconstructive-algorithmsdpmeet-in-the-middle
CF 327D - Block Tower

We are given a 2D grid with n rows and m columns. Each cell is either empty, where we can place a tower, or a hole, where no tower can be built.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphs
CF 327A - Flipping Game

We are given a binary array, every element is either 0 or 1. We must choose exactly one contiguous segment and flip every value inside it. A flip changes 0 to 1 and 1 to 0. After performing this single operation, we want the resulting array to contain as many ones as possible.

codeforcescompetitive-programmingbrute-forcedpimplementation
Kvant Math Problem 417

The object is a closed polygonal line drawn on the surface of a unit cube, with the condition that every face of the cube contains at least one entire segment of the polygonal line.

kvantmathematicsolympiad
CF 325D - Reclamation

We are asked to simulate a process of turning cells in a cylindrical grid from sea into land, one by one, while ensuring that a sea path connecting the top row to the bottom row always exists.

codeforcescompetitive-programmingdsu
Kvant Math Problem 409

The transformation replaces each entry in a row by the frequency of that value in the same row.

kvantmathematicsolympiad
CF 325B - Stadium and Games

We are given the exact number of football games that must be played, and we need to find every possible initial number of teams that produces exactly that many games under a specific tournament format.

codeforcescompetitive-programmingbinary-searchmath
Kvant Math Problem 406

Let the circle have center $O$ and radius $R$.

kvantmathematicsolympiad
Kvant Math Problem 401

Let $A,B,C$ be the angles of $\triangle ABC$.

kvantmathematicsolympiad
Kvant Math Problem 392

Let the positions of the three pedestrians at time $t$ be represented by vectors $A(t), B(t), C(t)$ in the plane.

kvantmathematicsolympiad
Kvant Math Problem 373

An infinite decimal expansion determines an infinite sequence of digits, hence an infinite word over the alphabet ${0,1,\dots,9}$.

kvantmathematicsolympiad
Kvant Math Problem 366

Assume such a configuration exists and consider the finite set of triangles.

kvantmathematicsolympiad
Kvant Math Problem 346

Place the square in a coordinate system with algebraic convenience so that perpendicularity can be tested by a dot product condition.

kvantmathematicsolympiad
Kvant Math Problem 330

Let $M_0$ and $M_1$ be convex polygons.

kvantmathematicsolympiad
Kvant Math Problem 322

Each circle contributes boundary pieces only where it is the lowest among the $N$ radii in some direction, since the intersection of disks can be described as the set of points satisfying $d(x,O_i)\le…

kvantmathematicsolympiad
Kvant Math Problem 315

Each edge of the convex polyhedron is oriented, so the 1-skeleton becomes an orientation of a connected planar graph embedded on the sphere.

kvantmathematicsolympiad
Kvant Math Problem 312

The outer parallelogram $P_1$ admits an affine normalization to a unit square without changing incidence relations such as “lying on a side” and “being parallel to fixed directions.

kvantmathematicsolympiad
Kvant Math Problem 310

An $n$-digit number is a sequence of digits $d_1d_2\ldots d_n$ where $d_1 \in {1,\dots,9}$ and $d_i \in {0,\dots,9}$ for $i \ge 2$.

kvantmathematicsolympiad
Kvant Math Problem 302

Let $O = AC \cap BD$ in the trapezoid $ABCD$ with $AB \parallel CD$.

kvantmathematicsolympiad
Kvant Math Problem 300

We are given a finite or otherwise fixed collection of forbidden words over the alphabet ${a,b,c}$, each forbidden word having length at least $2$, and all forbidden words having pairwise distinct len…

kvantmathematicsolympiad
Kvant Math Problem 293

Let $\gamma_n = \angle C_{n+1} C_n O$.

kvantmathematicsolympiad
Kvant Math Problem 291

Let the triangle have vertices $A_1,A_2,A_3$.

kvantmathematicsolympiad
Kvant Math Problem 289

Let the total weight be $S$, and suppose the $N$ weights are partitioned into $K$ piles each of sum $T$, so $S = KT$.

kvantmathematicsolympiad
Kvant Math Problem 281

Consider small convex polygons whose diagonals are defined as segments joining non-adjacent vertices.

kvantmathematicsolympiad
Kvant Math Problem 278

The configuration involves a convex hexagon with side lengths bounded below or above and three “long” diagonals connecting every second vertex.

kvantmathematicsolympiad
Kvant Math Problem 271

For small values, direct checking clarifies the constraint.

kvantmathematicsolympiad
Kvant Math Problem 268

The game is played on the graph of an $n\times n$ chessboard, where vertices are squares and edges correspond to standard knight moves $(\pm2,\pm1)$ and $(\pm1,\pm2)$.

kvantmathematicsolympiad
Kvant Math Problem 266

Consider the circle through three consecutive vertices $A_{i-1},A_i,A_{i+1}$.

kvantmathematicsolympiad
Kvant Math Problem 255

Let the centers of the spheres be $O_1$ and $O_2$, with radii $R_1$ and $R_2$.

kvantmathematicsolympiad
Kvant Math Problem 253

Let the given points be $O$, $I$, and $I_a$, where $O$ is the circumcenter, $I$ the incenter, and $I_a$ one of the excenters of triangle $ABC$.

kvantmathematicsolympiad
Kvant Math Problem 251

The condition says no color appears more than $\frac{n}{2}$ times.

kvantmathematicsolympiad
Kvant Math Problem 246

Let the triangle be $ABC$ with circumcenter $O$.

kvantmathematicsolympiad
Kvant Math Problem 232

For a triple of points $A,B,C$, the condition that the triangle is obtuse means that one of the three angles exceeds $90^\circ$, equivalently one of the three opposite-side inequalities of the form

kvantmathematicsolympiad
Kvant Math Problem 227

Let the parallelogram be mapped by an affine transformation to the unit square, since affine maps preserve parallelism, ratios of areas, and the condition of a point lying on a segment.

kvantmathematicsolympiad
Kvant Math Problem 219

Let the four points be $A,B,C,D$ in space, not lying in one plane.

kvantmathematicsolympiad
Kvant Math Problem 216

We interpret the situation as a simple undirected graph on $N$ vertices, where each vertex represents a person and each edge represents a mutual acquaintance.

kvantmathematicsolympiad
Kvant Math Problem 214

Let $f(x)=ax^{2}+bx+c$ and assume the equation $f(x)=x$ has no real roots.

kvantmathematicsolympiad
Kvant Math Problem 206

Let the digits of the infinite sequence be $a_1,a_2,a_3,\dots$, where each $a_i \in {0,1,\dots,9}$.

kvantmathematicsolympiad
Kvant Math Problem 203

Let $ABCD$ be a cyclic quadrilateral with diagonals $AC$ and $BD$ intersecting at $P$.

kvantmathematicsolympiad
Kvant Math Problem 191

Let $A$ and $B$ be fixed, and let $l$ be a fixed line through $A$ not containing $B$.

kvantmathematicsolympiad
Kvant Math Problem 184

The expression is a finite alternating sum of simple fractions with shifts in the denominator.

kvantmathematicsolympiad
Kvant Math Problem 181

The wire must be bent into the full frame of a cube of side $10$, which is the 1-skeleton of a cube graph with $8$ vertices and $12$ edges, each of length $10$.

kvantmathematicsolympiad
Kvant Math Problem 178

Let $A$ be the vertex of the angle whose bisector contains $P$.

kvantmathematicsolympiad
Kvant Math Problem 171

A regular hexagon of side length $1$ provides three natural directions of equal unit segments forming angles of $60^\circ$.

kvantmathematicsolympiad
Kvant Math Problem 169

Each row contains $n$ numbers arranged increasingly, so the $k$-th column consists of the $k$-th smallest element in each row.

kvantmathematicsolympiad
Kvant Math Problem 166

Let $A_1$ and $A_2$ be the sets of participants of the two trips, and let $B_i \subset A_i$ be the boys in the $i$-th trip.

kvantmathematicsolympiad
Kvant Math Problem 157

Let

kvantmathematicsolympiad
CF 325E - The Red Button

We are asked to find a sequence of node disarmaments for a circular system of size n where node 0 is special. Node 0 must appear twice: first at the start and last at the end. Every other node must appear exactly once.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardsugraphsgreedy
CF 325C - Monsters and Diamonds

Each monster type has one or more split rules. Applying a rule consumes one monster of that type and produces two things: First, some number of diamonds. Second, a multiset of new monsters.

codeforcescompetitive-programmingdfs-and-similargraphsshortest-paths
CF 323C - Two permutations

Each value from 1 to n appears exactly once in both permutations. For a value v, let: - posP[v] be its position in the first permutation. - posQ[v] be its position in the second permutation.

codeforcescompetitive-programmingdata-structures
CF 323B - Tournament-graph

We are asked to construct a tournament graph of n vertices with a specific connectivity property. A tournament graph is a directed graph where every pair of distinct vertices has exactly one directed edge between them.

codeforcescompetitive-programmingconstructive-algorithmsgraphs
CF 323A - Black-and-White Cube

We are asked to color every small cube inside a larger cube of size k × k × k using exactly two colors, black and white, with a specific local neighbor condition. Each small cube must have exactly two neighboring cubes of the same color.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithms
CF 322A - Ciel and Dancing

The task describes a dancing room where every performance involves exactly one boy and exactly one girl. The participants start with no prior experience, and during each dance at least one of the two people must be dancing for the first time.

codeforcescompetitive-programminggreedy
CF 322B - Ciel and Flowers

We are given three independent supplies of items, each representing flowers of a fixed color. From these supplies we can form bouquets in two fundamentally different ways.

codeforcescompetitive-programmingcombinatoricsmath
CF 321B - Ciel and Duel

We are given two sets of cards, one belonging to Jiro and one belonging to Ciel. Jiro’s cards come in two types, Attack and Defense, each with a strength value. Ciel’s cards are simpler: every one of her cards is an Attack card with a given strength.

codeforcescompetitive-programmingdpflowsgreedy
CF 321C - Ciel the Commander

We are given a tree with up to 100,000 nodes, and we must assign each node a letter from 'A' to 'Z'. These letters represent ranks, where 'A' is the strongest and 'Z' is the weakest.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardivide-and-conquergreedytrees
CF 321E - Ciel and Gondolas

We are given a line of people from position 1 to position n, and we must split this line into exactly k contiguous groups. Each group corresponds to a gondola ride and contains consecutive people in the queue.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdp
CF 321D - Ciel and Flipboard

We have a square board of size n by n, where n is always an odd number. Each cell contains an integer, which may be positive or negative.

codeforcescompetitive-programmingdpgreedymath
CF 321A - Ciel and Robot

We are asked to determine whether a robot moving on a 2D plane can reach a target point (a, b). The robot starts at the origin (0, 0) and follows a sequence of moves encoded in a string.

codeforcescompetitive-programmingbinary-searchimplementationmath
CF 320A - Magic Numbers

We are given a single integer written in decimal form, and we must decide whether it can be constructed by repeatedly placing one of three fixed building blocks next to each other: 1, 14, and 144.

codeforcescompetitive-programmingbrute-forcegreedy
CF 320B - Ping-Pong (Easy Version)

We are maintaining a growing collection of open intervals on the number line. Each time a new interval is added, it becomes a node in an implicit directed graph.

codeforcescompetitive-programmingdfs-and-similargraphs
CF 319A - Malek Dance Club

We are given a binary string that we interpret as an integer, and from it we construct a fixed pairing between two ordered sets of size $2^n$.

codeforcescompetitive-programmingcombinatoricsmath
CF 319C - Kalila and Dimna in the Logging Industry

We are given a sequence of trees with strictly increasing heights. Each tree can be cut down one unit at a time using a chainsaw. The chainsaw requires recharging after each cut, and the recharge cost depends on which trees have already been fully cut.

codeforcescompetitive-programmingdpgeometry
CF 319E - Ping-Pong

We are asked to maintain a dynamic set of intervals and answer reachability queries between them. Each interval is represented by two integers $(x, y)$ where $x < y$. Intervals are added one by one, and each new interval is guaranteed to be strictly longer than all previous ones.

codeforcescompetitive-programmingdata-structures
CF 319D - Have You Ever Heard About the Word?

We are given a single string and we repeatedly compress certain patterns inside it. The only pattern that matters is a substring that consists of two identical halves placed back to back, so a segment of the form X + X, where X is any non-empty string.

codeforcescompetitive-programminggreedyhashingstring-suffix-structuresstrings
CF 319B - Psychos in a Line

We are given a permutation of the numbers from 1 to n arranged in a line. Each position represents a “psycho” with a unique strength value, and the line evolves in discrete rounds. In one round, every psycho compares himself with the person immediately to his right.

codeforcescompetitive-programmingdata-structuresimplementation
CF 317B - Ants

We are asked to simulate the dispersal of ants on a two-dimensional integer grid. Initially, all n ants are placed at the origin (0, 0).

codeforcescompetitive-programmingbrute-forceimplementation
CF 317C - Balance

We are given a set of n vessels, each capable of holding up to v liters of water. Some vessels are connected by tubes that allow water to be transferred in integer amounts.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphstrees
CF 317E - Princess and Her Shadow

We have a two-dimensional integer grid representing a forest. Each cell can be empty or contain a tree. The Princess starts at a cell (vx, vy) and her Shadow starts at (sx, sy).

codeforcescompetitive-programmingconstructive-algorithmsshortest-paths
CF 317D - Game with Powers

We are given a set of integers from 1 to n. Two players alternate turns, and each move consists of selecting a number that has not been eliminated yet.

codeforcescompetitive-programmingdpgames
CF 317A - Perfect Pair

We are given two integers, $x$ and $y$, and a target threshold $m$. A pair is considered m-perfect if at least one of the two numbers is greater than or equal to $m$.

codeforcescompetitive-programmingbrute-force
CF 316A1 - Special Task

The problem asks us to count how many numeric codes match a hint string that can contain fixed digits, wildcards, and letters representing digit equality constraints. Each character in the hint string represents a position in the safe code. A question mark ?

codeforcescompetitive-programminggreedy
CF 316G3 - Good Substrings

We are given a main string $s$ and several constraints, each constraint consists of a pattern string $p$ and a numeric interval $[l, r]$.

codeforcescompetitive-programmingstring-suffix-structures
CF 316G1 - Good Substrings

We are asked to count the number of distinct substrings of a string s that satisfy a set of occurrence-based rules.

codeforcescompetitive-programminghashingstrings
CF 316F3 - Suns and Rays

The task is to analyze a binary image where 0 represents the background and 1 represents a sun or its rays. Each sun consists of a central ellipse (which may be rotated) and several rays extending outward as line segments from the ellipse’s boundary.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similarimplementation
CF 316F2 - Suns and Rays

The input is a pixel grid made of two values, where one value represents empty background and the other represents ink belonging to drawn objects.

codeforcescompetitive-programming
CF 316E3 - Summer Homework

We are maintaining an array that changes over time through point updates and range updates, while also answering range queries.

codeforcescompetitive-programmingdata-structuresmath
CF 316E1 - Summer Homework

We are given an array of integers, and we need to process a sequence of operations that modify the array or query it in a special way. There are three types of operations: direct assignment of a value to an element, range sums weighted by Fibonacci numbers, and range increments.

codeforcescompetitive-programmingbrute-forcedata-structures
CF 316D3 - PE Lesson

We are given a line of students, each initially holding a distinct labeled ball from 1 to n. The only operation allowed is choosing two different students and swapping the balls they currently hold.

codeforcescompetitive-programmingdpmath
CF 316D2 - PE Lesson

We are given a line of students, each initially holding a distinct labeled ball. The only operation allowed is to pick two students and swap the balls they currently hold.

codeforcescompetitive-programmingdp
CF 316B2 - EKG

We are given a queue of n beavers, each numbered from 1 to n. Each beaver either knows who should be immediately in front of them, represented as a[i] (the number of that beaver), or does not know, represented as 0.

codeforcescompetitive-programmingdfs-and-similardp
CF 316B1 - EKG

We are given a structure of people standing in a queue, but the queue is not fully known. Each person either clearly knows who stands immediately in front of them or does not know that information at all.

codeforcescompetitive-programmingbrute-forcedfs-and-similar
CF 315B - Sereja and Array

We have an array of integers and a sequence of operations. One operation changes a single position to a new value. Another operation adds the same number to every element in the array. The third operation asks for the current value at a specific position.

codeforcescompetitive-programmingimplementation