brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 464D - World of Darkraft - 2

Working

codeforcescompetitive-programmingdpprobabilities
CF 464A - No to Palindromes!

We are given a string s of length n consisting of lowercase letters, and an integer p representing the number of allowed letters from the start of the alphabet, that is, 'a' through chr(ord('a') + p - 1).

codeforcescompetitive-programminggreedystrings
CF 464C - Substitutes in Number

We start with a decimal string s. Then a sequence of replacement rules is applied in order. Each rule has the form d - t, meaning every occurrence of digit d is replaced by the string t.

codeforcescompetitive-programmingdp
CF 452F - Permutation

We are given a permutation of the numbers 1...n. For two distinct values a and b, their average is (a+b)/2. Since the permutation contains every integer exactly once, this average is also present whenever a+b is even.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerhashing
CF 452D - Washer, Dryer, Folder

We have a three-stage production pipeline. Every laundry item must first be washed, then immediately transferred to a dryer when washing finishes, then immediately transferred to a folding machine when drying finishes.

codeforcescompetitive-programminggreedyimplementation
CF 448E - Divisors

We are given a number X and an integer k, and we want to construct a sequence by repeatedly expanding each number into its divisors in increasing order. Formally, we define X0 as a sequence containing just X.

codeforcescompetitive-programmingbrute-forcedfs-and-similarimplementationnumber-theory
CF 448B - Suffix Structures

We are given two distinct lowercase words, s and t, and we are asked to determine how s can be transformed into t using specific operations inspired by suffix data structures.

codeforcescompetitive-programmingimplementationstrings
CF 448C - Painting Fence

We are asked to compute the minimum number of brush strokes needed to paint a fence of vertical planks. Each plank has a width of 1 meter and an individual height. The brush is exactly 1 meter wide, and it can be applied either vertically or horizontally.

codeforcescompetitive-programmingdivide-and-conquerdpgreedy
CF 447A - DZY Loves Hash

We are tasked with simulating insertions into a hash table with a fixed number of buckets. Each bucket can hold at most one element. The hash function is simple: for a number $x$, the target bucket is $x mod p$. We receive a sequence of numbers and must insert them in order.

codeforcescompetitive-programmingimplementation
Kvant Math Problem 2885

Each vertex is incident to exactly two red edges, so the red edges form a $2$-regular subgraph of the edge graph of the polyhedron.

kvantmathematicsolympiad
CF 446A - DZY Loves Sequences

We are given an array of up to $10^5$ integers. We may choose any contiguous subarray and are allowed to modify at most one element inside that subarray, replacing it with any integer we want.

codeforcescompetitive-programmingdpimplementationtwo-pointers
CF 446B - DZY Loves Modification

We have an n × m matrix of integers. We must perform exactly k operations. An operation chooses either an entire row or an entire column. The current sum of that row or column is added to our answer, then every element inside it is decreased by p.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedy
CF 445B - DZY Loves Chemistry

The chemicals and reactions form an undirected graph. Each vertex represents a chemical, and an edge between two vertices means those two chemicals react. We start with danger equal to 1. Chemicals are poured one at a time in any order.

codeforcescompetitive-programmingdfs-and-similardsugreedy
Kvant Math Problem 2876

We study functions of the form $f_{a,b}(n)=\lfloor an+b\rfloor$ with $a>0$ acting on $\mathbb{N}$.

kvantmathematicsolympiad
CF 444E - DZY Loves Planting

We are given a tree with n nodes, where each edge has a positive weight. For any two nodes x and y, the function g(x, y) is defined as the maximum weight along the unique path connecting them.

codeforcescompetitive-programmingbinary-searchdsutrees
CF 444C - DZY Loves Colors

We have a ribbon consisting of positions 1...n. Initially, position i has color i, so every position starts with a distinct color. Two kinds of operations are performed. A paint operation assigns a new color x to every position in a segment [l, r].

codeforcescompetitive-programmingdata-structures
CF 444B - DZY Loves FFT

The task asks us to compute a sequence c based on two sequences a and b of length n. Sequence a is a permutation of the integers from 1 to n, and b is a binary sequence with exactly d ones, both shuffled in a pseudo-random but reproducible way.

codeforcescompetitive-programmingprobabilities
CF 443B - Kolya and Tandem Repeat

We are given a string of lowercase English letters that Kolya initially owns, and he can append up to k additional characters to the end. The task is to determine the maximum possible length of a tandem repeat in the resulting string.

codeforcescompetitive-programmingbrute-forceimplementationstrings
CF 442D - Adam and Tree

The tree starts with a single root vertex. Each operation adds one new leaf to an existing vertex. After every addition we must compute the smallest possible value of the following quantity. We color the edges of the tree.

