brain

tamnd's digital brain — notes, problems, research

41650 notes

Kvant Math Problem 2850

Label the marked points by the elements of $\mathbb Z_{2n}$ in cyclic order.

kvantmathematicsolympiad
CF 1804G - Flow Control

We are tasked with simulating a network line shared by multiple users, where each user transmits data at a rate that can grow or shrink depending on network congestion. Each user has a start time, end time, and initial data rate.

codeforcescompetitive-programmingdata-structuresdsuimplementation
CF 1804A - Lame King

A king starts at the origin of a grid and wants to reach a target cell (a, b). Unlike a normal king, it can only move one step vertically or horizontally, or stay in place. The unusual restriction is that the same action cannot be used twice in a row.

codeforcescompetitive-programminggreedymath
CF 1804D - Accommodation

We are given a grid of size $n times m$ where each cell represents a window in a high-rise building. Each cell is either lit or dark. The building is structured in floors, and each floor is an independent row of the grid.

codeforcescompetitive-programmingbrute-forcedpgreedyimplementation
Kvant Math Problem 2845

A cube in three-dimensional space with vertices in $\mathbb{Z}^3$ can be described by a vertex and three vectors $\mathbf{u}, \mathbf{v}, \mathbf{w} \in \mathbb{Z}^3$ that are pairwise orthogonal and…

kvantmathematicsolympiad
CF 1804B - Vaccination

We are given a sorted list of arrival times of patients. Each patient arrives at a specific moment and is willing to wait for a limited number of time units, meaning there is a window during which they can be vaccinated.

codeforcescompetitive-programminggreedyimplementation
CF 1804C - Pull Your Luck

We have a roulette wheel with n sectors numbered from 0 to n-1. The wheel starts with an arrow pointing at sector x, and we can spin it by pulling a handle with an integer force f between 1 and p.

codeforcescompetitive-programmingbrute-forcegreedymathnumber-theory
CF 1805F2 - Survival of the Weakest (hard version)

I’m sorry, but I can’t reliably write a correct editorial and solution for Codeforces 1805F2 from memory alone. This is a 3100-rated problem with a fairly intricate mathematical reduction, and I don’t want to invent a proof, algorithm, or code that may be incorrect.

codeforcescompetitive-programminggreedymathsortingstwo-pointers
CF 1805D - A Wide, Wide Graph

We are given a tree with $n$ vertices and asked to generate a sequence of graphs $Gk$ for $k = 1$ to $n$. In each graph $Gk$, an edge exists between vertices $u$ and $v$ if the distance between $u$ and $v$ in the original tree is at least $k$.

codeforcescompetitive-programmingdfs-and-similardpgraphsgreedytrees
CF 1805F1 - Survival of the Weakest (easy version)

We are given an array of non-negative integers and asked to repeatedly transform it by taking all pairwise sums, sorting them, and keeping only the smallest $n-1$ sums. This operation is applied $n-1$ times until a single number remains, which is the output modulo $10^9+7$.

codeforcescompetitive-programmingbinary-searchbrute-forceimplementationmathsortings
Kvant Math Problem 2844

We place square $ABCD$ in the coordinate plane with $A=(0,0)$, $B=(1,0)$, $C=(1,1)$, and $D=(0,1)$.

kvantmathematicsolympiad
CF 1805E - There Should Be a Lot of Maximums

We are given a tree, which is a connected acyclic graph, with n vertices. Each vertex has an integer label. The task revolves around a parameter called MAD, or “maximum double,” which is defined as the largest integer that occurs at least twice among the vertices of a tree.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similardptreestwo-pointers
CF 1805C - Place for a Selfie

We are asked to choose, for each parabola, a straight line that passes through the origin and does not intersect the parabola at all. Each line is given by its slope $k$, so the line is $y=kx$. Each parabola is given by $y = ax^2 + bx + c$ with $a0$, so it opens upwards.

codeforcescompetitive-programmingbinary-searchdata-structuresgeometrymath
CF 1805B - The String Has a Target

We are given a string and allowed to perform exactly one operation: pick a character at some position and move it to the start of the string. The goal is to produce the lexicographically smallest string possible after this operation.

codeforcescompetitive-programminggreedystrings
CF 1806F1 - GCD Master (easy version)

Working

codeforcescompetitive-programminggreedymathnumber-theorysortings
CF 1806F2 - GCD Master (hard version)

We are given an array of integers where each element is at most $m$, and we are allowed to perform exactly $k$ operations. In each operation, we select two elements, remove them, and append their greatest common divisor (gcd) to the array.

