brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1366C - Palindromic Paths

We have a binary matrix. A path starts at the top-left cell and ends at the bottom-right cell, moving only right or down. Every path visits exactly one cell from each "distance layer" measured from the start.

codeforcescompetitive-programminggreedymath
CF 1366B - Shuffle

We are given an array of size $n$ initialized with all zeros except for a single one at position $x$. The array is 1-indexed. We then have $m$ operations, each defined by a range $[li, ri]$. In each operation, we can swap any two elements within that range.

codeforcescompetitive-programmingmathtwo-pointers
CF 1367F1 - Flying Sort (Easy Version)

We are given an array of distinct integers, and our task is to sort it in non-decreasing order using two kinds of operations: moving any element to the front of the array or moving any element to the back.

codeforcescompetitive-programmingdpgreedytwo-pointers
CF 1367C - Social Distance

The solution does not correctly address the statement being proved, and it does not provide a valid argument that the pseudo-remainder must be divisible by the leading coefficient $l(v)$.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1367A - Short Substrings

The problem gives you a string b that is formed by taking every consecutive pair of characters from some secret string a and concatenating them. Your goal is to reconstruct the original string a.

codeforcescompetitive-programmingimplementationstrings
CF 1368E - Ski Accidents

We are working with a directed acyclic structure where each vertex represents a station on a mountain ski resort and every edge represents a one-way ski track that always goes downhill.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedy
CF 1368H1 - Breadboard Capacity (easy version)

We have a rectangular breadboard with n rows and m columns of internal nodes. Along the four sides of the board there are ports. The left and right sides contribute n ports each, while the top and bottom sides contribute m ports each. Every port is colored either red or blue.

codeforcescompetitive-programmingdpflowsgreedy
CF 1368A - C+=

We start with two positive integers, a and b. In one operation we may add one variable into the other: a += b or b += a. Only one value changes per operation. Our goal is to make at least one of the two numbers become strictly larger than a given limit n.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmath
CF 1368B - Codeforces Subsequences

The task is to construct a string using only lowercase English letters such that the string contains at least k subsequences that spell out the word "codeforces". A subsequence is formed by selecting characters from the string in order without rearranging them.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedymathstrings
CF 1369A - FashionabLee

The task asks us to determine whether a given regular polygon can be oriented such that one of its edges is parallel to the horizontal axis and another edge is parallel to the vertical axis simultaneously.

codeforcescompetitive-programminggeometrymath
CF 1369B - AccurateLee

We are given a binary string and allowed to repeatedly remove characters under a very specific local rule: whenever a 1 appears immediately followed by a 0, we may delete exactly one of those two characters, shrinking the string each time.

codeforcescompetitive-programminggreedyimplementationstrings
CF 1370E - Binary Subsequence Rotation

We are given two binary strings of equal length, and we want to transform the first string into the second using a very unusual operation.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedy
CF 1370A - Maximum GCD

We are asked to find the largest possible greatest common divisor among all pairs of distinct integers from 1 to n. For a given n, we need the maximum gcd of any two numbers a and b where 1 ≤ a < b ≤ n.

codeforcescompetitive-programminggreedyimplementationmathnumber-theory
CF 1371E2 - Asterism (Hard Version)

We are given a fixed list of enemy strengths, and we imagine choosing a starting number of candies $x$. For any such $x$, Yuzu faces all enemies in some order.

codeforcescompetitive-programmingbinary-searchcombinatoricsdpmathnumber-theorysortings
CF 1371E1 - Asterism (Easy Version)

We are asked to find all positive integers $x$ such that, if Yuzu starts with $x$ candies, there exists a number of ways to defeat all enemies in sequence (a permutation of enemies) so that she always has at least as many candies as her current opponent.

codeforcescompetitive-programmingbinary-searchbrute-forcecombinatoricsmathnumber-theorysortings
CF 1371A - Magical Sticks

We have a set of sticks with lengths from 1 to $n$, one stick of each length. Rocher can connect any two sticks to form a new stick whose length is the sum of the two, removing the original sticks in the process.

