brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 2043E - Matrix Transformation

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresdfs-and-similargraphsgreedyimplementation
CF 2043D - Problem about GCD

We are asked to find two numbers $A$ and $B$ inside a closed range $[l, r]$ such that their greatest common divisor is exactly $G$, and the distance $ The inputs $l$, $r$, and $G$ can be as large as $10^{18}$, which rules out any solution that iterates through the entire range…

codeforcescompetitive-programmingbrute-forceflowsmathnumber-theory
CF 2043A - Coin Transformation

We start with a single coin whose value is given by an integer $n$. The only allowed move takes a coin whose value is strictly greater than 3, and replaces it with exactly two coins, each having value equal to the floor of one quarter of the original value.

codeforcescompetitive-programmingbrute-forcemath
CF 2043B - Digits

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programmingmathnumber-theory
CF 2043C - Sums on Segments

We are given an array where almost every element is either 1 or -1, with at most one element allowed to be any integer. Our task is to find all distinct sums of contiguous subarrays. The sum of a subarray is simply the sum of its elements.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdpgreedymath
Kvant Math Problem 408

Let the original rectangles have side lengths $a$ and $b$, and let their ratio be $r = \frac{a}{b} > 0$.

kvantmathematicsolympiad
CF 2044H - Hard Demon Problem

We are given an $n times n$ matrix of positive integers and multiple queries, each specifying a rectangular submatrix.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdpimplementationmath
CF 2044G2 - Medium Demon Problem (hard version)

The error in your Python solution is a simple syntax mistake: the map(int, input().split()) call for reading b is missing a closing parenthesis. This prevents the code from running at all. Once that is fixed, the solution logic itself can remain the same.

codeforcescompetitive-programmingdfs-and-similardpdsugraphsimplementationtrees
CF 2044G1 - Medium Demon Problem (easy version)

Each spider chooses exactly one recipient. We can view this as a directed graph where every vertex has out-degree exactly one. Initially every spider owns one plushie. During a year, every spider that currently has a plushie sends one plushie along its outgoing edge.

codeforcescompetitive-programmingdfs-and-similargraph-matchingsgraphsimplementationtrees
CF 2044D - Harder Problem

We are asked to construct an array b from a given array a such that for every prefix of b up to index i, the element a[i] is one of the modes of that prefix.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 2044F - Easy Demon Problem

We are given two arrays, a and b. From them we build an implicit matrix $$M{i,j}=ai bj.$$ The beauty of the matrix is the sum of all its entries.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresmathnumber-theory
CF 2044E - Insane Problem

We are asked to count the number of pairs of integers $(x, y)$ that satisfy two interval constraints and a geometric relationship. Specifically, $x$ must lie in the interval $[l1, r1]$, $y$ must lie in $[l2, r2]$, and $y / x$ must be an integer power of $k$.

codeforcescompetitive-programmingbinary-searchgreedyimplementationmathnumber-theory
CF 2044C - Hard Problem

We are asked to assign monkeys to seats in a classroom with exactly two rows of m seats each. The monkeys come in three categories: a monkeys that will only sit in the first row, b monkeys that will only sit in the second row, and c monkeys that have no preference.

codeforcescompetitive-programminggreedymath
CF 2044B - Normal Problem

We are given a string consisting only of the letters p, q, and w. Ship observes this string from outside a glass window, giving us string a. When Ship moves inside the store and looks through the same window, he sees string b. Our task is to determine what b looks like given a.

codeforcescompetitive-programmingimplementationstrings
CF 2044A - Easy Problem

We are asked to count ordered pairs of positive integers $(a, b)$ such that $a + b = n$, for multiple test cases. Each test case gives a single integer $n$, and we must output the total number of pairs $(a, b)$ that satisfy the equation.

codeforcescompetitive-programmingbrute-forcemath
CF 2045L - Buggy DFS

We are asked to study a variation of Depth First Search (DFS) called Buggy DFS (BDFS). In BDFS, a standard DFS is implemented using an explicit stack, but with a subtle behavior: for every node u popped from the stack, the algorithm increments a counter for every neighbor of u…

codeforcescompetitive-programmingconstructive-algorithms
CF 2045M - Mirror Maze

Think of the laser beam as moving along the grid lines between cells. Whenever the beam enters a cell through one side, the content of that cell determines which side it leaves from. An empty cell does not change direction.

codeforcescompetitive-programmingbrute-forcedfs-and-similargraphsimplementation
CF 2045K - GCDDCG