codeforcescompetitive-programmingdata-structurestrees
CF 442C - Artem and Array

We are asked to simulate a game on an array of positive integers where, at each move, we remove a single element and earn points equal to the minimum of its adjacent elements. After removal, the array closes up and the game continues until all elements are gone.

codeforcescompetitive-programmingdata-structuresgreedy
CF 442E - Gena and Second Distance

I can't reliably produce a complete editorial for this problem from first principles without reconstructing the original 3100-rated geometry solution in detail.

codeforcescompetitive-programminggeometry
Kvant Math Problem 2863

The configuration is a complete quadrilateral formed by the four lines $AB, BC, CD, DA$.

kvantmathematicsolympiad
CF 437C - The Child and Toy

We are given a toy made up of n parts connected by m ropes. Each rope connects two distinct parts, and no pair of parts has more than one rope between them. Each part i has an associated energy cost v[i]. The child removes parts one at a time.

codeforcescompetitive-programminggraphsgreedysortings
CF 345F - Superstitions Inspection

The input is not given in the usual structured format with counts. Instead, it is a small text file that alternates between country names and lists of superstitions. A line that does not start with is a country name.

codeforcescompetitive-programming*special
CF 345C - Counting Fridays

We are given a small list of contest dates. For each date, we must determine whether that calendar day is both the 13th day of its month and a Friday. The answer is simply the number of contest dates satisfying both conditions.

codeforcescompetitive-programming*special
Kvant Math Problem 2854

Let $n=\prod p_i^{\alpha_i}$ with all $p_i<100$.

kvantmathematicsolympiad
Kvant Math Problem 2830

Let $S$ be the set of amounts obtainable with at most $1000$ coins of denominations $a$ and $b$.

kvantmathematicsolympiad
Kvant Math Problem 2786

Let the value of a completed coloring be the number of edges of the 100-cycle whose endpoints have different colors.

kvantmathematicsolympiad
Kvant Math Problem 1580

The problem asks whether a circle can be dissected into finitely many pieces whose boundaries consist of line segments and circular arcs, and then reassembled into a square of the same area.

kvantmathematicsolympiad
Kvant Math Problem 1561

Let the convex polygon be $A_1A_2\ldots A_n$, indexed cyclically.

kvantmathematicsolympiad
Kvant Math Problem 1531

Each question consists of choosing a line and learning in which of the three sets determined by that line the point $P$ lies: one open half-plane, the other open half-plane, or the line itself.

kvantmathematicsolympiad
Kvant Math Problem 1503

Let $B$ be the set of black numbers and $W$ the set of white numbers.

kvantmathematicsolympiad
Kvant Math Problem 1483

Each vector lies in the first quadrant and has length $1$.

kvantmathematicsolympiad
Kvant Math Problem 1467

Let

kvantmathematicsolympiad
Kvant Math Problem 957

Each allowed integer has the form

kvantmathematicsolympiad
Kvant Math Problem 902

Suppose the partition consists of finitely many arithmetic progressions

kvantmathematicsolympiad
Kvant Math Problem 857

A number is marked if it can be written as a sum of exactly five powers of two, repetitions allowed.

kvantmathematicsolympiad
Kvant Math Problem 806

Let

kvantmathematicsolympiad
Kvant Math Problem 736

The statement involves a median and an angle bisector meeting at a point.

kvantmathematicsolympiad
Kvant Math Problem 697

Let the square have side length $1$.

kvantmathematicsolympiad
Kvant Math Problem 596

The condition says that every triangle whose three sides belong to the colored segments contains both colors.

kvantmathematicsolympiad
Kvant Math Problem 567

Take a small example, say $p=2$, $q=3$.

kvantmathematicsolympiad
Kvant Math Problem 490

Let the given integers be $a_1,\dots,a_{p-1}$, none divisible by $p$.

kvantmathematicsolympiad
Kvant Math Problem 437

Let the odd number be

kvantmathematicsolympiad
Kvant Math Problem 194

Take a small example, say $a=3$, $b=7$.

kvantmathematicsolympiad
Kvant Math Problem 1566

Each committee has $80$ members, and there are $16000$ committees.

kvantmathematicsolympiad
Kvant Math Problem 1529

The equalities

kvantmathematicsolympiad
Kvant Math Problem 1515

Let

kvantmathematicsolympiad
Kvant Math Problem 1470

We need a set $A$ of positive integers such that every infinite set $S$ of primes contains, among the squarefree numbers formed from distinct primes of $S$, two numbers with the same number $k\ge2$ of…

kvantmathematicsolympiad
Kvant Math Problem 916

