brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1678A - Tokitsukaze and All Zero Sequence

The problem asks us to turn a sequence of numbers into all zeros using a particular operation. In each operation, we pick two distinct elements. If they are equal, we replace one of them with zero. If they are different, we replace both with the smaller of the two.

codeforcescompetitive-programmingimplementation
CF 1678B1 - Tokitsukaze and Good 01-String (easy version)

We are given a binary string and allowed to flip any individual character at unit cost. After all changes, the string is interpreted by compressing it into maximal runs of identical characters.

codeforcescompetitive-programmingimplementation
CF 1679F - Formalism for Formalism

We are given a length $n$ string of decimal digits, and a set of constraints between digits in the form of allowed adjacent swaps.

codeforcescompetitive-programmingbitmasksdpmath
CF 1679E - Typical Party in Dorm

We are given a string of length n composed of the first 17 lowercase letters (a through q) and question marks. Each question mark acts as a wildcard that can be replaced by a letter from a specific set provided in a query.

codeforcescompetitive-programmingbitmaskscombinatoricsdpstrings
CF 1679D - Toss a Coin to Your Graph...

The problem gives a directed graph where each vertex has a positive integer value. Masha can place a coin on any vertex, and then move it along the graph edges exactly $k-1$ times. Every time the coin visits a vertex, the vertex’s number is recorded in a notebook.

codeforcescompetitive-programmingbinary-searchdfs-and-similardpgraphs
CF 1679A - AvtoBus

We are asked to determine how many buses a fleet could have given the total number of wheels. Each bus comes in one of two types: two-axle buses with 4 wheels and three-axle buses with 6 wheels.

codeforcescompetitive-programmingbrute-forcegreedymathnumber-theory
CF 1679B - Stone Age Problem

We are given an array of integers and a sequence of queries. Each query either replaces a single element in the array with a new value or replaces every element in the array with the same value. After each query, we need to report the sum of the array.

codeforcescompetitive-programmingdata-structuresimplementation
CF 1679C - Rooks Defenders

We are asked to simulate a sequence of operations on an $n times n$ chessboard involving rooks. Each rook attacks its entire row and column.

codeforcescompetitive-programmingdata-structuresimplementation
CF 1680A - Minimums and Maximums

We are asked to construct arrays called beautiful arrays. A beautiful array is one in which the number of elements equal to the minimum value falls between two given bounds, $l1$ and $r1$, and the number of elements equal to the maximum value falls between two bounds, $l2$ and…

codeforcescompetitive-programmingbrute-forcemath
CF 1680F - Lenient Vertex Cover

We are asked to find a lenient vertex cover for a connected undirected graph. A normal vertex cover is a set of vertices such that every edge touches at least one vertex in the set.

codeforcescompetitive-programmingdfs-and-similardivide-and-conquerdsugraphstrees
CF 1680D - Dog Walking

We are given a sequence of movements of a dog along an infinite line. Each minute, the dog moves a certain distance. Positive numbers move it to the right, negative to the left, and zero indicates unknown movement where we can pick any integer in the range $[-k, k]$.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1680E - Moving Chips

We are given a $2 times n$ board where some cells contain chips, represented by '', and others are empty, represented by '.'. Our task is to move chips so that exactly one chip remains on the board.

codeforcescompetitive-programmingbitmasksdpgreedy
CF 1680B - Robots

We are given a small rectangular grid, with each cell either empty or containing a robot. Robots can move simultaneously in one of four cardinal directions, and if any robot tries to leave the grid, it explodes.

codeforcescompetitive-programmingimplementation
CF 1680C - Binary String

We are given a binary string and we are allowed to cut it in a very specific way: we choose some prefix and suffix to remove, leaving a single contiguous substring in the middle. The remaining substring is what we “keep”, while everything outside it is considered removed.

codeforcescompetitive-programmingbinary-searchgreedystringstwo-pointers
CF 1681A - Game with Cards

Two players each hold a multiset of integers. They play a turn-based game where the only rule is that every newly played number must be strictly larger than the previous one.

codeforcescompetitive-programminggamesgreedy
CF 1681F - Unique Occurrences

We are given a tree with $n$ vertices. Each edge has an integer label. For any pair of vertices $v$ and $u$, we define $f(v, u)$ as the number of edge labels that appear exactly once along the unique path connecting $v$ and $u$.

codeforcescompetitive-programmingdata-structuresdfs-and-similardivide-and-conquerdpdsutrees
CF 1681E - Labyrinth Adventures