We are given a deck of $N$ cards, each labeled with an integer value between $1$ and $N$. The game has $N$ rounds.

codeforcescompetitive-programming
CF 2045I - Microwavable Subsequence

Thank you, now the problem is clear. The previous formula: does not always produce the optimal next floor because it computes the largest integer k ≤ (floor+D)//floor, but the next step may allow a smaller multiple of floor that lets a larger final floor later.

codeforcescompetitive-programmingdata-structures
CF 2045J - Xorderable Array

We are given an array of values $A$, and another array $X$. The task is not to modify $A$ directly, but to ask a very specific question about pairs of values from $X$. For any ordered pair $(p, q)$, we are allowed to rearrange the array $A$.

codeforcescompetitive-programmingbitmasksdata-structures
Kvant Math Problem 1557

Let $O$ be the center of the given circle.

kvantmathematicsolympiad
CF 2045H - Missing Separators

We are given a single long string made by writing several unknown words one after another in alphabetical order and then removing all separators. The original structure is a dictionary: words are distinct and sorted lexicographically.

codeforcescompetitive-programmingdpsortingsstring-suffix-structuresstrings
CF 2045E - Narrower Passageway

We are given a grid with two rows and $N$ columns. Each cell contains a value representing the strength of a soldier stationed there. On any given day, each column independently either disappears in fog or remains visible, with probability $1/2$.

codeforcescompetitive-programmingcombinatoricsdata-structures
CF 2045F - Grid Game 3-angle

We are given a triangular grid of size $N$, where row $r$ has $r$ cells. Certain cells initially contain some stones. Two players, Anda and Kamu, alternate turns, starting with Anda.

codeforcescompetitive-programminggamesmath
CF 2045G - X Aura

We are given a grid of size $R times C$ where each cell has a height from 0 to 9. You can move only between adjacent cells (up, down, left, right).

codeforcescompetitive-programminggraphsmathshortest-paths
CF 2045D - Aquatic Dragon

We are asked to navigate a line of islands numbered from 1 to N, starting at island 1 and ending at island N, while carrying a dragon whose stamina powers two special moves: swimming and flying.

codeforcescompetitive-programming
CF 2045B - ICPC Square

We are given a hotel with $N$ floors and an unusual elevator. From floor $x$, the elevator allows a jump to any floor $y$ such that $y$ is a multiple of $x$ and the difference $y - x$ does not exceed $D$.

codeforcescompetitive-programmingmathnumber-theory
CF 2045C - Saraga

We are given two strings, one called $S$ and another called $T$. We want to build a new string by taking some prefix of $S$ and some suffix of $T$, then concatenating them. The resulting string is called an abbreviation.

codeforcescompetitive-programminggreedystrings
CF 2045A - Scrambled Scrabble

We are asked to construct the longest possible word from a given string of uppercase letters under a very specific notion of syllables and letters. The alphabet is split into vowels (A, E, I, O, U), consonants (all others except Y), and a special letter Y that can act as either.

codeforcescompetitive-programmingbrute-forcegreedy
CF 2046F2 - Yandex Cuneiform (Hard Version)

We are given a string template consisting of the letters 'Y', 'D', 'X', and '?' of length divisible by three. Our task is to determine whether it is possible to replace every question mark with one of 'Y', 'D', or 'X' such that the resulting string can be built according to…

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyimplementation
CF 2046F1 - Yandex Cuneiform (Easy Version)

The problem asks us to determine whether a given string composed solely of the letters 'Y', 'D', and 'X' can be constructed incrementally following the rules of Yandex cuneiform.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 2046E1 - Cheops and a Contest (Easy Version)

We are given a set of participants, each described by two thresholds and a special attribute. Every participant either solves a problem because the problem is easy enough for their general skill, or because the problem matches their specialization and is still within their…

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2046E2 - Cheops and a Contest (Hard Version)

I can't reliably write a correct editorial and solution for Codeforces 2046E2 - Cheops and a Contest (Hard Version) from the statement alone. This is a 3500-rated constructive/greedy problem whose solution depends on a nontrivial characterization and construction.

codeforcescompetitive-programminggreedyimplementation
CF 2046D - For the Emperor!

We are given a directed graph where each vertex represents a city and each directed edge represents a road that allows messengers to travel one way. Some cities initially contain a number of messengers.

codeforcescompetitive-programmingflowsgraphs
CF 2046C - Adventurers