Let the acute triangle be $ABC$.

kvantmathematicsolympiad
Kvant Math Problem 817

Let

kvantmathematicsolympiad
Kvant Math Problem 790

The hypothesis is that a map $F:\mathbb{R}^2\to\mathbb{R}^2$ preserves unit distance, meaning every pair of points at distance $1$ is mapped to a pair of points at distance $1$.

kvantmathematicsolympiad
Kvant Math Problem 754

The expression

kvantmathematicsolympiad
Kvant Math Problem 723

We seek an infinite set $S \subset \mathbb{N}$ such that no element of $S$ and no finite sum of distinct elements of $S$ is a perfect power $a^k$ with $k \ge 2$.

kvantmathematicsolympiad
Kvant Math Problem 684

Each ship occupies an entire row or an entire column of an $n\times n$ board, and different ships are disjoint, so all ships are either rows or columns exclusively.

kvantmathematicsolympiad
Kvant Math Problem 651

Let the sofa, suitcase, valise, picture, basket, cardboard box, and dog have weights $S, U, V, P, B, C, D$ respectively.

kvantmathematicsolympiad
Kvant Math Problem 581

The first question asks for a three-digit integer $x$ such that $x^3$ ends in $777$, equivalently

kvantmathematicsolympiad
Kvant Math Problem 566

Let the fixed isosceles right triangle be placed as a unit right isosceles triangle with vertices $A(0,0)$, $B(1,0)$, $C(0,1)$.

kvantmathematicsolympiad
Kvant Math Problem 508

The three semicircles with diameters $AB$, $BC$, $AC$ lie on the same line $AB$, with centers at the midpoints of $AB$, $BC$, and $AC$.

kvantmathematicsolympiad
Kvant Math Problem 489

The transformation replaces each term by the average of the other two.

kvantmathematicsolympiad
Kvant Math Problem 462

Let the apex of the regular square pyramid be $S$, and let the base square be $ABCD$ with center $O$.

kvantmathematicsolympiad
Kvant Math Problem 435

Let $A=(a_{ij})$ be an $m\times n$ matrix.

kvantmathematicsolympiad
Kvant Math Problem 395

Label the vertices of a regular $n$-gon by $0,1,\dots,n-1$ in cyclic order.

kvantmathematicsolympiad
Kvant Math Problem 364

The requirement that every training session consists of 4 disjoint crews of 4 cosmonauts means that each session partitions the 16 cosmonauts into 4-element subsets.

kvantmathematicsolympiad
Kvant Math Problem 162

Let $A={a_1<a_2<a_3<\cdots}$.

kvantmathematicsolympiad
Kvant Math Problem 452

Let $ABC$ be the triangle $T_1$ inscribed in a circle with center $O$.

kvantmathematicsolympiad
Kvant Math Problem 415

The problem asks for the maximum number of mutually non-attacking kings on an $n\times n$ toroidal board.

kvantmathematicsolympiad
Kvant Math Problem 399

For a set of points on a segment, the condition “there exist two points at distance $m$” is equivalent to requiring that the difference set of all chosen coordinates contains every integer $1,2,\dots,…

kvantmathematicsolympiad
Kvant Math Problem 333

Let the flies be at positions $P(t),Q(t),R(t)$ on the sides of triangle $ABC$.

kvantmathematicsolympiad
Kvant Math Problem 12

A straight line intersects a convex quadrilateral in two points.

kvantmathematicsolympiad
Kvant Math Problem 951

Let the hexagon be $ABCDEF$ in convex order with $AB=BC=CD=DE=EF=FA=1$.

kvantmathematicsolympiad
Kvant Math Problem 930

We are asked to prove that in any partition of the integers from $1$ to $1985$ into six classes, one class must contain either a triple $a,b,c$ with $a+b=c$ or a pair $a,2a$.

kvantmathematicsolympiad
Kvant Math Problem 895

Place the cube of side $2$ in coordinates with center at the origin, so its vertices are $(\pm1,\pm1,\pm1)$ and its inscribed sphere is $x^2+y^2+z^2=1$.

kvantmathematicsolympiad
Kvant Math Problem 871

We encode each entry $x_{i,j}\in{\pm1}$ by $a_{i,j}\in\mathbb{F}_2$ via $x_{i,j}=(-1)^{a_{i,j}}$.

kvantmathematicsolympiad
Kvant Math Problem 847

The game is played on the edge set of the $n\times n$ square grid graph.

kvantmathematicsolympiad
Kvant Math Problem 828

Consider a function $a_{i,j}$ on the integer lattice.

kvantmathematicsolympiad
Kvant Math Problem 797