We are given a labyrinth structured as concentric layers in an $n times n$ grid. Each layer is a contiguous set of cells surrounding the previous layer. The first layer is just the bottom-left corner.

codeforcescompetitive-programmingdata-structuresdpmatricesshortest-paths
CF 1681D - Required Length

We are given an integer x and a target length n. We can repeatedly choose any digit y from the current number x and multiply x by y. The goal is to make x have exactly n digits using the minimum number of such operations.

codeforcescompetitive-programmingbrute-forcedfs-and-similardphashingshortest-paths
CF 1681C - Double Sort

We are given two arrays of the same length, a and b. We can perform a special swap operation: choose any two positions i and j, and simultaneously swap a[i] with a[j] and b[i] with b[j].

codeforcescompetitive-programmingimplementationsortings
CF 1681B - Card Trick

We are given a deck of n cards with distinct integer values, ordered from top to bottom. We then perform m shuffle operations, each defined by a number bj.

codeforcescompetitive-programmingimplementationmath
CF 1682D - Circular Spanning Tree

We are asked to construct a tree on n nodes arranged in a circle. Each node has a requirement: its degree must be even or odd, depending on the corresponding character in a binary string s.

codeforcescompetitive-programmingconstructive-algorithmsimplementationtrees
CF 1682F - MCMF?

We are given a sorted array a and an integer array b. Each query gives a segment [l, r], and we only care about it if the sum of b over this segment is zero. This condition guarantees that total “supply” and “demand” inside the segment balance perfectly.

codeforcescompetitive-programmingdata-structuresflowsgraphsgreedysortingstwo-pointers
CF 1682E - Unordered Swaps

We are given a permutation of integers from $1$ to $n$ and a set of $m$ swaps, which are guaranteed to be the minimum swaps required to sort the permutation. These swaps have been shuffled arbitrarily.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsgreedymathsortingstrees
CF 1682B - AND Sorting

We are given a permutation of the integers from 0 to n−1, and we are allowed to rearrange it using a very unusual swap rule. A swap between two positions is only allowed when the bitwise AND of the two values currently stored at those positions equals a chosen value X.

codeforcescompetitive-programmingbitmasksconstructive-algorithmssortings
CF 1682A - Palindromic Indices

We are given a string that is already a palindrome, meaning it reads the same from left to right and right to left. For each position in this string, we imagine removing exactly one character and then ask whether the remaining string is still a palindrome.

codeforcescompetitive-programminggreedystrings
CF 1682C - LIS or Reverse LIS?

We are given several test cases. Each test case provides a multiset of numbers, and we are allowed to rearrange them in any order we want. After choosing an ordering, we look at two sequences: the chosen array itself, and its reverse.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 1684H - Hard Cut

We are given a binary string, which is a sequence of '0's and '1's. Our task is to partition this string into contiguous substrings in such a way that, if we interpret each substring as a binary number and sum them all, the result is a power of two.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardivide-and-conquermath
CF 1684G - Euclid Guess

We are given a multiset of positive integers, and we are told that this multiset was produced by repeatedly running Euclid’s algorithm on several unknown integer pairs.

codeforcescompetitive-programmingconstructive-algorithmsflowsgraph-matchingsmathnumber-theory
CF 1684D - Traps

We are given a sequence of traps, each with a base damage value. We traverse the traps in order, and for each trap we either take its damage or skip it by jumping over it.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 1684F - Diverse Segments

We are given an array and several queries, where each query describes a segment of indices. The requirement is that inside every given query segment, all values must be pairwise distinct. If the array already satisfies this condition for all segments, we do nothing.

codeforcescompetitive-programmingdata-structurestwo-pointers
CF 1684E - MEX vs DIFF

We are given an array of non-negative integers and we are allowed to perform up to k replacements, where each replacement changes any element to any non-negative value. After these edits, we evaluate the array using two quantities.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsdata-structuresgreedytwo-pointers
CF 1684B - Z mod X = C

We are asked to construct three positive integers $x, y, z$ given three constraints on remainders. Each constraint relates one number to another through a modulo operation: the remainder when dividing $x$ by $y$ must equal $a$, the remainder when dividing $y$ by $z$ must equal…

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1684C - Column Swapping

We are given a matrix where each row represents a sequence of numbers arranged across columns. The goal is to make every row individually non-decreasing from left to right, but we are only allowed a single global operation: swap two entire columns.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedyimplementationsortings
CF 1684A - Digit Minimization

