brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1569A - Balanced Substring

We are given a binary string consisting only of the characters a and b. For each test case, we must find any contiguous segment whose number of a characters is exactly equal to its number of b characters.

codeforcescompetitive-programmingimplementation
Kvant Physics Problem 183

The problem involves a dynamometer sliding along a smooth horizontal table, pulled by a constant horizontal force $F=4~\text{N}$, with the mass of its spring equal to the mass of its casing.

kvantphysics
CF 1569B - Chess Tournament

We are given a group of players where every pair plays a single chess game. For each match, we must decide one of three outcomes: one player wins and the other loses, or both draw.

codeforcescompetitive-programmingconstructive-algorithms
Kvant Physics Problem 186

A passenger of mass $m$ moves along a curved path of radius $R$ with speed $v$ during a turn.

kvantphysics
CF 1571J - Two Railroads

The problem is not a small implementation bug. The entire algorithmic approach is fundamentally wrong. Let's trace the sample that immediately disproves it: The proposed algorithm sees at least one '1', then only checks the first and last characters: - s[0] = ')' → flip needed…

codeforcescompetitive-programming*special
Kvant Physics Problem 178

A cubic vessel of edge length $a = 1~\text{cm} = 10^{-2}~\text{m}$ contains $n$ gas molecules at room temperature.

kvantphysics
Kvant Physics Problem 184

The physical system is a television image transmission channel.

kvantphysics
CF 1571H - Laser Beams

We are given a rectangular game level defined by its width a and height b. Inside the level are n enemies, each at a unique position (xi, yi).

codeforcescompetitive-programming*specialgeometryprobabilities
CF 1571I - Physical Examination

We are given several test cases. Each test case describes a set of doctors, where each doctor is available only during a fixed integer time interval.

codeforcescompetitive-programming*specialbinary-searchdata-structures
CF 1571E - Fix the String

We are given a string of brackets s and a binary string a of length n-3. Each '1' in a imposes a constraint that the corresponding 4-character substring of s must be a valid regular bracket sequence.

codeforcescompetitive-programming*specialbitmasksdpgreedy
CF 1571F - Kotlinforces

We are asked to place a collection of “events,” where each event is not a single day but a whole arithmetic progression of days.

codeforcescompetitive-programming*specialconstructive-algorithmsdp
CF 1571G - A Battle Against a Dragon

Codeforces 1571G: A Battle Against a Dragon

codeforcescompetitive-programming*specialdata-structuresdp
Kvant Physics Problem 182

A person jumps vertically upward from the surface of the Moon.

kvantphysics
CF 1571C - Rhyme

We are given several pairs of strings, each marked either as needing to rhyme or explicitly not rhyming. Two strings rhyme under a positive integer $k$ if their last $k$ characters are identical and each string has length at least $k$.

codeforcescompetitive-programming*specialimplementation
CF 1571D - Sweepstake

We are given a competition with n programmers and a survey of m spectators, each predicting who will finish first and last. You, as the first spectator, have submitted your prediction (f1, l1).

codeforcescompetitive-programming*specialbrute-forceconstructive-algorithmsimplementationmath
Kvant Physics Problem 180

A perfectly conducting isolated metal sphere of radius $R$ is placed in a uniform external electric field of magnitude $E$ directed along a fixed axis.

kvantphysics
CF 1571A - Sequence of Comparisons

We are given a sequence of relational signs between consecutive elements of an array, and we are asked to determine whether we can uniquely infer the relation between the first and the last element.

codeforcescompetitive-programming*special
CF 1572C - Paint

We have a one dimensional image represented by an array of colors. A single operation chooses a connected monochromatic segment and repaints the entire segment to any color. The connectivity definition is slightly unusual.

codeforcescompetitive-programmingdpgreedy
CF 1572F - Stations

We have a row of cities, each of which can host a broadcasting station. Each station has a height and a range. A station can reach cities to its right up to its range limit, but it is blocked by any taller station in between.

codeforcescompetitive-programmingdata-structures
CF 1572D - Bridge Club

We are given a universe of $2^n$ players, where each player is identified by an $n$-bit mask. Each bit represents whether that player has a positive or negative opinion on a topic.

codeforcescompetitive-programmingflowsgraph-matchingsgraphsgreedy
Kvant Physics Problem 177

A stretched string performs small transverse vibrations.

kvantphysics
Kvant Physics Problem 176

The system consists of a rigid tool, such as an awl, nail, or knife, interacting with a deformable material.

kvantphysics
Kvant Physics Problem 179

A submarine moves vertically downward with constant speed $u$ in still water where sound propagates with speed $V$.