We interpret the problem as asking whether, for every fixed block of $n$ decimal digits $A=a_1a_2\ldots a_n$, there exists an integer $x$ such that the last $n+1$ digits of $x^2$ have the form $A b$,…

kvantmathematicsolympiad
Kvant Math Problem 782

Let $a+b=30030$ with $a,b\in \mathbb{N}$.

kvantmathematicsolympiad
Kvant Math Problem 744

The configuration consists of two similar triangles $ABC$ and $A_1B_1C_1$, with $A_1 \in BC$, $B_1 \in CA$, $C_1 \in AB$.

kvantmathematicsolympiad
Kvant Math Problem 712

We seek to represent an arbitrary positive real number as a sum of nine numbers whose decimal expansions use only digits $0$ and $7$.

kvantmathematicsolympiad
Kvant Math Problem 691

Let $P(n,k)=n(n+1)\cdots(n+k-1)$ for $n\ge 2$.

kvantmathematicsolympiad
Kvant Math Problem 662

The statement concerns a piggy bank containing coins whose total value is $4$ rubles.

kvantmathematicsolympiad
Kvant Math Problem 586

Let $B=60^\circ$ and let $O$ be the incenter of triangle $ABC$.

kvantmathematicsolympiad
Kvant Math Problem 572

The kangaroo moves in the integer lattice of the first quadrant with vectors $v_1=(1,-1)$ and $v_2=(-5,7)$, always staying in $x\ge 0$, $y\ge 0$.

kvantmathematicsolympiad
Kvant Math Problem 565

For each $k$, the quantity $b_k$ is the average of all products of $k$ distinct elements from $a_1,\ldots,a_n$.

kvantmathematicsolympiad
Kvant Math Problem 511

ABMD is a parallelogram, so the vertices satisfy the affine relation $a+m=b+d$, hence $m=a+d-b$.

kvantmathematicsolympiad
Kvant Math Problem 487

Let $O_1$ and $O_2$ be the centers of circles $\gamma_1$ and $\gamma_2$, with radii $R_1$ and $R_2$.

kvantmathematicsolympiad
Kvant Math Problem 469

Let $P(x)=x^4+ax^3+bx+c$ have four distinct real roots $r_1<r_2<r_3<r_4$.

kvantmathematicsolympiad
Kvant Math Problem 438

The configuration is a fixed circular segment determined by a chord $AB$ of a circle with center $O$.

kvantmathematicsolympiad
Kvant Math Problem 428

The problem is naturally translated into graph theory.

kvantmathematicsolympiad
Kvant Math Problem 404

Start with small $n$.

kvantmathematicsolympiad
Kvant Math Problem 390

Let $s(m)$ denote the sum of decimal digits of $m$.

kvantmathematicsolympiad
Kvant Math Problem 305

The concurrency of $AA'$, $BB'$, $CC'$ at $P$ together with products $|AP|\cdot|A'P|=t$ suggests a fixed-power relation, which is characteristic of inversion centered at $P$.

kvantmathematicsolympiad
Kvant Math Problem 201

Let triangle $ABC$ have sides $a=BC$, $b=CA$, $c=AB$.

kvantmathematicsolympiad
CF 442A - Borya and Hanabi

We have a collection of cards, each defined by a color and a number between 1 and 5. Borya holds n cards, and while he knows which cards he has, he cannot distinguish between identical cards in terms of position.

codeforcescompetitive-programmingbitmasksbrute-forceimplementation
CF 441B - Valera and Fruits

Valera has a garden with a number of fruit trees, each producing a specific number of fruits on a particular day. Each fruit becomes collectible on its ripening day and remains fresh only for the next day.

codeforcescompetitive-programminggreedyimplementation
CF 441E - Valera and Number

Valera starts with a number $x$ and performs $k$ random operations on it. On each step, he flips a biased coin: with probability $p/100$, he doubles the current number, otherwise he increments it by one.

codeforcescompetitive-programmingbitmasksdpmathprobabilities
CF 441C - Valera and Tubes

We are given an $n times m$ grid where every cell must be partitioned into exactly $k$ simple paths. Each path, called a tube, must contain at least two cells and must move only through edge-adjacent cells, never revisiting a cell.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similarimplementation
CF 440D - Berland Federalization

We are given a country with n towns connected by n - 1 roads. Because the number of roads is exactly one less than the number of towns and any town can reach the capital, the road network forms a tree.

codeforcescompetitive-programmingdptrees
CF 440C - One-Based Arithmetic

We are asked to represent a given positive integer $n$ as a sum of numbers, where each number consists entirely of the digit 1 repeated one or more times.

codeforcescompetitive-programmingbrute-forcedfs-and-similardivide-and-conquer