brain

tamnd's digital brain — notes, problems, research

43815 notes

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
CF 1821D - Black Cells

We have a huge one-dimensional grid of cells, indexed from 0 to $10^{18}-1$. Each cell starts white, and we control a pointer initially at cell 0. The pointer can move one step to the right at a time.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedymath
CF 1821E - Rearrange Brackets

We are given a sequence of parentheses that is already regular, meaning it can be fully matched into pairs without any leftover. The sequence could be something like ()(), ((())), or more complex nestings.

codeforcescompetitive-programmingbrute-forcedpgreedysortingsstrings
CF 1821C - Tear It Apart

Thanks for providing the new failing sample. This is a different problem from the earlier input parsing bug. The code now runs, but produces wrong output, so it is a logic error in the algorithm itself. Let's analyze carefully.

codeforcescompetitive-programmingbrute-forceimplementationmathstrings
CF 1821B - Sort the Subarray

We are given two arrays of integers, the original array a and a modified array a'. The modification consists of selecting a contiguous subarray of a and sorting it in non-descending order to produce a'.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1821A - Matching

We are given a string consisting of digits and question marks. Each question mark represents an unknown digit, and we want to count all positive integers that can be formed by replacing the question marks with digits such that the resulting number has no leading zeros.

codeforcescompetitive-programmingcombinatoricsmath
CF 1822G2 - Magic Triples (Hard Version)

We are asked to count the number of triples of indices in an array where each triple is "magic" according to a multiplicative pattern. Specifically, a triple $(i, j, k)$ is magic if $aj$ is some integer multiple $b$ of $ai$ and $ak$ is the same multiple $b$ of $aj$.

codeforcescompetitive-programmingbrute-forcedata-structuresmathnumber-theory
CF 1822G1 - Magic Triples (Easy Version)

We are given a sequence of integers and asked to count the number of triples of indices $(i, j, k)$ such that each index is distinct and there exists a positive integer $b$ where multiplying the value at $i$ by $b$ gives the value at $j$, and multiplying the value at $j$ by…

codeforcescompetitive-programmingbrute-forcedata-structuresmathnumber-theory
CF 1822C - Bun Lover

Each person contributes one of three things: A fixed seat request consumes exactly one seat and pins structure. A -1 person can always be used to extend a segment outward from the current left boundary.

codeforcescompetitive-programmingmath
CF 1822F - Gardening Friends

We are given a tree rooted at vertex 1, where every edge has the same length. The “cost” of the tree is simply how far the farthest vertex is from the current root. Because all edges have identical weight, this cost is just the height of the tree times the edge length.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpgraphstrees
CF 1822E - Making Anti-Palindromes

We are given a string consisting of lowercase English letters, and we want to transform it into an anti-palindrome using the minimum number of character swaps.

codeforcescompetitive-programminggreedymathstrings
CF 1822D - Super-Permutation

We are given a sequence of integers from 1 to n arranged in some order, and we interpret it as a permutation. From this permutation, we construct a running sum array where each position stores the prefix sum of the permutation, reduced modulo n.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1822A - TubeTube Feed

The feed can be thought of as a linear list of videos, each with two attributes: how long it takes to watch and how enjoyable it is. Mushroom Filippov starts at the first video and can move rightwards through the list, spending one second per step to skip to the next item.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1822B - Karina and Array

We are given an array of integers and we are allowed to delete any subset of elements while preserving the relative order of what remains.

codeforcescompetitive-programminggreedymathsortings
CF 1823F - Random Walk

We are given a tree where a chip performs a random walk that stops only when it reaches a designated target vertex $t$.

codeforcescompetitive-programmingdpgraphsmathprobabilitiestrees
CF 1823B - Sort with Step

I have carefully analyzed the failures. The previous solutions were trying to use “next greater/previous greater element” to compute contributions, but that approach is not the correct algorithm for the Easy Version of Codeforces 1827B1.

codeforcescompetitive-programmingbrute-forcemathsortings
CF 1823D - Unique Palindromes

We are asked to construct a string of length n such that certain prefixes of the string contain exactly a given number of unique palindromic substrings. Each prefix is defined by a length xi, and the number of unique palindromes it should contain is ci.

codeforcescompetitive-programmingconstructive-algorithmsmathstrings
CF 1823E - Removing Graph

We are asked to determine the winner in a two-player game played on a special type of graph. The graph has each vertex of degree exactly 2, which immediately tells us that every connected component is either a cycle or a simple loop. There are no self-loops or multiple edges.

codeforcescompetitive-programmingbrute-forcedpgamesgraphsmath
CF 1823C - Strongly Composite

We are given several test cases. In each test case, there is an array of integers, and the total product of all numbers in this array is fixed.

codeforcescompetitive-programminggreedymathnumber-theory
CF 1823A - A-characteristic

We are asked to construct an array of length $n$ consisting only of 1s and -1s such that the number of pairs of indices $i < j$ with equal elements (both 1 or both -1) is exactly $k$. This number of pairs is referred to as the array's $A$-characteristic.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsmath
CF 1824E - LuoTianyi and Cartridge

We are given a tree with n vertices, where each vertex has two attributes, ai and bi. Each edge also has two attributes, cj and dj.

codeforcescompetitive-programmingdata-structurestrees
CF 1824A - LuoTianyi and the Show

We have a row of m seats and n people who want to occupy them, each with a fixed type of preference. Some people insist on sitting at a specific numbered seat.

codeforcescompetitive-programminggreedyimplementation
CF 1824D - LuoTianyi and the Function

We are given an array of integers a of length n, indexed from 1. For any subarray defined by indices i through j, we define a function g(i, j) as the largest integer x such that the set of elements from position i to j is contained in the set of elements from x to j.

codeforcescompetitive-programmingdata-structures
CF 1824C - LuoTianyi and XOR-Tree

We are given a tree with n vertices, each labeled with a non-negative integer. The root is vertex 1. The goal is to modify as few vertex values as possible so that the XOR of values along every path from the root to any leaf equals zero.

codeforcescompetitive-programmingdata-structuresdfs-and-similardpdsugreedytrees
CF 1824B1 - LuoTianyi and the Floating Islands (Easy Version)

We are given a tree with $n$ nodes representing islands. On this tree, $k$ distinct nodes are chosen uniformly at random to host people. For any fixed configuration of these $k$ nodes, every island can compute the total distance to all chosen nodes.

codeforcescompetitive-programmingcombinatoricsmathprobabilitiestrees
CF 1824B2 - LuoTianyi and the Floating Islands (Hard Version)

We are given a tree with $n$ nodes. Then we choose $k$ distinct nodes uniformly at random, and place one “person” on each of them.

codeforcescompetitive-programmingcombinatoricsdfs-and-similarmathprobabilitiestrees
CF 1825E - LuoTianyi and XOR-Tree

We are given a rooted tree with n vertices, each labeled with a non-negative integer. The root is vertex 1. We are allowed to change the value of any vertex to any non-negative integer, and our goal is to minimize the number of changes required so that the bitwise XOR of the…

codeforcescompetitive-programmingdata-structuresdpdsugreedytrees
CF 1825D1 - LuoTianyi and the Floating Islands (Easy Version)

We are given a tree with $n$ nodes, representing islands connected by $n-1$ bidirectional routes. From this tree, we randomly choose $k$ distinct nodes, where $k le 3$. These chosen nodes represent the locations of people.

codeforcescompetitive-programmingcombinatoricsdpmathtrees
CF 1825D2 - LuoTianyi and the Floating Islands (Hard Version)

We have a set of $n$ islands connected in a tree structure. That means any two islands are connected by exactly one path, and there are $n-1$ edges. LuoTianyi wants to meet $k$ friends, each located on a distinct island.

codeforcescompetitive-programmingcombinatoricsdfs-and-similarmathtrees
CF 1825C - LuoTianyi and the Show

We are given a row of seats numbered from 1 to $m$ and $n$ people arriving in a show. Each person has a preferred seating type: they either want to sit immediately to the left of the leftmost occupied seat, immediately to the right of the rightmost occupied seat, or in a…

codeforcescompetitive-programminggreedysortings
CF 1825B - LuoTianyi and the Table

We are given a flat list of n m integers and asked to fill them into an n-by-m table. After filling, we compute a sum over all submatrices that start at the top-left corner (1,1) and end at each position (i,j).

codeforcescompetitive-programminggreedymath
CF 1825A - LuoTianyi and the Palindrome String

We are given a string that is guaranteed to be a palindrome. The task is to find the longest subsequence of this string that is not a palindrome.

codeforcescompetitive-programminggreedystrings
CF 1826B - Lunatic Never Content

I have carefully examined the problem and the previous attempts. The algorithm itself - iterating over all subarrays, keeping a running currentmin and currentmax, and adding currentmax - currentmin - is correct for the easy version of the problem.

codeforcescompetitive-programmingmathnumber-theory
CF 1826F - Fading into Fog

We are asked to find a set of hidden points on a 2D plane using queries that return projections of all points onto a line of our choice. Each query gives us the locations of these projections along the line, with slight precision errors.

codeforcescompetitive-programminggeometryinteractivemathprobabilities
CF 1826E - Walk the Runway

We are given a sequence of runway shows across multiple cities, each with its own ranking of models. There are n models and m cities. Each model has a profit value, and each city gives a rating to each model.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresdpgraphsimplementationsortings
CF 1826D - Running Miles

We are given a linear street with n sights, each at a specific mile marker from the start. Each sight has an associated beauty score.

codeforcescompetitive-programmingbrute-forcedpgreedy