kvantphysics
CF 1572B - Xor of 3

We are given a sequence of 0s and 1s and an operation that can change any three consecutive elements to the XOR of those three elements.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedytwo-pointers
CF 1573A - Countdown

The problem presents a digital clock showing an integer with exactly $n$ digits. Each digit ranges from 0 to 9, and the display includes leading zeroes so the number always has length $n$. The goal is to reduce this number to zero with the fewest possible operations.

codeforcescompetitive-programminggreedy
Kvant Physics Problem 174

An ideal gas containing $n$ moles undergoes a quasistatic thermodynamic process in which the temperature $T$ is prescribed as a function of the volume $V$.

kvantphysics
Kvant Physics Problem 175

Two identical solid elastic spheres of radius $R = 1~\text{cm} = 1.

kvantphysics
CF 1573B - Swaps

We are given two arrays of length $n$, where array $a$ contains all the odd numbers from $1$ to $2n$ in some order, and array $b$ contains all the even numbers from $1$ to $2n$ in some order.

codeforcescompetitive-programminggreedymathsortings
Kvant Physics Problem 166

A horizontal cylinder contains $n=1$ mole of an ideal gas.

kvantphysics
CF 1574C - Slay the Dragon

We have a squad of heroes, each with a fixed strength. For every dragon, we must choose exactly one hero to fight it, while all remaining heroes stay behind to defend the castle. A dragon has two requirements.

codeforcescompetitive-programmingbinary-searchgreedysortingsternary-search
CF 1574F - Occurrences

We are asked to construct a length m array a, where each position can take a value from 1 to k. The twist is that we are given several “pattern arrays” Ai, and these patterns impose constraints on how often they are allowed to appear inside a.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardpdsufftgraphs
CF 1574E - Coloring

We are asked to fill an initially empty $n times m$ matrix with 0s and 1s such that every $2 times 2$ submatrix contains exactly two 0s and two 1s.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsimplementationmath
CF 1574D - The Strongest Build

In this problem, we are asked to help Ivan choose the strongest possible hero build from a set of equipment slots, each with multiple items of different strengths. Each slot has its own list of items, already sorted by increasing strength.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdfs-and-similargraphsgreedyhashingimplementation
CF 1574B - Combinatorics Homework

The proposed solution appears to be a complete and well-explained editorial for Codeforces 1575A, but it does not address Exercise 4.2.2.16 from TAOCP at all.

codeforcescompetitive-programmingcombinatoricsgreedymath
Kvant Physics Problem 173

A solid sphere of radius $R$ carries a uniform volume charge density $\sigma$ with units $\mathrm{C/m^3}$.

kvantphysics
Kvant Physics Problem 172

A rigid conducting rod of length $l = 0.

kvantphysics
CF 1574A - Regular Bracket Sequences

We are asked to generate valid bracket sequences, which are strings consisting only of "(" and ")" that form balanced parentheses. A sequence is valid if every opening bracket has a corresponding closing bracket and no closing bracket appears before its matching opening bracket.

codeforcescompetitive-programmingconstructive-algorithms
CF 1575A - Another Sorting Problem

We have a collection of distinct book titles, all with the same length. The books are not sorted using ordinary lexicographic order. When comparing two titles, we scan from left to right until we find the first position where they differ.

codeforcescompetitive-programmingdata-structuressortingsstrings
CF 1575L - Longest Array Deconstruction

We start with an array. We may repeatedly delete arbitrary elements, and after each deletion the remaining elements close up together. For any resulting array, define its score as the number of positions where the value equals its current 1-based index.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdpsortings
CF 1575M - Managing Telephone Poles

The grid describes a city map where some cells contain telephone poles. Each cell corresponds to an integer coordinate point on a plane, and a value of 1 means a pole exists at that location.

codeforcescompetitive-programmingdata-structuresgeometry
Kvant Physics Problem 171

The system consists of two identical point masses, each of mass $m$, fixed at the ends of a massless rigid rod of length $l$.

kvantphysics
CF 1575K - Knitting Batik

We are asked to count the number of ways to color a large rectangular cloth with size $n times m$ using $k$ colors, given that two fixed subrectangles of size $r times c$ must be identical in their color patterns.

codeforcescompetitive-programmingimplementationmath
Kvant Physics Problem 170

A homogeneous plasma initially occupies a slab of thickness $x$ and contains a uniform density $n$ of positive ions and an equal density $n$ of electrons, where $n$ is the number of particles of each…

kvantphysics
CF 1575J - Jeopardy of Dropped Balls