We are given an integer with no zero digits, and two players, Alice and Bob, play a turn-based game on its digits. Alice always moves first and can swap any two digits at different positions. Bob always removes the last digit of the number.

codeforcescompetitive-programmingconstructive-algorithmsgamesmathstrings
CF 1685D2 - Permutation Weight (Hard Version)

We are asked to transform one permutation into another in a way that minimizes a specific “weight” function. The weight is the sum of absolute differences between each element of the new permutation and the element of the original permutation located at the next position in…

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1685E - The Ultimate LIS Problem

We are given a permutation of size $2n+1$, and this array keeps changing through swaps of two positions. After every swap, we are not asked to analyze the array itself directly, but to consider all its cyclic rotations and determine whether at least one rotation has a…

codeforcescompetitive-programmingdata-structuresgreedy
CF 1685D1 - Permutation Weight (Easy Version)

We are given a permutation p of the numbers from 1 to n, and our task is to construct another permutation q of the same numbers that minimizes a specific weight function.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardsu
CF 1685A - Circular Local MiniMax

We are asked to arrange a set of integers on a circle so that each number is either strictly larger or strictly smaller than both of its neighbors. The input consists of multiple test cases. Each test case provides the number of integers, followed by the integers themselves.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 1685B - Linguistics

The solution addresses the exercise directly. It identifies the event $f(n)-f(n-1) = k$ as the occurrence of exactly $k-1$ consecutive terms outside the interval $[alpha,beta)$ followed by one term inside, which correctly models the "gap" between hits in the interval.

codeforcescompetitive-programminggreedyimplementationsortingsstrings
CF 1685C - Bring Balance

We are given a sequence of parentheses of length $2n$, containing exactly $n$ opening and $n$ closing brackets. The task is to transform this sequence into a correct balanced parentheses string using the minimum number of operations, where each operation consists of reversing…

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedy
CF 1686B - Odd Subarrays

We are given a permutation of the numbers from 1 to n. We may split this permutation into any number of consecutive pieces. Each piece is a subarray. For every subarray, we look at its inversion count. A subarray is called odd if its inversion count is odd.

codeforcescompetitive-programmingdpgreedy
CF 1686A - Everything Everywhere All But One

We are given several independent test cases. Each test case starts with an array of integers. The only operation allowed transforms the array in a very specific way: we pick exactly one element to leave untouched and replace every other element by the average of the chosen group.

codeforcescompetitive-programminggreedy
CF 1687F - Koishi's Unconscious Permutation

The solution addresses the exercise directly. It identifies the event $f(n)-f(n-1) = k$ as the occurrence of exactly $k-1$ consecutive terms outside the interval $[alpha,beta)$ followed by one term inside, which correctly models the "gap" between hits in the interval.

codeforcescompetitive-programmingfftmath
CF 1687D - Cute number

For every integer, look at the two consecutive perfect squares surrounding it. If $$m^2 le x < (m+1)^2,$$ then $g(x)=m^2$ and $f(x)=(m+1)^2$. The number is called cute when it is strictly closer to the lower square than to the upper square.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdsuimplementationmath
CF 1687E - Become Big For Me

We are given a sequence of integers a and a number v initialized to 1. The task is to perform a series of operations on v so that it becomes the greatest common divisor of all pairwise products of elements from a.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsgreedymathnumber-theory
CF 1687C - Sanae and Giant Robot

The solution addresses the exercise directly. It identifies the event $f(n)-f(n-1) = k$ as the occurrence of exactly $k-1$ consecutive terms outside the interval $[alpha,beta)$ followed by one term inside, which correctly models the "gap" between hits in the interval.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdsugreedysortings
CF 1687A - The Enchanted Forest

We are asked to compute the maximum number of mushrooms Marisa can collect in a one-dimensional forest over a limited number of minutes.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1687B - Railway System

We are given a railway network consisting of n stations and m bidirectional tracks, each with a positive length. The network may not be fully connected and can have multiple tracks between the same pair of stations.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedyinteractivesortings
CF 1688C - Manipulating History

We are asked to reconstruct the initial string of length 1 from which a sequence of operations produced a given final string. Each operation consists of selecting a substring of the current string and replacing it with another string, possibly of different length.

codeforcescompetitive-programmingconstructive-algorithmsgreedystrings
CF 1688A - Cirno's Perfect Bitmasks Classroom