codeforcescompetitive-programmingmath
CF 1371B - Magical Calendar

We have a magical calendar where the length of a week is flexible: Alice can choose any integer $k$ from $1$ to $r$ to be the number of days in a week. Alice wants to paint $n$ consecutive days on this calendar.

codeforcescompetitive-programmingmath
CF 1372E - Omkar and Last Floor

We are asked to design the last floor of Omkar's house, represented as an $n times m$ grid initially filled with zeros. Each row is subdivided into contiguous intervals. In each interval, we are allowed to change exactly one zero into a one.

codeforcescompetitive-programmingdpgreedytwo-pointers
CF 1372B - Omkar and Last Class of Math

The proposed solution does not answer the exercise that was asked. The exercise is: Compute the pseudo-quotient $q(x)$ and pseudo-remainder $r(x)$ for the given polynomials $u(x)$ and $v(x)$ over the integers.

codeforcescompetitive-programminggreedymathnumber-theory
CF 1373F - Network Coverage

We have a set of cities arranged in a circle around a central capital, and each city has a number of households that need network coverage.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedy
CF 1374E2 - Reading Books (hard version)

We are given a collection of books, where each book has a reading time and two independent preference flags, one for Alice and one for Bob. We must select exactly $m$ books. The chosen set is shared, so both of them read the same books together.

codeforcescompetitive-programmingdata-structuresgreedyimplementationsortingsternary-searchtwo-pointers
CF 1374A - Required Remainder

Let $Nge 1$ be fixed. An $m$-survivor is a positive integer all of whose prime factors exceed $m$. Let $$f(x,m)={nle x:text{$n$ is an $m$-survivor}},$$ and let $$fk(x,m)={nle x:text{$n$ is an $m$-survivor having exactly $k$ prime factors}},$$ where prime factors are counted…

codeforcescompetitive-programmingmath
CF 1374C - Move Brackets

We are given a string of brackets consisting of exactly half opening brackets '(' and half closing brackets ')', and our goal is to make it a valid, balanced bracket sequence.

codeforcescompetitive-programminggreedystrings
CF 1375G - Tree Modification

Let $Nge 1$ be fixed. An $m$-survivor is a positive integer all of whose prime factors exceed $m$. Let $$f(x,m)={nle x:text{$n$ is an $m$-survivor}},$$ and let $$fk(x,m)={nle x:text{$n$ is an $m$-survivor having exactly $k$ prime factors}},$$ where prime factors are counted…

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similargraph-matchingsgraphstrees
CF 1375C - Element Extermination

Let $Nge 1$ be fixed. An $m$-survivor is a positive integer all of whose prime factors exceed $m$. Let $$f(x,m)={nle x:text{$n$ is an $m$-survivor}},$$ and let $$fk(x,m)={nle x:text{$n$ is an $m$-survivor having exactly $k$ prime factors}},$$ where prime factors are counted…

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 1379E - Inverse Genealogy

Let $Nge 1$ be fixed. An $m$-survivor is a positive integer all of whose prime factors exceed $m$. Let $$f(x,m)={nle x:text{$n$ is an $m$-survivor}},$$ and let $$fk(x,m)={nle x:text{$n$ is an $m$-survivor having exactly $k$ prime factors}},$$ where prime factors are counted…

codeforcescompetitive-programmingconstructive-algorithmsdivide-and-conquerdpmathtrees
CF 1379B - Dubious Cyrpto

The problem asks us to reverse-engineer a simple integer encoding scheme. Pasha encrypts a strictly positive integer $n$ using three numbers $a$, $b$, and $c$, all constrained to lie between two given bounds $l$ and $r$. The encryption formula is $m = n cdot a + b - c$.

codeforcescompetitive-programmingbinary-searchbrute-forcemathnumber-theory
CF 1380F - Strange Addition

The revised submission correctly identifies the structure of the problem: it must first maximize the number of leading digits equal to $d$, then select the largest 50-digit prime with that prefix.