We have an n × m grid. Every cell stores one of three directions. A value of 1 means a ball moves one cell to the right. A value of 2 means the ball moves one cell downward. A value of 3 means the ball moves one cell to the left.

codeforcescompetitive-programmingbinary-searchbrute-forcedsuimplementation
CF 1575G - GCD Festival

We are given an array of integers a with length n. The goal is to compute a sum over all pairs (i, j) where i and j are indices of the array, and for each pair we multiply two quantities: the GCD of the array elements a[i] and a[j], and the GCD of their positions i and j.

codeforcescompetitive-programmingmathnumber-theory
CF 1575H - Holiday Wall Ornaments

We are given a binary string representing a wall, where each character is either 0 or 1. This string, a, is of length n. Mr. Chanek wants to place his nephew’s favorite pattern, another binary string b of length m, onto the wall.

codeforcescompetitive-programmingdpstrings
CF 1575F - Finding Expected Value

We start with an array whose values lie in the range [0, k - 1]. As long as not all positions contain the same value, we repeatedly choose a random position and a random value, then overwrite that position.

codeforcescompetitive-programmingmath
CF 1575E - Eye-Pleasing City Park Tour

The city park is a tree where each attraction is a node and each rail is an edge. Every node has a happiness value, and every edge has a color, either black or white. Moving through the tree is always along simple paths, meaning you never revisit a node.

codeforcescompetitive-programmingdata-structurestrees
CF 1575B - Building an Amusement Park

We want to place a circular amusement park so that it touches the origin. If the park has radius $r$, then its center must lie exactly $r$ units from the origin, because the origin lies on the boundary of the park. Each bird habitat is a point in the plane.

codeforcescompetitive-programmingbinary-searchgeometry
Kvant Physics Problem 154

The physical system is a layer of fog consisting of identical spherical water droplets suspended in air.

kvantphysics
CF 1575D - Divisible by Twenty-Five

We are given a very short string, at most length 8, that represents a partially unknown integer. Some positions contain fixed digits, some contain a wildcard underscore meaning “any digit is allowed here”, and some contain the character X meaning all X positions must share…

codeforcescompetitive-programmingbrute-forcedfs-and-similardp
CF 1575C - Cyclic Sum

We are given an array a of length n and a repetition count m. From this, we form a cyclic sequence b by concatenating m copies of a. Conceptually, b is circular: after the last element, the first element follows.

codeforcescompetitive-programmingdata-structuresfftnumber-theory
CF 1576A - Communication Routing Challenge

The system models a communication network where each node represents a switching site and each edge represents a physical communication link between two sites. Every link has a limited capacity, a length cost, and belongs to a group.

codeforcescompetitive-programming*special
Kvant Physics Problem 137

The radiation of a fixed infrared wavelength propagates through methane according to the exponential attenuation law.

kvantphysics
CF 1578I - Interactive Rays

We are working in a plane where a circle is hidden from us. The circle is fully determined by its center coordinates and its radius, but we do not know them. Our only tool is to shoot a ray starting from the origin and passing through an integer point we choose.

codeforcescompetitive-programminggeometryinteractive
Kvant Physics Problem 139

A football is launched from a fixed point on level ground with initial speed $v$ at an angle $\alpha=30^\circ$ to the horizontal.

kvantphysics
CF 1578H - Higher Order Functions

We are given a single string that represents a type expression built from three constructs: a base unit type written as (), parentheses that group a type without changing its meaning, and a function constructor written as - that connects two types.

codeforcescompetitive-programmingimplementationstrings
CF 1578E - Easy Scheduling

We are asked to schedule tasks that are arranged as a full binary tree of height $h$. A full binary tree of height $h$ has $2^h - 1$ nodes. Initially, only the root task is ready. At each discrete moment of time, up to $p$ processes can perform ready tasks simultaneously.

codeforcescompetitive-programmingimplementationmath
CF 1578C - Cactus Lady and her Cing

We are given a cactus graph, which is a connected undirected graph where each vertex lies on at most one simple cycle. That means every vertex is either part of a tree structure or part of a single cycle. No multi-edges or loops are allowed.

codeforcescompetitive-programming
CF 1578D - Dragon Curve

Every unit square with integer corners is crossed by exactly one segment of one of four infinite dragon curves. For a query square with opposite corners $(x,y)$ and $(x+1,y+1)$, we must determine two things.

codeforcescompetitive-programming
CF 1579F - Array Stabilization (AND version)

We are given an array consisting only of zeroes and ones, and a positive integer d that specifies a cyclic right shift.

codeforcescompetitive-programmingbrute-forcegraphsmathnumber-theoryshortest-paths
CF 1579E2 - Array Optimization by Deque