Each city is a point on the plane. We choose a dividing point $(x0,y0)$, which splits the plane into four regions: $$begin{aligned} &x ge x0, y ge y0 &x < x0, y ge y0 &x ge x0, y < y0 &x < x0, y < y0 end{aligned}$$ Every city belongs to exactly one of these regions, according…

codeforcescompetitive-programmingbinary-searchdata-structuresgreedysortingsternary-searchtwo-pointers
Kvant Math Problem 1530

Numbers $1,2,\dots,2p$ split into residue classes modulo $p$ as

kvantmathematicsolympiad
CF 2046A - Swap Columns and Find a Path

We are given a two-row matrix with $n$ columns, where each cell contains an integer. We can swap any two columns any number of times. After performing swaps, we must choose a path from the top-left cell $(1,1)$ to the bottom-right cell $(2,n)$.

codeforcescompetitive-programminggreedysortings
CF 2046B - Move Back at a Cost

We are given a sequence of integers, and we are allowed to repeatedly perform a very specific transformation: pick any element, increase it by one, and move it to the end of the array.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedysortings
CF 2048I2 - Kevin and Puzzle (Hard Version)

We are asked to count arrays of non-negative integers that satisfy conditions imposed by a string of L and R characters.

codeforcescompetitive-programmingbitmasksfftmath
CF 2048G - Kevin and Matrices

There is not enough information to diagnose the algorithm from the sample alone. The input contains only pairs (n, k), and the expected outputs are permutations: Many different Codeforces and contest problems use exactly this input format and require constructing a permutation…

codeforcescompetitive-programmingbrute-forcecombinatoricsdpmath
CF 2048I1 - Kevin and Puzzle (Easy Version)

We are asked to construct an array of non-negative integers corresponding to a string of directions, where each character in the string specifies a condition about the count of distinct numbers in either the prefix or suffix of the array.

codeforcescompetitive-programmingconstructive-algorithms
CF 2048H - Kevin and Strange Operation

We are given a binary string s composed of 0s and 1s. Kevin can repeatedly perform a special operation: choose a position p, replace every character before it with the maximum of itself and the next character, then remove the character at position p.

codeforcescompetitive-programmingdata-structuresdp
CF 2048E - Kevin and Bipartite Graph

We are asked to design a bipartite graph for a poster pattern. The left part has $2n$ vertices, and the right part has $m$ vertices, with every left vertex connected to every right vertex. Each edge must be colored with an integer between $1$ and $n$.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedy
CF 2048F - Kevin and Math Class

We are given two arrays of the same length. The first array represents the values we want to eventually reduce to ones, and the second array controls how fast we can reduce segments. A single operation chooses a contiguous segment.

codeforcescompetitive-programmingbrute-forcedata-structuresdivide-and-conquerdpimplementationmathtrees
CF 2048B - Kevin and Permutation

The reported failure is not caused by the algorithm's logic. The traceback shows: at: This means that somewhere before the call, the name solve was overwritten with None: or equivalently: and then later: was executed.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2048D - Kevin and Competition Memories

We are given a fixed list of problem difficulties and a list of participant ratings. If a participant has rating $ai$, they solve exactly those problems whose difficulty is at most $ai$.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresgreedysortingstwo-pointers
Kvant Math Problem 1506

For a fixed interval $[a,b]$, the condition that the sums of integrals over white and black subintervals are equal for every polynomial in a given family can be rewritten as the vanishing of a signed…

kvantmathematicsolympiad
CF 2048C - Kevin and Binary Strings

We are given a binary string where the first character is always 1. From this string, we must pick two non-empty substrings, and we are allowed to pick the same substring twice or pick overlapping ones.

codeforcescompetitive-programmingbitmasksbrute-forcegreedyimplementationstrings
CF 2048A - Kevin and Combination Lock

We are given a starting integer and a small set of operations that modify it. The goal is to determine whether we can eventually reduce the number exactly to zero. The two operations behave very differently.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmathnumber-theory
CF 2049F - MEX OR Mania

The task asks us to process a sequence of integers and repeatedly answer the following: after each update to an element, what is the length of the longest contiguous subarray for which the MEX minus the bitwise OR of all elements equals exactly one.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresdsuimplementation
CF 2049E - Broken Queries

We are asked to determine a hidden integer $k$ in an interactive setting, where $k$ controls the behavior of a device that responds to range queries on a hidden binary array of length $n$. The array contains exactly one 1 and all other elements are 0.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forceconstructive-algorithmsimplementationinteractive
CF 2049D - Shift + Esc