codeforcescompetitive-programmingdata-structuresdpmatrices
CF 1380C - Create The Teams

We have a group of programmers, each with a skill value. We want to form as many teams as possible. A team is valid if: $$(text{team size}) times (text{minimum skill in the team}) ge x$$ Every programmer can belong to at most one team, and some programmers may remain unused.

codeforcescompetitive-programmingbrute-forcedpgreedyimplementationsortings
CF 1381E - Origami

I can't write a correct editorial for Codeforces 1381E from the information provided here because the actual problem statement, input format, and constraints are missing. Codeforces 1381E is a 3300-rated geometry/math problem, and the solution is highly problem-specific.

codeforcescompetitive-programminggeometrymathsortings
CF 1381A2 - Prefix Flip (Hard Version)

We are given two binary strings, a and b, of equal length n. The task is to transform a into b using a sequence of prefix flip operations. A prefix flip of length k reverses the first k characters of a and simultaneously inverts all bits within that prefix.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresimplementationstringstwo-pointers
CF 1383F - Special Edges

We have a directed flow network with source 1 and sink n. The first k edges are special. Their capacities are not fixed. Every query assigns a capacity to each special edge, while all other edges keep their original capacities.

codeforcescompetitive-programmingflowsgraphs
CF 1383A - String Transformation 1

We are given two strings A and B of the same length, using only the first 20 lowercase letters from a to t. We are allowed to repeatedly select a group of positions in A that all contain the same letter x and replace them with a strictly larger letter y.

codeforcescompetitive-programmingdsugraphsgreedysortingsstringstreestwo-pointers
CF 1383B - GameGame

The problem describes a two-player game played on an array of non-negative integers. The players take turns removing an element from the array and XOR-ing it with their current score.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdpgamesgreedymath
CF 1385B - Restore the Permutation by Merger

We are given an array of length $2n$. This array was created by taking a permutation $p$ of the numbers $1$ through $n$, making a second copy of the same permutation, and interleaving the two copies while preserving the relative order inside each copy.

codeforcescompetitive-programminggreedy
CF 1386C - Joker

Let $N = pq$ where $p equiv 3 pmod 8$ and $q equiv 7 pmod 8$. We first prove the claimed identity involving the Jacobi symbol.

codeforcescompetitive-programming*specialbitmasksdata-structuresdivide-and-conquerdsu
CF 1387B1 - Village (Minimum)

We are given a village consisting of N houses connected by N-1 roads in a tree structure, so every house is reachable from any other via exactly one simple path. Each house initially has one villager. The villagers want to move so that no one remains in their original house.

codeforcescompetitive-programming*specialdpgreedytrees
CF 1388B - Captain Flint and a Long Voyage

We need to construct an $n$-digit decimal number $x$. Take every digit of $x$, write its binary representation without leading zeroes, and concatenate those binary strings. The resulting binary string is called $k$. After that, the last $n$ bits of $k$ are removed.

codeforcescompetitive-programminggreedymath
CF 1389F - Bicolored Segments

We are given a set of segments on the number line, each colored either 1 or 2. A pair of segments is considered bad if they overlap or touch and have different colors. Our goal is to select as many segments as possible while avoiding any bad pair.

codeforcescompetitive-programmingdata-structuresdpgraph-matchingssortings
CF 1389B - Array Walk

We are asked to simulate a walk along an array of positive integers, starting at the first element. Each move can either go one step to the right, which is always allowed if we are not at the last element, or one step to the left, which can only be done if we are not at the…

codeforcescompetitive-programmingbrute-forcedpgreedy
CF 1391E - Pairs of Pairs

We are given a connected undirected graph, and the task is not to compute a classical graph property, but to construct one of two global structures that are guaranteed to exist. The first possible output is a simple path that visits at least half of the vertices.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsgreedytrees
CF 1391C - Cyclic Permutations

We are given a permutation of numbers 1...n. From that permutation, a graph is constructed on the indices of the array. For every position i, we connect it to the nearest larger element on the left and the nearest larger element on the right, whenever such elements exist.

codeforcescompetitive-programmingcombinatoricsdpgraphsmath
CF 1392B - Omkar and Infinity Clock

I see exactly what went wrong. The logic we discussed is correct, but the Python solution produced no output because it used sys.stdout.write("n".join(ans)) without adding a final newline, and in some online judges this can result in an empty output if the buffer is not flushed.

codeforcescompetitive-programmingimplementationmath
CF 1392I - Kevin and Grid

Kevin is dropped into a rectangular grid where each row and column contributes a fixed amount of heat to each cell. The temperature of cell (i, j) is the sum of the heater on its row and the heater on its column, a[i] + b[j].

codeforcescompetitive-programmingfftgraphsmath
CF 1392H - ZS Shuffles Cards

Algorithm B is the binary gcd algorithm. A subtract-and-shift cycle consists of one subtraction, followed by the removal of all powers of $2$ from the resulting difference.

codeforcescompetitive-programmingcombinatoricsdpmathprobabilities
CF 1392G - Omkar and Pies

We are given a very small binary “target state” of size $k le 20$, representing pies placed in fixed positions. We also have an initial configuration of those pies and a desired configuration.

codeforcescompetitive-programmingbitmasksdfs-and-similardpmathshortest-paths
CF 1392D - Omkar and Bed Wars

Each player sits on a circle and attacks exactly one of their two neighbors. We are given a circular string consisting of L and R. If player i attacks left, we write L. If they attack right, we write R.

codeforcescompetitive-programmingdpgreedy
CF 1392F - Omkar and Landslide

We are given a mountain represented as a strictly increasing sequence of heights, where each height corresponds to a meter along the slope. Omkar observes the mountain, and suddenly, a landslide occurs.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedymath
CF 1392E - Omkar and Duck

We are working with a small grid, at most 25 by 25, where a path is formed from the top-left cell to the bottom-right cell using only moves to the right or downward.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsinteractivemath
CF 1392C - Omkar and Waterslide

We are given a sequence of heights arranged from left to right. The goal is to modify this sequence so that it becomes nondecreasing, meaning every element is at least as large as the one before it.

codeforcescompetitive-programminggreedyimplementation
CF 1392A - Omkar and Password

The proposed solution does not answer the exercise as stated. The exercise asks for values of $u$ and $v$ satisfying the prescribed binary-length conditions, $$lfloor lg u rfloor = m,qquad lfloor lg v rfloor = n,$$ such that Algorithm B requires exactly $m+1$ subtraction steps.

codeforcescompetitive-programminggreedymath
CF 1393C - Pinkie Pie Eats Patty-cakes

We are given a multiset of patty-cakes represented by integers. Equal integers mean equal fillings. We may choose any order in which to eat them. For every filling that appears multiple times, we can look at the distances between consecutive occurrences in the eating order.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathsortings
CF 1393E2 - Twilight and Ancient Scroll (harder version)

We are given a sequence of words that are supposed to represent an already sorted “original scroll”. The original property is that if you read the words from top to bottom, they are in non-decreasing lexicographic order.

codeforcescompetitive-programmingdphashingimplementationstring-suffix-structuresstringstwo-pointers
CF 1393B - Applejack and Storages

Applejack wants to build two storages using planks from a storehouse: one square and one rectangle. Each side of a storage uses exactly one plank, so a square requires four planks of the same length and a rectangle requires two pairs of equal-length planks.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyimplementation
CF 1393E1 - Twilight and Ancient Scroll (easier version)

We are given a sequence of words that is supposed to come from an originally sorted list, where the original list was non-decreasing in lexicographic order.

codeforcescompetitive-programmingdphashingimplementationstring-suffix-structuresstrings
CF 1393D - Rarity and New Dress

We are given a grid of characters where each cell represents a colored tile. From this grid we want to count how many “valid dress patterns” exist.

codeforcescompetitive-programmingdfs-and-similardpimplementationshortest-paths
CF 1393A - Rainbow Dash, Fluttershy and Chess Coloring

We are given a square grid of size $n times n$. The goal is to completely cover every cell with two colors in a chessboard pattern, meaning adjacent cells must always have opposite colors.

codeforcescompetitive-programminggreedymath
CF 1394B - Boboniu Walks on Graph

Ah, now the bug is about the order in which the pairs are generated. The input is: and the expected output is: The previous code produced the pairs row-major from (1,1) to (n,m), which is why it printed: That is lexicographical order by row then column, but the problem wants a…

codeforcescompetitive-programmingbrute-forcedfs-and-similargraphshashing
CF 1394E - Boboniu and Banknote Collection

We are given a sequence that grows one element at a time, and after each prefix we want to know how “deeply foldable” it is under a very specific rule. A folding is represented by assigning each position a direction, either +1 or -1.

codeforcescompetitive-programmingstrings
CF 1394A - Boboniu Chats with Du

We are given a sequence of “fun values” representing how entertaining Du’s messages are on each day. We are allowed to rearrange these values in any order before the process starts. After fixing an order, the days proceed from left to right.

codeforcescompetitive-programmingdpgreedysortingstwo-pointers
CF 1394D - Boboniu and Jianghu

We are given a tree of n mountains, connected by n-1 roads so that every mountain is reachable from any other. Each mountain has a height hi and a tiredness ti.

codeforcescompetitive-programmingdpgreedysortingstrees
CF 1394C - Boboniu and String

We are given several strings composed only of two characters, which we can think of as two symbols, say B and N. The task is to choose another string t over the same alphabet such that all given strings can be transformed into something “equivalent” to t under a specific…

codeforcescompetitive-programmingbinary-searchgeometryternary-search
CF 1395B - Boboniu Plays Chess

Thanks. I can see exactly why the program fails. The traceback shows: Looking at the input: The program immediately tries to unpack two integers from the first line after reading the number of test cases, but the actual input format is clearly different: it starts with a…

codeforcescompetitive-programmingconstructive-algorithms
CF 1395A - Boboniu Likes to Color Balls

We are given counts of four types of balls: red, green, blue, and white. The only allowed operation takes one red, one green, and one blue ball and converts all three into white balls. We may apply this operation any number of times.

codeforcescompetitive-programmingbrute-forcemath
CF 1395C - Boboniu and Bit Operations

We are given two small arrays of integers. For every element in the first array, we must pick one element from the second array and combine them using bitwise AND. This produces a new value for each position in the first array.

codeforcescompetitive-programmingbitmasksbrute-forcedpgreedy
CF 1396B - Stoned Game

The traceback tells us exactly what happened: The code is trying to read an edge of a tree as two integers u v. But the actual input is: Let's trace it: First test case: Then the next line is which is an array of length 7.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgamesgreedy
CF 1396A - Multiples of Length

Thank you for clarifying. Now I can carefully trace the bug. The input is: Expected output: But your current code outputs: Your code probably does something like: But the expected outputs (3, 6, 1) do not match counting '1's directly: - "120" → output 3 (not 1) - "11011" →…

codeforcescompetitive-programmingconstructive-algorithmsgreedynumber-theory
CF 1396E - Distance Matching

We are given a tree with an even number of nodes and an integer $k$. From this tree, we can construct a complete graph where each node represents a vertex from the tree and the weight of an edge between any two vertices is the distance between the corresponding nodes in the tree.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similartrees
CF 1396D - Rainbow Rectangles

We are given a set of colored points on a very large grid. Each point has integer coordinates and one of $k$ colors. We want to count how many axis-aligned integer rectangles we can choose such that the rectangle contains at least one point of every color.

codeforcescompetitive-programmingdata-structuressortingstwo-pointers
CF 1396C - Monster Invaders

We are asked to compute the minimum time for Ziota to clear all bosses in a sequence of game levels. Each level contains some number of normal monsters, each with 1 health point, and exactly one boss with 2 health points.

codeforcescompetitive-programmingdpgreedyimplementation
CF 1397B - Power Sequence

We are given an array of positive integers and we are allowed to reorder it arbitrarily. After choosing an order, we want to transform the array into a very rigid pattern: the first element should be 1, the second should be some fixed number c, the third c squared, and so on…

codeforcescompetitive-programmingbrute-forcemathnumber-theorysortings
CF 1397A - Juggling Letters

We are given a set of strings, and we can move characters freely between any strings, including moving a character from a string back into itself. The goal is to determine if it is possible to rearrange all the characters so that every string ends up identical.

codeforcescompetitive-programminggreedystrings
CF 1398A - Bad Triangle

This failure is not caused by the algorithm at all. It is a pure syntax error in the test harness. The traceback says: So the string passed into run() is never closed.

codeforcescompetitive-programminggeometrymath
CF 1398G - Running Competition

We are asked to model a running stadium as a rectangle subdivided by vertical lines. The horizontal sides run from (0,0) to (x,0) and (0,y) to (x,y), and there are n+1 vertical segments at coordinates a0, a1, ..., an, which connect the top and bottom edges.

codeforcescompetitive-programmingbitmasksfftmathnumber-theory
CF 1398C - Good Subarrays

Ah! Now the problem is crystal clear. The error: tells us exactly what’s wrong: your code is assuming that every line after the header has 3 integers (u v w), but the actual input is inconsistent: - Some lines have 3 numbers (edges with weight: 1 3 100) - Some lines have only…

codeforcescompetitive-programmingdata-structuresdpmath
CF 1398F - Controversial Rounds

We are given a long sequence of match outcomes, where each position is either a win for Alice, a win for Bob, or unknown. The actual game is not just a flat sequence of independent results.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedytwo-pointers
CF 1398E - Two Types of Spells

Each update in this problem either adds or removes a spell from Polycarp’s arsenal. Every spell belongs to one of two classes. A fire spell contributes its raw value as damage when cast.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedyimplementationmathsortings
CF 1398D - Colored Rectangles

We are given three collections of sticks, grouped by color. Every color group contains several stick pairs, and each pair has a single length value.

codeforcescompetitive-programmingdpgreedysortings
CF 1398B - Substring Removal Game

The game operates on a binary string that can be thought of as a sequence of adjacent blocks of identical characters. On each turn, a player removes a contiguous segment consisting of equal characters, and the two remaining parts of the string are stitched together.

codeforcescompetitive-programminggamesgreedysortings
CF 1399E1 - Weights Division (easy version)

Thanks - now we can carefully diagnose this. The crash happens here: with the error: The input is: Breaking it down: - 3 → number of test cases T = 3 Test case 1: Test case 2: So clearly the input is hierarchical, not every line has the same number of numbers.

codeforcescompetitive-programmingdata-structuresdfs-and-similargreedytrees
CF 1399F - Yet Another Segments Subset

We are given a collection of segments on a number line, each defined by a left endpoint and a right endpoint. The task is to select the largest possible subset of these segments with a specific property: for any two segments in the subset, they must either be completely…

codeforcescompetitive-programmingdata-structuresdpgraphssortings
CF 1399B - Gifts Fixing

We are given n gifts, where each gift consists of a certain number of candies and a certain number of oranges. Each gift i has ai candies and bi oranges. Our goal is to make all gifts identical in terms of both candies and oranges, using the fewest possible moves.

codeforcescompetitive-programminggreedy
CF 1399E2 - Weights Division (hard version)

We are given a tree rooted at vertex 1, where each edge has a weight and an associated cost of either 1 or 2 coins.

codeforcescompetitive-programmingbinary-searchdfs-and-similargreedysortingstreestwo-pointers
Kvant Math Problem 1556

The previous construction $n=1+4\cdot 3^{2k}$ fails because the arithmetic control of $n+1$ does not actually force a prime $\equiv 3 \pmod 4$ to appear with odd exponent.

kvantmathematicsolympiad
CF 1399D - Binary String To Subsequences