We are given a positive integer $x$, and the task is to find the smallest positive integer $y$ such that two bitwise conditions hold simultaneously: the bitwise AND of $x$ and $y$ is greater than zero, and the bitwise XOR of $x$ and $y$ is also greater than zero.

codeforcescompetitive-programmingbitmasksbrute-force
CF 1688B - Patchouli's Magical Talisman

We are asked to transform a collection of magical tokens so that every token has an odd magical power. Each token starts with some positive integer power.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedysortings
CF 1689B - Mystic Permutation

We are given a permutation $p$ of the numbers $1$ through $n$. We want to construct another permutation $q$ using the same numbers such that every position changes. For every index $i$, the value placed in $qi$ must be different from $pi$.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1689E - ANDfinity

We are given an array of non-negative integers. Each array element corresponds to a vertex in a graph. Two vertices are connected by an edge whenever the bitwise AND of their values is positive. The graph is not guaranteed to be connected.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsdfs-and-similardsugraphs
CF 1689D - Lena and Matrix

We are given a grid of size $n times m$, where each cell is either black or white. Our task is to pick a cell such that the maximum Manhattan distance from this cell to any black cell is minimized.

codeforcescompetitive-programmingdata-structuresdpgeometryshortest-paths
CF 1689C - Infected Tree

We are given a binary tree rooted at vertex 1. Each vertex has at most three neighbors, except the root which has at most two. Initially, only the root is infected.

codeforcescompetitive-programmingdfs-and-similardptrees
CF 1689A - Lex String

We are given two strings, a and b, which do not share any letters. We can build a new string c by repeatedly taking the smallest available letter from either a or b. However, there is a restriction: we cannot take more than k characters from the same string consecutively.

codeforcescompetitive-programmingbrute-forcegreedyimplementationsortingstwo-pointers
CF 1690G - Count the Trains

Each carriage has its own maximum speed. When all carriages start moving, a carriage cannot move faster than any carriage in front of it, so its actual speed becomes the minimum value seen so far from the left.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedysortings
CF 1690C - Restoring the Duration of Tasks

We are given two increasing arrays. The array s contains the arrival time of each task. Task i becomes available at time s[i]. The array f contains the completion time of each task. Task i finishes exactly at time f[i]. Polycarp processes tasks in FIFO order.

codeforcescompetitive-programmingdata-structuresgreedyimplementation
CF 1690F - Shifting String

We are given a string s of length n and a permutation p of the integers from 1 to n. Each permutation p defines a reordering operation: after one application, the character at position i in the new string moves to position p[i].

codeforcescompetitive-programminggraphsmathnumber-theorystrings
CF 1690E - Price Maximization

We are given an even number of goods, each with a weight, and we need to pack them into pairs. The cost of a pair is calculated by taking the sum of its weights, dividing by a fixed number $k$, and rounding down to the nearest integer.

codeforcescompetitive-programmingbinary-searchgreedymathtwo-pointers
CF 1690D - Black and White Stripe

We are given a stripe of tiles, each either white or black, and the goal is to ensure that at least one segment of exactly k consecutive tiles is entirely black.

codeforcescompetitive-programmingimplementationtwo-pointers
CF 1690B - Array Decrements

We are given two arrays of non-negative integers, a and b, both of length n. The allowed operation is to simultaneously decrement all positive elements of a by one.

codeforcescompetitive-programminggreedyimplementation
CF 1690A - Print a Pedestal (Codeforces logo?)

We are given a number of identical building blocks and must split them into three stacks representing a podium. Each stack corresponds to a rank: third place, second place, and first place.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1691C - Sum of Substrings

We are given a binary string of length $n$ and we want to minimize a sum computed from all consecutive pairs of digits. Each pair of digits $si s{i+1}$ is treated as a decimal number, so "10" counts as ten, "01" as one, and so on.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedymathstrings
CF 1691F - K-Set Tree

We are given an undirected tree with $n$ vertices. For every choice of a root $r$, the tree becomes rooted. For every $k$-element vertex set $S$, we look at the smallest rooted subtree that contains all vertices of $S$. A rooted subtree is not just any connected subgraph.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardpmathtrees
CF 1691E - Number of Groups

We are given a set of segments on the number line, each colored either red or blue. Each segment occupies a continuous interval from li to ri, inclusive.

codeforcescompetitive-programmingdata-structuresdfs-and-similardsugraphsgreedysortings
CF 1691D - Max GEQ Sum