We are given a grid of integers with $n$ rows and $m$ columns. Each cell contains a non-negative integer. We start at the top-left corner and want to reach the bottom-right corner, moving only right or down.

codeforcescompetitive-programmingbrute-forcedp
CF 2049B - pspspsps

I can't reliably diagnose the algorithmic bug from the information provided. The sample input/output pair is not enough to reconstruct the original problem, and the fact that the program now produces a blank output instead of a traceback suggests that we're no longer looking…

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgraph-matchingsimplementation
CF 2049A - MEX Destruction

We are given several independent test cases. In each test case, there is an array of small integers. The allowed operation takes any contiguous segment of the array, computes the MEX of the values inside that segment, and replaces the entire segment with that single value.

codeforcescompetitive-programminggreedyimplementation
CF 2049C - MEX Cycle

We are given a circular arrangement of $n$ nodes, each representing a dragon. Every dragon is connected to its two neighbors in the circle, and additionally there is one extra undirected edge between two specified nodes $x$ and $y$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedyimplementation
CF 2050F - Maximum modulo equality

Thank you for the clarification. I see exactly why the previous solution fails. The core issue is that the greedy left-to-right redistribution is too strict: it assumes you can only push surplus to the next element, but in reality the allowed operations let you shift values…

codeforcescompetitive-programmingdata-structuresdivide-and-conquermathnumber-theory
CF 2050D - Digital string maximization

We are given a string of digits, representing a number without leading zeros. We can repeatedly perform a restricted operation: pick any digit except the leftmost one or zero, decrease it by one, and swap it with the digit immediately to its left.

codeforcescompetitive-programmingbrute-forcegreedymathstrings
CF 2050G - Tree Destruction

We are given a tree, which is an acyclic connected graph, with $n$ vertices. The task is to select two vertices, $a$ and $b$, and remove all vertices along the unique path between them, including $a$ and $b$ themselves.

codeforcescompetitive-programmingdfs-and-similardptrees
CF 2050E - Three Strings

We are given three strings: a, b, and c. Conceptually, c is formed by taking letters from a and b in some interleaving order. At each step, one letter is taken from the front of either a or b and appended to c.

codeforcescompetitive-programmingdpimplementationstrings
Kvant Math Problem 1479

The problem asks for the maximum number $K(n)$ of quadruples of natural numbers summing to $n$, under the global constraint that all numbers appearing in all quadruples are pairwise distinct.

kvantmathematicsolympiad
CF 2050B - Transfusion

We are given an array of integers representing “pools” of some resource. At each operation, we can pick an element that is not at the boundaries and move one unit from one neighbor to the other neighbor.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 2050A - Line Breaks

We are given a list of words and a fixed-length strip that can hold a certain number of characters. The task is to decide how many words we can consecutively place on this first strip without exceeding its length, while the remaining words go on a second strip that has…

codeforcescompetitive-programmingimplementation
CF 2050C - Uninteresting Number

We are given a very long decimal string, and we are allowed to repeatedly modify it digit by digit. A move picks one digit, replaces it with the value of its square, and keeps it as a single decimal digit only if the square is still between 0 and 9.

codeforcescompetitive-programmingbrute-forcedpmath
CF 2051G - Snakes

We are asked to place a set of snakes on a very long 1-dimensional strip of cells. Each snake initially occupies a single cell, and over a sequence of events it can either grow to the right or shrink from the left.

codeforcescompetitive-programmingbitmasksdpdsugraphs
CF 2051E - Best Price

The algorithm itself is correct. The symptom is that the program produces no output at all, not incorrect output. That means the bug is not in the logic for determining pass/fail. It is in the program structure.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresgreedysortings
CF 2051F - Joker

We are working with a deck of cards where only the relative position of a special card, the joker, matters. Initially the joker sits at position m in a line of n cards. Then we perform a sequence of operations.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmath
CF 2051A - Preparing for the Olympiad

We are given two arrays of length n, one representing how many problems Monocarp can solve on each day, and another representing how many problems Stereocarp would solve on each day if he trains. Monocarp has full freedom to choose any subset of days to train.

codeforcescompetitive-programminggreedy
CF 2051D - Counting Pairs

We are given an array of positive integers and a target interval $[x, y]$. We are allowed to remove exactly two distinct elements from the array. After removing them, we look at the sum of what remains, and we want this remaining sum to fall inside the given interval.