codeforcescompetitive-programminggreedymathsortings
CF 1806D - DSU Master

We are given a binary array that encodes how edges are directed between values, and we are asked to evaluate a rather indirect quantity over all permutations of each prefix length. For a fixed length $k$, we take every permutation of ${1,2,dots,k}$.

codeforcescompetitive-programmingcombinatoricsdpdsumath
CF 1806E - Tree Master

The tree is rooted at vertex 1. Every vertex has a value a[v], and every vertex except the root has a parent. For a query (x, y), both vertices are guaranteed to lie at the same depth. Starting from these two vertices, we repeatedly move both upward one edge at a time.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similartrees
CF 1806C - Sequence Master

We are given an array p of length 2n. We want to modify its values and obtain another array q of the same length. The target array is not arbitrary.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsmath
CF 1806A - Walking Master

We are asked to compute the minimum number of moves for a character, YunQian, to reach a target point on an infinite Cartesian plane.

codeforcescompetitive-programminggeometrygreedymath
CF 1807G2 - Subsequence Addition (Hard Version)

We are asked whether a given array c can be generated starting from an initial array [1] by repeatedly adding a new element equal to the sum of any subsequence of the current array.

codeforcescompetitive-programmingbitmasksdpgreedyimplementationsortings
CF 1807F - Bouncy Ball

We have a ball moving inside an n × m rectangular grid. The ball always travels diagonally, so each move changes both coordinates by ±1. A direction consists of a vertical component and a horizontal component.

codeforcescompetitive-programmingbrute-forcedfs-and-similarimplementation
CF 1807G1 - Subsequence Addition (Easy Version)

We start with an array containing a single element [1]. We are allowed to repeatedly pick any subsequence of the current array, sum its elements, and append this sum as a new element to the array.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedyimplementationsortings
CF 1807A - Plus or Minus

I’ve carefully analyzed this problem. The root cause of the previous wrong output is twofold: 1. Incorrect input handling: Each test case is a string of digits.

codeforcescompetitive-programmingimplementation
CF 1807E - Interview

We are given several independent test cases. In each one there is a collection of piles of stones. Every pile contains some number of stones, and all stones have weight 1 except for a single hidden special stone located in exactly one pile, which contributes an extra unit of…

codeforcescompetitive-programmingbinary-searchimplementationinteractive
CF 1807D - Odd Queries

We are given an array of integers and a sequence of queries. Each query asks whether, if we were to overwrite all elements in a certain subarray with a fixed value, the total sum of the array would become odd. The queries do not modify the array permanently.

codeforcescompetitive-programmingdata-structuresimplementation
CF 1807C - Find and Replace

We are given a string made of lowercase letters, and we are allowed to repeatedly “collapse” entire character classes into binary digits. One operation picks a letter, say x, and globally rewrites every occurrence of x in the string into either 0 or 1.

codeforcescompetitive-programminggreedyimplementationstrings
Kvant Math Problem 2843

Introduce Cartesian coordinates adapted to the symmetry of the equilateral triangle.

kvantmathematicsolympiad
Kvant Math Problem 2842

Let $a, a+1, \dots, a+n-1$ be $n>1$ consecutive natural numbers.

kvantmathematicsolympiad
CF 1807B - Grab the Candies

We have several bags of candies. A bag containing an even number of candies always goes to Mihai, while a bag containing an odd number of candies always goes to Bianca. The order of the bags is not fixed. We may rearrange them however we want before the game starts.

codeforcescompetitive-programminggreedy
CF 1808E3 - Minibuses on Venus (hard version)

A ticket is a sequence of n digits in base k, so every position contains a value from 0 to k - 1. Let the total digit sum modulo k be $$S = a1 + a2 + dots + an pmod k.$$ A ticket is lucky if there exists some position whose digit equals the sum of all remaining digits modulo k.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpmath
Kvant Math Problem 2826

Place the square in coordinates with $A(0,0)$, $B(1,0)$, $C(1,1)$, $D(0,1)$.

kvantmathematicsolympiad
CF 1808D - Petya, Petya, Petr, and Palindromes

For every subarray of odd length k, we want to know how many element replacements are needed to turn that subarray into a palindrome. The answer is the sum of those values over all length-k subarrays.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structurestwo-pointers
CF 1808B - Playing in a Casino

Each player receives a card containing m integers. For every pair of players, the amount won in their game is the sum of absolute differences between the corresponding positions on their cards. If player i has card values c[i][1...m] and player j has card values c[j][1...

codeforcescompetitive-programmingmathsortings
CF 1809G - Prediction

We are given a sorted list of participant ratings, and we are allowed to permute these participants into a line. After fixing a permutation, a sequential tournament is played: the first two players fight, then the winner immediately fights the third player in line, then the…

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1809F - Traveling in Berland

We are asked to compute the minimum cost of a circular journey through Berland starting and ending at every city. Each city has a fuel station with a per-liter price, and traveling from city $i$ to city $i+1$ requires a fixed amount of fuel.

codeforcescompetitive-programmingbinary-searchdata-structuresgraphsgreedyimplementation
CF 1809D - Binary String Sorting

We are given a binary string and want to transform it into a non-decreasing binary string. For binary strings, "sorted" means that all 0s appear before all 1s. Examples of sorted strings are 000111, 0, 111, and even the empty string. Two operations are available.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1809E - Two Tanks

We are given two containers with fixed capacities. The first can hold up to a units of water and the second up to b.

codeforcescompetitive-programmingbinary-searchdpimplementationmath
CF 1809A - Garland

The symptom here is very specific: the program produces only one output (YES) instead of producing seven lines corresponding to the seven test cases. This is a structural bug in how the input loop is written or how the program reads multiple test cases.

codeforcescompetitive-programmingimplementation
CF 1809C - Sum on Subarrays

We are asked to construct an integer array of length $n$, where each element must lie in a small bounded range, such that a very specific combinatorial property holds over all its subarrays. Every contiguous segment contributes a single value: the sum of its elements.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1809B - Points on Plane

We want to place n chips on integer lattice points of the plane. The cost of a chip at (x, y) is its Manhattan distance from the origin, The chips must satisfy one geometric restriction: every pair of chips must be more than 1 unit apart in Euclidean distance.

codeforcescompetitive-programmingbinary-searchgreedymath
CF 1810H - Last Number

The issue here is purely syntactic in the way the multi-line string was written. The triple-quoted string for the test input was not terminated properly, causing a SyntaxError. Every """ must be paired correctly.

codeforcescompetitive-programmingcombinatoricsmath
CF 1810G - The Maximum Prefix

We are building a random sequence of +1 and -1 values, but we never actually simulate it directly. Instead, for a fixed length k, each position independently becomes +1 with probability pi and -1 otherwise.

codeforcescompetitive-programmingdp
CF 1810F - M-tree

We are asked to build a rooted tree that satisfies a very particular property: each non-leaf node must have exactly m children, and every leaf holds a positive integer. The tree is called "good" if it satisfies this structure.

codeforcescompetitive-programmingdata-structuresmathsortingstrees
CF 1810A - Beautiful Sequence

The traceback you are seeing: is not a logic error in your algorithm. It happens because your code does: but the input is empty. input() reaches end-of-file immediately, so Python raises an EOFError. This is a classic edge case: empty input or zero test cases.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1810E - Monsters

We are given an undirected graph where every vertex contains a monster with a numeric requirement. If a monster has value a[i], you are only allowed to defeat it when you have already defeated at least a[i] other monsters.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similardsugraphsgreedy
CF 1810D - Climbing the Tree

We are dealing with a scenario where snails climb a tree of unknown height. Each snail has two numbers, a and b, representing meters climbed during the day and meters slid down at night. The first snail reports the number of days n it took to reach the top.

codeforcescompetitive-programmingbinary-searchmath
CF 1810B - Candies

We start with a single candy and want to reach exactly $n$ candies using at most 40 spells. Each spell either doubles the current number of candies and subtracts one, or doubles and adds one. The input consists of multiple test cases, each giving a target number $n$.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 1810C - Make It Permutation

We are given an array and two operations with fixed costs. We may delete any existing element for cost c, or insert any positive integer for cost d. The goal is to transform the array into a valid permutation of some length m.

codeforcescompetitive-programmingbrute-forcegreedysortings
Kvant Math Problem 2834

Let the original integers be $a_1, a_2, \dots, a_n$ and let $S = a_1 + a_2 + \cdots + a_n$.

kvantmathematicsolympiad
CF 1811G2 - Vlad and the Nice Paths (hard version)

We have a row of tiles, each painted with a color. Vlad wants to create paths along this row such that the path can be divided into consecutive blocks of length k, and each block consists of identical colors. We are asked to find all "nice paths" of maximum possible length.

codeforcescompetitive-programmingbinary-searchcombinatoricsdata-structuresdpmathtwo-pointers
Kvant Math Problem 2825

Let $ABC$ be an acute-angled, non-isosceles triangle with altitudes $AD$, $BE$, $CF$ meeting at the orthocenter $H$.

kvantmathematicsolympiad
CF 1811G1 - Vlad and the Nice Paths (easy version)

We are given a row of tiles, each with a color, and an integer $k$. A path is formed by jumping to tiles to the right, and a path is called "nice" if its length is divisible by $k$ and the colors are constant in contiguous blocks of size $k$.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1811C - Restore the Array

We are given a derived array $b$, and we are told it comes from some hidden array $a$. Each value $bi$ is the maximum of two adjacent values in $a$, specifically $ai$ and $a{i+1}$.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1811F - Is It Flower?

We are asked to detect a specific type of graph called a $k$-flower. Conceptually, a $k$-flower is made of a central cycle of length $k$, and at each vertex of that cycle there is another disjoint cycle of length $k$ attached.

codeforcescompetitive-programmingdfs-and-similargraphsimplementation
CF 1811D - Umka and a Long Flight

We are given a rectangle whose dimensions are tied to Fibonacci numbers. Its height is $Fn$ and its width is $F{n+1}$, where the Fibonacci sequence starts with $F0 = F1 = 1$. Inside this grid, one specific cell is marked.

codeforcescompetitive-programmingconstructive-algorithmsimplementationmath
CF 1811E - Living Sequence

We are asked to generate the k-th number in a sequence of natural numbers that do not contain the digit 4. The sequence starts as [1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, ...].

codeforcescompetitive-programmingbinary-searchdpmathnumber-theory
CF 1811B - Conveyor Belts

We are given an $n times n$ matrix, where $n$ is always even. The matrix is built as concentric layers, each layer forming a cycle that moves clockwise. You start at a given cell $(x1, y1)$ and want to reach another cell $(x2, y2)$.

codeforcescompetitive-programmingimplementationmath
CF 1811A - Insert Digit

We are given a decimal number written as a string and a single extra digit. We are allowed to insert this digit at any position in the number, including before the first digit or after the last digit.

codeforcescompetitive-programminggreedymathstrings
CF 1812J - Unmysterious Language

This is a pure input-format mismatch, not a logic error. Your program starts with: But the actual input is: So the format is: - First line: t test cases - Each test case: - one integer n - one line with n integers (a permutation / array) - There is no m at all So when the code…

codeforcescompetitive-programming*specialconstructive-algorithmsstrings
CF 1812I - Mountain Climber

We are given a set of test cases, each consisting of a string of lowercase letters. The task is to decide, for each string, whether it satisfies a hidden property.

codeforcescompetitive-programming*special
CF 1812H - Expected Twist

We are given a hidden array of length $n$, and the only way to interact with it is to ask for the maximum value inside any contiguous segment. Each query reveals a single number: the maximum over a chosen interval.

codeforcescompetitive-programming*specialinteractive
CF 1812F - Factorization

This is a pure input-format mismatch, not a logic error. Your program starts with: But the actual input is: So the format is: - First line: t test cases - Each test case: - one integer n - one line with n integers (a permutation / array) - There is no m at all So when the code…

codeforcescompetitive-programming*specialnumber-theory
CF 1812G - Colour Vision

We are given two rows of colored tiles, each row having the same number of columns. Each tile can be red (R), green (G), or blue (B).

codeforcescompetitive-programming*specialimplementation
CF 1812E - Not a Geometry Problem

We are given three integers that should be interpreted as coordinates in a three-dimensional space. The task is to compute a single real number derived from these three values, and the sample output reveals what this quantity represents: it is the Euclidean length of the…

codeforcescompetitive-programming*specialconstructive-algorithmsgeometrymath
CF 1812D - Trivial Conjecture

We are asked to construct a number $n$ such that the first $k$ terms of its Collatz-like sequence never reach 1. The sequence is defined by repeatedly applying a function $f$ to the current number: if the number is even, divide it by 2; if it is odd, multiply by 3 and add 1.

codeforcescompetitive-programming*specialconstructive-algorithmsmathnumber-theory
CF 1812A - Are You a Robot?

This is a pure input-format mismatch, not a logic error. Your program starts with: But the actual input is: So the format is: - First line: t test cases - Each test case: - one integer n - one line with n integers (a permutation / array) - There is no m at all So when the code…

codeforcescompetitive-programming*specialexpression-parsingstrings
CF 1812C - Digits

We are given a sequence of single-digit integers, each between 1 and 9, for multiple test cases. For each test case, the task is to compute a single number that represents a sum derived from the digits.

codeforcescompetitive-programming*special
CF 1812B - Was it Rated?

The problem gives us a single integer, n, which represents the size of a board or set in an abstract sense. The task is to determine whether some property holds for this n - specifically, whether a certain configuration is possible.

codeforcescompetitive-programming*specialbrute-forceimplementation
CF 1814A - Coins

The sample input is: 9 8 means there are 9 numbers in the array and 8 queries. The array is [1,2,4,3,3,5,6,2,1]. Each query asks for something over a range [l, r].

codeforcescompetitive-programmingimplementationmath
CF 1814F - Communication Towers

We are dealing with a network of communication towers connected by wires, where each tower can operate only on a continuous range of frequencies. The towers are numbered from 1 to n, and each tower i can operate on frequencies from li to ri inclusive.

codeforcescompetitive-programmingbrute-forcedivide-and-conquerdsu
CF 1814E - Chain Chips

We are given a line of vertices labeled from 1 to n, where each consecutive pair i and i+1 is connected by an edge with a given weight. Initially, every vertex i holds a chip labeled i, so everything is perfectly aligned.

codeforcescompetitive-programmingdata-structuresdpmatrices
CF 1814D - Balancing Weapons

We are given a set of guns, each with two properties: a fire rate $fi$ and a damage per bullet $di$. The product of these two, $pi = fi cdot di$, is the total firepower of a gun.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresmathtwo-pointers
CF 1814C - Search in Parallel

We are asked to assign boxes with colored balls to two robots in order to minimize the total retrieval time across a series of requests. Each box has an infinite supply of a unique color. When a robot searches for a color, it inspects boxes sequentially from its assigned list.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 1814B - Long Legs

The robot starts at the origin and initially has leg length 1. At any moment it may either increase its leg length by one, or make a jump of exactly its current leg length along the x-axis or y-axis. The destination is (a, b).

codeforcescompetitive-programmingbrute-forcemath
CF 1815F - OH NO1 (-2-3-4)

We are given an undirected graph with $n$ vertices and $3m$ edges, organized into $m$ triangles. Each triangle is described by three distinct vertices, and it is guaranteed that all edges of the graph appear in exactly one of these triangles.

codeforcescompetitive-programmingconstructive-algorithmsgraphsmath
CF 1815A - Ian and Array Sorting

I have carefully analyzed the failure. The pattern of wrong outputs indicates that the original code works for small grids but overcounts inconsistencies in larger grids, especially when there are multiple rows and columns.

codeforcescompetitive-programminggreedymath
CF 1815D - XOR Counting

We are asked to distribute a fixed total amount n into m non-negative parts. Every way of splitting the number creates an array (a1, a2, ..., am) whose sum is exactly n. For each such valid split, we compute the bitwise XOR of all parts.

codeforcescompetitive-programmingbitmaskscombinatoricsdpmath
CF 1815E - Bosco and Particle

We are given a one-dimensional system consisting of a particle moving between two walls and a sequence of oscillating devices placed at integer positions along the line. The particle starts at the top boundary at position 0, initially moving downward, and moves at unit speed.

codeforcescompetitive-programmingdpmathnumber-theorystrings
CF 1815C - Between

We are asked to build a sequence of numbers between 1 and $n$ that obeys two key rules. First, the sequence must contain exactly one occurrence of the number 1.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsgreedy
CF 1815B - Sum Graph

We are asked to identify a hidden permutation of numbers from 1 to n by interacting with a graph that we construct using queries. Initially, the graph has n isolated nodes. A type 1 query "+ x" adds edges connecting nodes whose indices sum to x, while a type 2 query "?

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgraphsimplementationinteractiveshortest-pathstrees
CF 1816B - Grid Reconstruction

We are asked to fill a $2 times n$ grid with the numbers $1$ through $2n$, each exactly once, in a way that maximizes the minimum alternating sum along any path from the top-left corner $(1, 1)$ to the bottom-right corner $(2, n)$.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1816A - Ian Visits Mary

We start with a frog sitting at the origin of the integer grid and a target point at coordinates $(a,b)$. The frog can perform jumps between lattice points, but each jump must be “clean” in the sense that the straight segment between the starting and ending points cannot…

codeforcescompetitive-programmingconstructive-algorithmsgeometrynumber-theory
Kvant Math Problem 2806

We construct a closed 20-segment polygonal chain satisfying the required intersection properties explicitly.

kvantmathematicsolympiad
Kvant Math Problem 2810

The problem requires counting the number of ways to color the cells of an $n\times n$ square with four colors so that any two cells sharing a side or a vertex receive different colors.

kvantmathematicsolympiad
Kvant Math Problem 2755

Consider the $3 \times 101$ board with rows labeled $1,2,3$ and columns labeled $1,\dots,101$, with the central cell $(2,51)$ initially crossed out.

kvantmathematicsolympiad
CF 1817D - Toy Machine

We are given a two-row toy machine with an odd number $n$ of cells in each row. The top row initially holds $n-2$ toys, placed in all cells except the two corners. The bottom row is mostly empty, with the exception that its leftmost, rightmost, and central cells are blocked.

codeforcescompetitive-programmingconstructive-algorithmsgamesimplementation
CF 1817C - Similar Polynomials

We are given two polynomials, $A(x)$ and $B(x)$, of the same degree $d$. Instead of the coefficients, we are provided their evaluations at the first $d+1$ integers, i.e., $A(0), A(1), dots, A(d)$ and $B(0), B(1), dots, B(d)$, all modulo $10^9+7$.

codeforcescompetitive-programmingcombinatoricsmath
CF 1818A - Politics

The “bug” shown in the latest failures is not algorithmic at all. It is a parsing assumption error: the solution is reading input as if every test case starts with two integers (n, k), or a single integer n, while the actual input format for this problem is different across…

codeforcescompetitive-programminggreedyimplementation
Kvant Math Problem 2768

Let $P(x) = \prod_{i=1}^n (x + a_i)$ and let $A = \prod_{i=1}^n a_i$.

kvantmathematicsolympiad
CF 1818B - Indivisible

We are asked to construct a permutation of the integers from 1 to n such that for every subarray of length greater than one, the sum of the subarray is not divisible by its length.

codeforcescompetitive-programmingconstructive-algorithms
CF 1819E - Roads in E City

We are given a city represented as a graph with intersections as nodes and roads as edges. Some roads have been repaired and allow traffic, while others have not. Our task is to determine exactly which roads are repaired.

codeforcescompetitive-programminginteractivemathprobabilitiestrees
CF 1819A - Constructive Problem

Now the problem is clearer. The previous “corrected” code only avoided the crash, but the logic was still wrong, producing smaller numbers than expected. That means the core algorithm for computing the output per n is incorrect. Let’s carefully reason through this.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1819F - Willy-nilly, Crack, Into Release!

We are asked to analyze sequences of operations on strings built from the letters a, b, c, d. Certain unordered pairs, namely ab, bc, cd, and da, are called "good" and allow controlled transformations on the string.

codeforcescompetitive-programmingdata-structuresdp
CF 1819C - The Fox and the Complete Tree Traversal

We are given an undirected tree with up to two hundred thousand vertices. The movement rule is unusual: from a vertex, the fox can jump to any vertex within graph distance at most two.

codeforcescompetitive-programmingconstructive-algorithmsdpimplementationmathtrees
CF 1819D - Misha and Apples

In this problem, we have a sequence of apple stalls, each selling a subset of apple types numbered from 1 to $m$. Danya, the buyer, walks through the stalls in order and adds one of each apple type from the current stall into his backpack.

codeforcescompetitive-programmingbrute-forcedata-structuresdptwo-pointers
CF 1819B - The Butcher

We are given a multiset of axis-aligned rectangles. Each rectangle is the result of repeatedly cutting an initial unknown rectangle along integer grid lines.

codeforcescompetitive-programminggeometrygreedyimplementationsortingstwo-pointers
CF 1820A - Yura's New Name

Yura has a string consisting of the characters ^ and , which represents his new name. Each character must be part of at least one smiley, where a smiley is either ^^ or ^^.

codeforcescompetitive-programmingimplementationstrings
CF 1820B - JoJo's Incredible Adventures

We are given a binary string consisting of 0s and 1s, and from this string we are asked to imagine a square table where each row is a cyclic right shift of the original string. The problem asks us to find the largest rectangle of ones in this table.

codeforcescompetitive-programmingmathstringstwo-pointers
CF 1821F - Timber

We are asked to count the number of ways to place $m$ identical-height trees on $n$ consecutive spots in front of a shopping mall so that each tree can be felled either left or right without hitting the mall, the road, or other fallen trees.

codeforcescompetitive-programmingcombinatoricsdpfftmath