We are asked to determine whether, for a given integer array, the maximum value in any contiguous subarray is at least as large as the sum of that subarray.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresdivide-and-conquerimplementationtwo-pointers
CF 1691B - Shoe Shuffling

We are given a sorted list of shoe sizes for a group of students. Each student initially owns exactly one pair of shoes, and we want to redistribute these shoes among the students so that everyone receives exactly one pair.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationtwo-pointers
CF 1691A - Beat The Odds

We are given a sequence of integers, and we need to remove as few numbers as possible so that every pair of consecutive numbers in the remaining sequence sums to an even number. The sum of two numbers is even if both numbers are even or both are odd.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1692H - Gambling

We know the outcomes of the next $n$ dice rolls in advance. Marian chooses a value $a$, and a contiguous segment of rounds $[l,r]$. During every round in that segment he always guesses the same value $a$. Whenever the actual rolled value equals $a$, his money doubles.

codeforcescompetitive-programmingdata-structuresdpgreedymath
CF 1692G - 2^Sort

We are given an array and asked to examine every contiguous segment of fixed length $k+1$. For each such segment starting at position $i$, we conceptually transform it by multiplying element $j$ (relative to the segment start) by $2^j$.

codeforcescompetitive-programmingdata-structuresdpsortingstwo-pointers
CF 1692D - The Clock

We are given a starting time on a 24-hour clock and a fixed number of minutes between observations. Starting from the given time, Victor repeatedly looks at the clock after every $x$ minutes.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1692F - 3SUM

We are given an array of positive integers, and we want to know if we can select three distinct elements whose sum ends with the digit 3. In other words, if we denote the chosen elements as $ai$, $aj$, and $ak$, then $(ai + aj + ak) mod 10 = 3$.

codeforcescompetitive-programmingbrute-forcemath
CF 1692E - Binary Deque

We are given a binary array of length $n$, meaning each element is either 0 or 1. The task is to perform a sequence of operations where, in each operation, we remove either the first or the last element of the array.

codeforcescompetitive-programmingbinary-searchimplementationtwo-pointers
CF 1692B - All Distinct

We are given an array of integers. In one operation, we must remove exactly two elements from the array. The two removed elements can be any values, as long as they come from different positions.

codeforcescompetitive-programminggreedysortings
CF 1692A - Marathon

We are asked to determine Timur's position relative to three other runners in a marathon. Each test case provides four distinct integers: Timur's distance first, followed by the distances run by three other participants.

codeforcescompetitive-programmingimplementation
CF 1692C - Where's the Bishop?

The discrepancy is not caused by a small implementation bug. The outputs show that the algorithm itself is overcounting the cost of independent intervals.

codeforcescompetitive-programmingimplementation
CF 1693F - I Might Be Wrong

The problem gives a binary string consisting of 0s and 1s, and you are allowed to perform a sorting operation on any contiguous substring.

codeforcescompetitive-programmingbinary-searchgreedytwo-pointers
CF 1693E - Outermost Maximums

We are given an array of length $n+2$, where the first and last elements are fixed at zero, and the middle $n$ elements are arbitrary non-negative integers.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1693D - Decinc Dividing

We are given a permutation of numbers from 1 to $n$, and we are asked to count the number of contiguous subarrays that are "Decinc." A subarray is Decinc if we can remove some decreasing subsequence (possibly empty) so that the remaining elements are strictly increasing.

codeforcescompetitive-programmingbrute-forcedata-structuresdivide-and-conquerdpgreedy
CF 1693A - Directional Increase

The proposed solution answers the exercise that was actually asked. Exercise 3.4.2.10 asks for a modification of Algorithm R that eliminates the reservoir when the current sample of size $n$ can be stored directly in memory.

codeforcescompetitive-programminggreedy
CF 1693B - Fake Plastic Trees

We are given a rooted tree. Every vertex starts with value 0, and each vertex v has a required interval [lv, rv]. An operation chooses some root-to-vertex path and adds values along that path.

codeforcescompetitive-programmingdfs-and-similardpgreedytrees
CF 1693C - Keshi in Search of AmShZ

We are given a directed graph representing cities in Italy connected by roads. Keshi starts in city 1 and wants to reach city n, where AmShZ is waiting. Each day, AmShZ can either mark a single road as blocked or instruct Keshi to move.

codeforcescompetitive-programminggraphsgreedyshortest-paths
CF 1694A - Creep