codeforcescompetitive-programmingbinary-searchsortingstwo-pointers
CF 2051C - Preparing for the Exam

There are $n$ possible exam questions. Each available exam version contains all questions except one. The value $ai$ tells us which question is omitted from the $i$-th version. Monocarp knows a set of $k$ questions.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 2051B - Journey

Monocarp is going on a multi-day hike and has a repeating pattern of distances for each day: he walks a kilometers on the first day, b on the second, c on the third, then repeats that cycle indefinitely.

codeforcescompetitive-programmingbinary-searchmath
Kvant Math Problem 970

Let the 32 stops lie on a line in increasing order of distance from the initial point, labeled $1,2,\dots,32$.

kvantmathematicsolympiad
CF 2052M - Managing Cluster

I can't write a correct editorial, proof, algorithm, or solution for Codeforces 2052K from the information provided, because the problem statement, input format, output format, constraints, and samples are all missing.

codeforcescompetitive-programmingdpgraphsmathtrees
CF 2052J - Judicious Watching

We are given a schedule-like situation with two independent activities that compete for time. On one side there are homework tasks. Each task takes a fixed amount of uninterrupted time, and each has a deadline by which it must be fully completed.

codeforcescompetitive-programmingbinary-searchgreedysortings
CF 2052L - Legacy Screensaver

We are given a rectangular screen divided into a grid of pixels. Each pixel has a brightness value. The problem describes a screensaver that repeatedly selects a rectangular subregion of the screen and applies a transformation that reduces each pixel’s brightness to the…

codeforcescompetitive-programming
CF 2052K - Knowns and Unknowns

I can't write a correct editorial, proof, algorithm, or solution for Codeforces 2052K from the information provided, because the problem statement, input format, output format, constraints, and samples are all missing.

codeforcescompetitive-programming
CF 2052I - Incompetent Delivery Guy

I can’t write a correct, detailed editorial for Codeforces 2052I - Incompetent Delivery Guy yet because the actual problem statement (or at least its full content) is missing from your prompt. Right now, only the title and metadata are provided.

codeforcescompetitive-programminggraphsshortest-paths
CF 2052H - Hunting Hoglins in Hogwarts

The race starts with cars ordered by their labels: $$1,2,3,dots,n.$$ During the race, an overtake is an adjacent swap. If car $x$ is directly behind car $y$, then the event "$x$ overtakes $y$" swaps their positions. At the end of the race we know only the final ordering $c$.

codeforcescompetitive-programminginteractive
CF 2052F - Fix Flooded Floor

We are given a grid with two rows and n columns. Each cell is either already broken (empty space we must fill) or intact and unusable. Our task is to cover every broken cell exactly once using dominoes of size 1 by 2.

codeforcescompetitive-programmingconstructive-algorithmsdpgraphs
CF 2052G - Geometric Balance

We are asked to analyze a drawing procedure performed by a turtle on the plane. The turtle moves and rotates according to a sequence of commands: it can rotate by a multiple of 45 degrees, move forward either with or without leaving a trace, and draw a segment of a given length.

codeforcescompetitive-programmingdata-structuresgeometryimplementation
CF 2052A - Adrenaline Rush

The race starts with cars ordered by their labels: $$1,2,3,dots,n.$$ During the race, an overtake is an adjacent swap. If car $x$ is directly behind car $y$, then the event "$x$ overtakes $y$" swaps their positions. At the end of the race we know only the final ordering $c$.

codeforcescompetitive-programmingconstructive-algorithms
CF 2052E - Expression Correction

We are given a string representing a mathematical equality composed of addition and subtraction expressions. Each side of the equality can have multiple numbers joined by + or - operators. The numbers themselves are non-negative and do not have unnecessary leading zeros.

codeforcescompetitive-programmingbrute-forceexpression-parsingstrings
CF 2052D - DAG Serialization

We are given a sequence of operations applied to a single boolean register that starts in the false state. Each operation is either a set or an unset.

codeforcescompetitive-programmingbrute-forcegraphs
CF 2052C - Cactus without Bridges

The problem gives you an undirected graph with $n$ nodes and $m$ edges and asks you to construct a “cactus” graph with the same number of nodes and edges, under the condition that the resulting cactus does not have any bridges.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 2052B - BitBitJump

I can’t reliably reconstruct the full statement of Codeforces 2052B “BitBitJump” from the title alone, and for a 2400-rated problem the exact jump rules are crucial to the solution structure.