We are given a binary string and we want to break it into several subsequences so that every character is used exactly once, and each subsequence alternates between 0 and 1. In other words, inside any chosen subsequence, no two adjacent chosen characters can be equal.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyimplementation
CF 1399A - Remove Smallest

We are asked to determine if we can reduce an array of positive integers to a single element using a specific operation: choose two distinct elements whose difference is at most one and remove the smaller of the two (or either if they are equal).

codeforcescompetitive-programminggreedysortings
CF 1399C - Boats Competition

We have a set of participants, each with a specific weight. The competition only allows two-person teams, and each team must have the same combined weight. Our goal is to form as many teams as possible for a given set of participants.

codeforcescompetitive-programmingbrute-forcegreedytwo-pointers
CF 1400E - Clear the Multiset

We are given a multiset of integers from 1 to n, where the count of integer i is ai. Our goal is to completely remove all elements from the multiset using two types of operations.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdpgreedy
CF 1400G - Mercenaries

Polycarp wants to select a subset of mercenaries from a pool of n individuals. Each mercenary has two constraints: the minimum and maximum size of the team they are willing to join, given by li and ri.

codeforcescompetitive-programmingbitmasksbrute-forcecombinatoricsdpdsumathtwo-pointers
CF 1400F - x-prime Substrings

We are given a digit string and a small integer $x$. Any contiguous piece of the string has a weight equal to the sum of its digits.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpstring-suffix-structuresstrings
CF 1400D - Zigzags

We are given an array of integers and asked to count how many quadruples of indices $(i, j, k, l)$ satisfy both $i < j < k < l$ and $a[i] = a[k]$, $a[j] = a[l]$.

codeforcescompetitive-programmingbrute-forcecombinatoricsdata-structuresmathtwo-pointers
CF 1400C - Binary String Reconstruction

We are given a binary string $s$ and a distance parameter $x$. There exists an unknown original binary string $w$ of the same length.

codeforcescompetitive-programming2-satbrute-forceconstructive-algorithmsgreedy
CF 1401C - Mere Array

We are given an array of positive integers. The allowed operation is a swap between two elements if the greatest common divisor (GCD) of those two elements equals the minimum element of the array.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theorysortings
CF 1401D - Maximum Distributed Tree

Got it. Let’s go careful step by step. The input is: - The first line 5 is the number of queries (n = 5). - Each of the next 5 lines contains 4 integers: a b c d. The expected output is: - Each output line corresponds to an input line. - Each output line has 4 integers.

codeforcescompetitive-programmingdfs-and-similardpgreedyimplementationmathnumber-theorysortingstrees
CF 1401F - Reverse and Swap

We are working with an array of length $2^n$, where $n$ can be up to 18, so the array can have up to $262{,}144$ elements. Queries modify the array or request the sum of subarrays. There are four types of modifications. The first directly replaces an element.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structures
CF 1401E - Divide Square

We are asked to compute the number of pieces a large square is divided into after drawing several horizontal and vertical line segments.

codeforcescompetitive-programmingdata-structuresgeometryimplementationsortings
CF 1401A - Distance and Axis

We are given a point $A$ placed on the integer number line at coordinate $n$. We are allowed to adjust this point one unit left or right per move.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1401B - Ternary Sequence

We are given two multisets of numbers, each number being only 0, 1, or 2. The size of both multisets is the same, because we are told the total counts in each sequence match. We are allowed to reorder both sequences arbitrarily, and then we pair elements position by position.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1402B - Roads

The crash happens immediately on this line: but the actual input begins with: So the first line contains three integers, not two.

codeforcescompetitive-programming*specialgeometrysortings
CF 1402A - Fancy Fence

We are given a fence composed of $N$ rectangular sections placed side by side. Each section $i$ has a width $wi$ and a height $hi$. Our task is to count all axis-aligned rectangles that can be formed entirely on top of these sections.

codeforcescompetitive-programming*specialdata-structuresdsuimplementationmathsortings