The proposed solution does address the actual exercise and identifies the key idea: each pair $(U{2n-1},U{2n})$ is transformed by either keeping it unchanged or swapping coordinates, depending on whether the point lies in $G$. This is indeed the mechanism behind the construction.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1579G - Minimal Coverage

We are given a sequence of segment lengths, and we must place these segments one after another on an infinite number line. The first segment starts at coordinate 0, with one endpoint fixed at 0.

codeforcescompetitive-programmingdp
CF 1579E1 - Permutation Minimization by Deque

We are given a permutation of size $n$, which means an array containing all integers from 1 to $n$ exactly once. Our task is to process this permutation into a double-ended queue, or deque, where each new element can either be placed at the front or the back.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1579C - Ticks

We are given a grid of size $n times m$ representing a paper, where some cells are black (denoted by ) and others are white (.). Casimir claims the black cells are produced by drawing ticks.

codeforcescompetitive-programminggreedyimplementation
CF 1579A - Casimir's String Solitaire

We are given a string containing only the characters A, B, and C. In one move, we may remove either an A together with a B, or a B together with a C. The two removed characters can come from any positions in the string.

codeforcescompetitive-programmingmathstrings
CF 1579D - Productive Meeting

We are asked to organize a meeting with $n$ people, where each person has a limit on how many private conversations they can participate in. The array $a$ describes each person’s sociability: $ai$ is the number of talks person $i$ can attend before leaving.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedy
CF 1579B - Shifting Sort

We are given an array and a special operation. Instead of swapping individual elements, we may choose any contiguous segment and rotate that segment to the left by any amount. After the rotation, the elements remain inside the same interval, only their order changes cyclically.

codeforcescompetitive-programmingimplementationsortings
CF 1580E - Railway Construction

We are given a network of railway stations in Gensokyo, connected by two-way railways with positive lengths. The stations are numbered from 1 to $n$, with station 1 being the main hub. The network is fully connected, so every station is reachable from any other station.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdata-structuresgraphsshortest-paths
CF 1580C - Train Maintenance

We have a system that tracks trains of different models over a sequence of days. At the start, there are no trains. On each day, we either add a train of a specific model or remove one.

codeforcescompetitive-programmingbrute-forcedata-structuresimplementation
Kvant Physics Problem 85

An ideal gas in equilibrium is described by states $(p,V)$ with $p>0$, $V>0$ and equation of state $pV=\nu RT$.

kvantphysics
CF 1580F - Problems for Codeforces

I can write a full editorial in that format, but I need the actual solution first. Codeforces 1580F is a 3300-rated problem whose accepted solution is highly nontrivial and relies on fairly deep generating-function techniques with FFT.

codeforcescompetitive-programmingcombinatoricsfftmath
CF 1580D - Subsequence

We are given a sequence of distinct integers of length $n$, and we are asked to select a subsequence of length $m$ to maximize a specific value.

codeforcescompetitive-programmingbrute-forcedivide-and-conquerdpgreedytrees
CF 1580A - Portal

We are given a binary grid. A cell containing 1 is an obsidian block and a cell containing 0 is empty. We may flip any cell, changing 0 to 1 or 1 to 0, with cost one per flip.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedyimplementation
CF 1580B - Mathematics Curriculum

We are asked to count permutations of the numbers from 1 to $n$ that have exactly $k$ "good" numbers. A number $x$ in a permutation is called good if, when we look at all contiguous subarrays containing $x$, there are exactly $m$ distinct maxima.

codeforcescompetitive-programmingbrute-forcecombinatoricsdptrees
CF 1581A - CQXYM Count Permutations

The outputs: show that the current algorithm is not merely suffering from a small implementation bug. It is solving a different optimization problem. Let's examine the samples: Input: Expected: Current output: 15 is simply the sum of the array.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 1581B - Diameter of Graph

We are asked to determine whether it is possible to construct a simple, connected, undirected graph with a given number of nodes n and edges m such that the graph's diameter is strictly less than k-1.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedymath
CF 1582F1 - Korney Korneevich and XOR (easy version)

We are given an array of integers, and the task is to determine all possible values of x that can be obtained as the XOR of some increasing subsequence of the array.

codeforcescompetitive-programmingbitmasksdpgreedy
Kvant Physics Problem 77

A rectangular block of height $H$ and base dimensions $a \times b$ stands on a horizontal rigid surface.

kvantphysics
Kvant Physics Problem 72

The solution correctly identifies that each ball undergoes uniform circular motion about its respective pivot, with angular velocities $\omega_1 = v/l$ and $\omega_2 = 2v/(2l) = v/l$, so the angular s…