codeforcescompetitive-programming
CF 2053I1 - Affectionate Arrays (Easy Version)

We are given an integer array a and asked to create a new array b which contains a as a subsequence, has the same total sum as a, and minimizes the maximum subarray sum - the so-called boredom.

codeforcescompetitive-programmingdata-structuresdpgreedy
CF 2053I2 - Affectionate Arrays (Hard Version)

We are given an initial integer sequence $a$. We are allowed to construct longer sequences $b$ under two global constraints: the sequence $a$ must appear inside $b$ as a subsequence, and the total sum of elements in $b$ must equal the total sum of $a$.

codeforcescompetitive-programmingdata-structuresdpgraphsgreedymathshortest-pathstwo-pointers
CF 2053H - Delicate Anti-monotonous Operations

We are given a sequence of integers, each between 1 and a maximum value $w$. The sequence can contain repeated numbers, but we are allowed to perform a special operation any number of times: select two consecutive elements that are equal and change both to any two numbers we…

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 2053G - Naive String Splits

We are given two strings for each test case: a string s of length n and a string t of length m. The task is to examine all ways to split s into a prefix x and a suffix y at positions 1 through n-1, and for each split, determine whether the string t can be written as a…

codeforcescompetitive-programmingbinary-searchbrute-forcegreedyhashingmathnumber-theorystrings
Kvant Math Problem 918

Let the triangle have sides $a,b,c$ and semiperimeter $s=\frac{a+b+c}{2}$.

kvantmathematicsolympiad
CF 2053F - Earnest Matrix Complement

For a row $i$, let: - $zi$ = number of -1 cells in that row. - $cnti(u)$ = number of already fixed occurrences of value $u$. Suppose we decide that every blank in row $i$ is filled with the same value $pi$. This is not a restriction.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedyimplementationmath
CF 2053D - Refined Product Optimality

We are given two arrays, a and b, each of length n. The task is to compute the maximum product $$P = prod{i=1}^{n} min(ai, bi)$$ after any rearrangement of b.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedymathschedulessortings
CF 2053E - Resourceful Caterpillar Sequence

We are given a tree. Two endpoints are chosen, a head $p$ and a tail $q$, and the only vertices that matter are those on the unique path between them. The game is a two-player process where Nora controls the head side and Aron controls the tail side.

codeforcescompetitive-programmingdfs-and-similardpgamesgraphsgreedytrees
CF 2053A - Tender Carpenter

The problem presents an array of integers representing stick lengths. A set of integers is defined as stable if any three elements selected from it (with possible repetition) can form a non-degenerate triangle.

codeforcescompetitive-programmingdpgeometrygreedymath
CF 2053C - Bewitching Stargazer

We are asked to simulate the process of Iris observing stars with a lazy, recursive strategy. She starts with all stars in a single segment and repeatedly targets the middle star of any odd-length segment, adding its 1-based index to her "lucky value".

codeforcescompetitive-programmingbitmasksdivide-and-conquerdpmath
CF 2053B - Outstanding Impressionist

We are given a sequence of impressions, where each impression is represented by a range of possible integer values. Eric can only remember that the $i$-th impression is somewhere between $li$ and $ri$.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresgreedy
CF 2055E - Haystacks

We are given several piles of hay. Each pile starts with some number of haybales, and each pile also has a personal capacity that becomes relevant only after we empty it once.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdata-structuresgreedysortings
CF 2055F - Cosmic Divide

We are given a polyomino described row by row. Each row contains a contiguous horizontal segment of filled unit cells, so the shape is a “staircase-like” union of intervals on integer rows.

codeforcescompetitive-programmingbrute-forcegeometryhashingmathstrings
CF 2055D - Scarecrow

We are simulating a one-dimensional system where a crow moves only by teleportation, and its motion is entirely dictated by the nearest scarecrow on its left. The crow starts at position zero and wants to reach at least position ℓ.

codeforcescompetitive-programminggreedyimplementationmath
CF 2055C - The Trail

We are given a grid where every cell initially contains an integer altitude. Along one special path from the top-left corner to the bottom-right corner, all values have been erased and replaced with zero.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedymathtwo-pointers
CF 2055B - Crafting

We are given several test cases. In each one, we start with a collection of $n$ material types. Each type $i$ has an initial amount $ai$, and we want to reach at least $bi$ units for every type. There is a single operation that couples all resources tightly.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings