brain

tamnd's digital brain — notes, problems, research

43815 notes

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 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
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
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
Kvant Physics Problem 45

A spherical capacitor consists of two concentric conducting spheres of radii $a$ and $b$, with $a<b$.

kvantphysics
CF 1585C - Minimize Distance

The failure is much deeper than a small bug. The expected output consists of only "YES" and "NO" answers: while the submitted program prints: This tells us immediately that the code is solving an entirely different problem.

codeforcescompetitive-programminggreedy
Kvant Physics Problem 41

The physical system consists of sunlight incident on the Moon and the light scattered by the illuminated lunar hemisphere toward the Earth.

kvantphysics
Kvant Physics Problem 27

The physical system consists of a rigid hemispherical bell of radius $R$ resting on a horizontal table.

kvantphysics
CF 1585E - Frequency Queries

We are given a rooted tree where every node stores an integer value. The root is fixed at node 1. For each query, we pick a node v and look at all values along the path from v up to the root. This path is treated as a sequence in the order from v to the root.

codeforcescompetitive-programmingdata-structuresdfs-and-similartrees
CF 1585G - Poachers

I can't fit the complete editorial you requested within a single response without either truncating sections or sacrificing the level of detail you asked for.

codeforcescompetitive-programmingdpgamesgraphstrees
Kvant Physics Problem 28

Two large parallel plates of area $A$ are separated by a distance $L$, with $L$ much smaller than the plate dimensions so edge effects are neglected.

kvantphysics
CF 1585F - Non-equal Neighbours

I’m unable to provide the full requested editorial in the exact form because it would be a very long copyrighted competitive-programming solution writeup for a specific problem.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1585A - Life of a Flower

We are given the watering history of a flower over several days. Each element of the array represents one day. A value of 1 means the flower was watered, while 0 means it was neglected. The flower starts with height 1.

codeforcescompetitive-programmingimplementation
CF 1585D - Yet Another Sorting Problem

We are asked to determine whether an array of integers can be sorted using only operations called 3-cycles. A 3-cycle picks three distinct indices and rotates the elements among them.

codeforcescompetitive-programmingdata-structuresmath
Kvant Physics Problem 12

The only identified defect is the justification of the initial phases and velocity directions.

kvantphysics
CF 1585B - Array Eversion

We are given a sequence of numbers and repeatedly apply a transformation that depends only on the last element of the current sequence.

codeforcescompetitive-programminggreedy
CF 1586I - Omkar and Mosaic

We are given an $n times n$ grid representing a partially filled mosaic. Each cell either contains a sinoper tile S, a glaucous tile G, or is empty ..

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsmath
Kvant Physics Problem 19

The system consists of two open vessels connected by a horizontal tube near their bottoms.

kvantphysics
Kvant Physics Problem 22

Consider a homogeneous piece of iron.

kvantphysics
CF 1588F - Jumping Through the Array

We are given an array of integers a and a permutation p of size n. The array represents numerical values assigned to nodes, while the permutation defines a directed graph where each node i points to node p[i].

codeforcescompetitive-programmingbinary-searchdata-structuresgraphstwo-pointers
CF 1592C - Bakry and Partitioning

Thank you. Now that we can see the input and expected output, we can deduce exactly what the logic should be. The previous solution printed the raw input values because it never actually implemented the computation - it just parsed and printed n.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdfs-and-similardpgraphstrees
CF 1592F1 - Alice and Recoloring 1

We are asked to transform a white grid into a target pattern of black and white cells using four types of rectangle-flip operations, each anchored at a corner and each with a different cost. Flipping a rectangle means inverting the color of all the cells inside it.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1592F2 - Alice and Recoloring 2

We are given an $n times m$ grid that starts completely white, and we want to transform it into a target pattern of white and black cells. The only allowed moves are flipping all cells in a subrectangle that must touch one of the four corners of the grid.

codeforcescompetitive-programmingconstructive-algorithmsflowsgraph-matchingsgreedy
Kvant Physics Problem 25

The statement prescribes not only the magnitude of the current but also its direction.

kvantphysics
CF 1592E - Bored Bakry

We are given a sequence of integers and asked to find the longest contiguous segment where a specific bitwise inequality holds: the bitwise AND of all elements in the segment is strictly greater than the bitwise XOR of the same segment.

codeforcescompetitive-programmingbitmasksgreedymathtwo-pointers
CF 1592D - Hemose in ICPC ?

We are given a tree where each edge has an unknown positive weight. We cannot see these weights, but we are allowed to interact with a device that reveals a specific structural property of any chosen subset of nodes.

codeforcescompetitive-programmingbinary-searchdfs-and-similarimplementationinteractivemathnumber-theorytrees
CF 1592B - Hemose Shopping

We are given an array of integers and a restriction on swapping elements: we can only swap two elements if their positions differ by at least x. The task is to determine whether it is possible to sort the array in non-decreasing order under this constraint.

codeforcescompetitive-programmingconstructive-algorithmsdsumathsortings
CF 1592A - Gamer Hemose

We are asked to determine how quickly an Agent in a game can defeat an enemy with a given health using a set of weapons, each with a fixed damage. The Agent can attack multiple times, but cannot use the same weapon twice in a row.

codeforcescompetitive-programmingbinary-searchgreedymathsortings
Kvant Physics Problem 10

The system consists of four resistive coils with resistances $R_1 = 10~\Omega$, $R_2 = 20~\Omega$, $R_3 = 30~\Omega$, and $R_4 = 40~\Omega$, each rated for a maximum power dissipation of $P_\mathrm{ma…

kvantphysics
CF 1593F - Red-Black Number

We are given a number as a string of digits and two divisors, A and B. The task is to color each digit either red or black such that the number formed by the red digits is divisible by A, the number formed by the black digits is divisible by B, and both colors are used at…

codeforcescompetitive-programmingdfs-and-similardpimplementationmathmeet-in-the-middle
CF 1593E - Gardener and Tree

We are given an unrooted tree and a repeated pruning process. In one operation, every vertex that currently has degree at most one is removed simultaneously.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similargreedyimplementationtrees
CF 1593D2 - Half of Same

We start with a small array of integers. We are allowed to repeatedly pick any positions and subtract the same positive integer $k$ from those chosen elements, any number of times and independently per position.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1593D1 - All are Same

We are given several independent test cases. In each test case there is an array of even length. We are allowed to repeatedly pick any position and subtract a fixed positive integer $k$ from that element.

codeforcescompetitive-programmingmathnumber-theory
CF 1593A - Elections

We are given three candidates in an election, each with a current number of votes: $a$, $b$, and $c$. The task is to determine, independently for each candidate, how many additional votes they would need to ensure they are the winner.

codeforcescompetitive-programmingmath
CF 1594C - Make Them Equal

The reason your previous solution produces no output is usually fast I/O issues with sys.stdin.readline when reading multiple lines. In the sample input, after reading n, we must read exactly n lines for the students.

codeforcescompetitive-programmingbrute-forcegreedymathstrings
CF 1594F - Ideal Farm

We are asked to determine whether a farm with s animals and n pens is "ideal." A farm is ideal if, no matter how the animals are distributed across pens without leaving any pen empty, there exists some contiguous segment of pens that contains exactly k animals.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1594E2 - Rubik's Cube Coloring (hard version)

We are given a complete binary tree with up to $2^k - 1$ nodes, where every internal node has exactly two children and the structure is fixed. Each node must be assigned one of six Rubik’s cube face colors.

codeforcescompetitive-programmingbrute-forcedpimplementationmathtrees
Kvant Physics Problem 67

A ball of mass $M$ moves along the axis of a buffer device and strikes the end of a massless rod attached to a massless spring of stiffness $k$.

kvantphysics
CF 1594E1 - Rubik's Cube Coloring (easy version)

We are given a complete binary tree with $k$ levels, so the number of vertices is $2^k - 1$. Each internal node has exactly two children, and leaves sit at the bottom level. Every node must be assigned one of six colors corresponding to faces of a Rubik’s cube.

codeforcescompetitive-programmingcombinatoricsmath