The proposed solution answers the exercise that was actually asked. Exercise 3.4.2.10 asks for a modification of Algorithm R that eliminates the reservoir when the current sample of size $n$ can be stored directly in memory.

codeforcescompetitive-programminggreedyimplementation
CF 1694B - Paranoid String

We are asked to count substrings of a binary string that are "paranoid." A paranoid string is one that can be reduced to a single character by repeatedly applying two operations: replacing 01 with 1 or 10 with 0.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1695E - Ambiguous Dominoes

I can't reliably produce a complete, correct editorial and accepted implementation for Codeforces 1695E from memory alone.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphs
CF 1695D1 - Tree Queries (Easy Version)

We are asked to determine the minimum number of distance queries required to uniquely identify a hidden vertex in a tree. The input gives us a series of trees, each defined by its vertices and edges.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similardpgreedytrees
CF 1695D2 - Tree Queries (Hard Version)

We are given an unrooted tree with $n$ vertices. There is a hidden vertex $x$ that we need to identify. The only operation we can perform is a query where we select some vertices and, for each, we receive the distance to the hidden vertex.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardpgreedytrees
CF 1695C - Zero Path

We have a grid whose cells contain only 1 or -1. Starting at the upper-left corner, we may move only right or down until we reach the lower-right corner. Every visited cell contributes its value to the path sum. The task is not to find the number of such paths or the minimum sum.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgraphsgreedyshortest-paths
CF 1695A - Subrectangle Guess

We are given a grid containing distinct integers. Michael chooses dimensions h × w, then Joe secretly selects any subrectangle of exactly that size. Michael must name the maximum value inside Joe's chosen rectangle before seeing which rectangle was selected.

codeforcescompetitive-programminggames
CF 1695B - Circle Game

We are asked to analyze a two-player game played on a circle of stone piles. Each pile has a certain number of stones. Players take turns removing a positive number of stones from the current pile.

codeforcescompetitive-programminggamesgreedy
CF 1696H - Maximum Product?

We are given a collection of integers where each element is tied to its index, so even equal values are treated as distinct items. From this collection, every subset is considered independently.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpgreedyimplementationmathtwo-pointers
CF 1696C - Fishingprince Plays With Array

We are given two arrays and a fixed integer $m$. Starting from the first array, we may repeatedly split an element divisible by $m$ into $m$ equal pieces, or merge $m$ consecutive equal elements into one larger element.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 1696G - Fishingprince Plays With Array Again

We are given an array whose values represent amounts that must be removed. An operation acts on one adjacent pair. If we spend $t$ seconds on edge $(i,i+1)$, we may subtract $(x t, y t)$ from the pair or $(y t, x t)$ from the pair.

codeforcescompetitive-programmingbrute-forcedata-structuresgeometrymath
CF 1696F - Tree Recovery

We are asked to reconstruct a tree based on a set of distance equalities between triples of vertices. Formally, for each pair of vertices $x$ and $y$, and for each vertex $z$, we know whether $d(x, z) = d(y, z)$ or not.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similardsugraphstrees
CF 1696D - Permutation Graph

We are given a permutation of integers from 1 to n and asked to construct a graph based on the relative minimum and maximum values in contiguous segments.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresdivide-and-conquergreedyshortest-paths
CF 1696E - Placing Jinas

We are asked to control dolls on an infinite grid where each cell can be white or black. The color of each cell is defined by a non-increasing sequence $a0, a1, dots, an$, extended with zeros beyond $n$.

codeforcescompetitive-programmingcombinatoricsmath
CF 1696B - NIT Destroys the Universe

We are given an array representing the “universe,” where each element is a non-negative integer. The protagonist, NIT, can perform a specific operation on any contiguous subarray: compute the mex of that subarray and set every element in it to that mex.

codeforcescompetitive-programminggreedy
CF 1696A - NIT orz!

We are given an array of integers and a number $z$. We are allowed to repeatedly pick any element $ai$ and perform two bitwise operations: update $ai$ to $ai operatorname{or} z$ and simultaneously update $z$ to $ai operatorname{and} z$.

codeforcescompetitive-programmingbitmasksgreedy
CF 1697C - awoo's Favorite Problem

The problem gives two strings s and t of the same length consisting of the characters 'a', 'b', and 'c'. The allowed operations let us swap adjacent "ab" to "ba" and "bc" to "cb". The task is to determine whether we can transform s into t using any number of these moves.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedyimplementationstringstwo-pointers