kvantphysics
CF 1582F2 - Korney Korneevich and XOR (hard version)

We are given an array of integers a of length n. The task is to find all non-negative integers x that can be expressed as the XOR of some strictly increasing subsequence of a.

codeforcescompetitive-programmingbinary-searchbrute-forcedpgreedytwo-pointers
Kvant Physics Problem 71

Consider a straight line segment $AB$ carrying a uniform linear charge density $\lambda$.

kvantphysics
Kvant Physics Problem 68

The physical system consists of a rigid container containing an ideal gas whose bulk temperature is $T_1$, while the walls are maintained at temperature $T$.

kvantphysics
CF 1582B - Luntik and Subsequences

We are given several arrays. For each array, let the sum of all elements be $s$. We need to count how many subsequences have sum exactly $s-1$. A subsequence is formed by deleting any number of elements, possibly none of them or all of them.

codeforcescompetitive-programmingcombinatoricsmath
Kvant Physics Problem 69

The fragment “NOT_FOUN_” contains no equations, constraints, or target quantity, so the problem cannot be instantiated as a well-posed Kvant task.

kvantphysics
Kvant Physics Problem 56

A flag is modeled as a thin flexible sheet of characteristic length $L$ and mass per unit area $\sigma$, clamped along one edge to a rigid pole.

kvantphysics
Kvant Physics Problem 63

The physical system consists of a person moving on an icy slope inclined at an angle $\alpha$ to the horizontal.

kvantphysics
CF 1583C - Omkar and Determination

We are given a rectangular board where each cell is either blocked by an X or empty. From an empty cell we may move only upward or leftward. A cell is called exitable if some sequence of such moves lets us leave the grid. The question is not to simulate those moves.

codeforcescompetitive-programmingdata-structuresdp
Kvant Physics Problem 65

The system consists of two conducting plates and the ground.

kvantphysics
Kvant Physics Problem 58

The system consists of a thin metallic ring of mass $m$ and resistance $R$, with diameter $d$, falling vertically in a magnetic field that points along the vertical direction.

kvantphysics
CF 1584F - Strange LCS

We are given up to 10 strings, all over a mixed alphabet of lowercase and uppercase English letters. The task is to construct a single string that appears as a subsequence in every given string, and among all such strings we want the longest possible one.

codeforcescompetitive-programmingbitmasksdpgraphsgreedystrings
CF 1584G - Eligible Segments

We have several points on the plane. We want to count pairs of points whose connecting segment stays close to every point in the set. More precisely, for a chosen pair $(pi,pj)$, every point must lie at distance at most $R$ from that segment.

codeforcescompetitive-programminggeometry
CF 1584A - Mathematical Addition

For each test case we are given two positive integers, $u$ and $v$. We must find any pair of integers $x$ and $y$, not both zero, such that $$frac{x}{u}+frac{y}{v}=frac{x+y}{u+v}.$$ The task is not to count solutions or find a particular one.

codeforcescompetitive-programmingmath
Kvant Physics Problem 57

Two identical balls, each of mass $m$, are connected by a massless spring of stiffness $k$.

kvantphysics
CF 1584E - Game with Stones

We are given a sequence of piles of stones, each with a non-negative integer count. Bob can repeatedly remove one stone from two adjacent piles. If a pile becomes empty, it no longer counts as part of any adjacent pair.

codeforcescompetitive-programmingbinary-searchdata-structuresgamesgreedy
CF 1584D - Guess the Permutation

We are given a sequence of length $n$ that initially contains integers from $1$ to $n$ in increasing order. Then the jury selects three indices $i < j < k$ with $j - i 1$ and reverses two subsegments: the first from $i$ to $j-1$, and the second from $j$ to $k$.

codeforcescompetitive-programmingbinary-searchcombinatoricsinteractivemath
CF 1584B - Coloring Rectangles

We start with an $n times m$ grid of cells. The rectangle may be cut repeatedly along grid lines, producing smaller rectangles. The only restriction is that no final piece may have size $1 times 1$.

codeforcescompetitive-programminggreedymath
CF 1584C - Two Arrays

We are given two integer arrays of equal length. The allowed operation on the first array is quite specific: we may choose some subset of positions and increase each chosen element by exactly one. After that, we are allowed to freely reorder the array.

codeforcescompetitive-programminggreedymathsortings
Kvant Physics Problem 55

An arrow of mass

kvantphysics
Kvant Physics Problem 51

A camera obscura is modeled as a rectangular box of length $L$ with a small circular aperture of diameter $d = 1,\text{mm} = 1\times 10^{-3},\text{m}$.

kvantphysics