brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1372F - Omkar and Modes

We are given a hidden array of length $n$, already sorted in nondecreasing order, and containing at most $k le 25000$ distinct values. Our only way to inspect it is by querying a segment $[l,r]$.

codeforcescompetitive-programmingbinary-searchdivide-and-conquerinteractive
CF 1371F - Raging Thunder

We are given a line of positions, each containing a direction symbol that behaves like a deterministic local rule. From every starting position, a ball moves left or right according to its own symbol and the symbol of the neighbor it is interacting with.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerimplementation
CF 1371C - A Cookie for You

We are given two types of cookies and two types of guests. The cookies are split into vanilla and chocolate counts, and guests also come in two behavioral types.

codeforcescompetitive-programminggreedyimplementationmath
CF 1370F2 - The Hidden Pair (Hard Version)

We are given a tree and two hidden distinct nodes inside it. We do not know which nodes they are, but we can interactively probe the tree by choosing any subset of nodes.

codeforcescompetitive-programmingbinary-searchdfs-and-similargraphsinteractiveshortest-pathstrees
CF 1370B - GCD Compression

We are given an array of length $2n$. We are allowed to remove exactly two elements permanently. After that, the remaining $2n-2$ elements must be partitioned into pairs. Each pair is replaced by the sum of its two elements, producing an array $b$ of length $n-1$.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 1370D - Odd-Even Subsequence

We are given a sequence of numbers and asked to choose a subsequence of fixed length $k$. Once we pick this subsequence, we alternate its elements into odd and even positions based on their order inside the subsequence, not their original positions in the array.

codeforcescompetitive-programmingbinary-searchdpdsugreedyimplementation
CF 1369F - BareLee

Each round is a two-player deterministic game played on a single integer. A round starts with a value $si$ on a board and a limit $ei$. Players alternate turns, and on each turn the current value $a$ must be replaced by either $a+1$ or $2a$.

codeforcescompetitive-programmingdfs-and-similardpgames
CF 1369D - TediousLee

The structure in this problem is a very specific rooted tree that grows level by level. Starting from a single node, each level expands every vertex depending on how many children it already has.

codeforcescompetitive-programmingdpgraphsgreedymathtrees
CF 1368H2 - Breadboard Capacity (hard version)

The structure we are working with is a rectangular grid where every cell is a junction and every boundary cell has a port attached to one of the two external systems. Each port is either red or blue.

codeforcescompetitive-programming
CF 1368C - Even Picture

We are asked to construct a set of grid cells on an infinite checkerboard, where each chosen cell is considered “gray”. The shape we build must behave like a graph: cells are vertices, and edges connect cells that share a side. The construction must satisfy three conditions.

codeforcescompetitive-programmingconstructive-algorithms
CF 1368F - Lamps on a Circle

We are playing an interactive game on a circular array of n positions. All positions start empty. On each turn, the player is allowed to pick a number k and activate any k positions.

codeforcescompetitive-programminggamesimplementationinteractivemath
CF 1367F2 - Flying Sort (Hard Version)

We are given a sequence of numbers and a very specific way to reorder it. In one operation, we pick any element and either push it all the way to the front or all the way to the back of the array.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedysortingstwo-pointers
CF 1367D - Task On The Board

We are given a multiset of lowercase letters, initially written as a string $s$. From this multiset, some letters are discarded and the remaining letters are rearranged arbitrarily to form a new string $t$.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationsortings
CF 1367B - Even Array

We are given an array where each position has a fixed “required parity”: even indices must contain even numbers, and odd indices must contain odd numbers.

codeforcescompetitive-programminggreedymath
CF 1366D - Two Divisors

Each input value can be viewed as a box labeled with an integer, and for every box we must choose two non-trivial divisors of that number.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 1365F - Swaps Again

We are given two arrays of equal length and a very specific transformation rule. Starting from the first array, we are allowed to repeatedly pick a split size and swap two equal-length blocks: the prefix of that size and the suffix of the same size.

codeforcescompetitive-programmingconstructive-algorithmsimplementationsortings
CF 1365G - Secure Password

We are given an unknown array of non-negative integers, each up to 64-bit range. We cannot see the array directly. Instead, we can query any subset of indices, and the judge returns the bitwise OR of the elements at those positions.

codeforcescompetitive-programmingbitmaskscombinatoricsconstructive-algorithmsinteractivemath
CF 1364B - Most socially-distanced subsequence

We are given a permutation, which means every number from 1 to n appears exactly once, just in some order. From this array we are allowed to delete elements and keep the remaining ones in the same relative order, forming a subsequence.

codeforcescompetitive-programminggreedytwo-pointers
CF 1364E - X-OR

We are given a hidden arrangement of the numbers from 0 to n−1 placed at indices 1 through n. The only way to gain information is to choose two different positions and receive the bitwise OR of the values stored at those positions.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdivide-and-conquerinteractiveprobabilities
CF 1363D - Guess The Maximums

We are given an array $A$ of length $n$, but we cannot see it directly. Instead, we can ask queries: pick any subset of indices and the judge returns the maximum value of $A$ over those indices. Along with this hidden array, we are given $k$ special index sets $S1, S2, dots, Sk$.

codeforcescompetitive-programmingbinary-searchimplementationinteractivemath
CF 1363E - Tree Shuffling

We are given a rooted tree where each node carries two bits of information: an initial binary digit and a desired final binary digit.

codeforcescompetitive-programmingdfs-and-similardpgreedytrees
CF 1362C - Johnny and Another Rating Drop

We are given a sequence that always contains consecutive integers starting from 0 up to some number n. Each number is viewed in binary, and all numbers are conceptually padded with leading zeros so they share the same bit length.

codeforcescompetitive-programmingbitmasksgreedymath
CF 1362A - Johnny and Ancient Computer

We are given a starting number and a target number, and we are allowed to transform the starting value using a very specific set of operations.

codeforcescompetitive-programmingimplementation
CF 1361C - Johnny and Megan's Necklace

Each input item is a small “edge gadget” consisting of two pearls, and each pearl has an integer color in the range $[0, 2^{20})$. The goal is to take all these $n$ gadgets and connect their endpoints into one single cycle that uses every pearl exactly once.

codeforcescompetitive-programmingbinary-searchbitmasksconstructive-algorithmsdfs-and-similardsugraphs
CF 1361D - Johnny and James

We are given a set of points on the plane, one of which is guaranteed to be the origin. From these points, we must keep exactly k points and delete the rest.

codeforcescompetitive-programminggreedyimplementationmathtrees
CF 1360G - A/B Matrix

We are asked to construct a binary grid of size $n times m$, where each cell is either 0 or 1, under two simultaneous constraints that tightly couple rows and columns. Every row must contain exactly $a$ ones, and every column must contain exactly $b$ ones.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1360C - Similar Pairs

We are given several independent arrays, each with an even number of elements. For each array, we must decide whether it is possible to split all elements into disjoint pairs such that every number belongs to exactly one pair and each pair satisfies a compatibility rule.

codeforcescompetitive-programmingconstructive-algorithmsgraph-matchingsgreedysortings
CF 1359E - Modular Stability

We are asked to count how many strictly increasing sequences of length $k$, chosen from the integers $1$ to $n$, have a very strong invariance property under repeated modulo operations.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 1359F - RC Kaboom Show

We are given a collection of moving objects on an infinite plane. Each object starts from a fixed point, has a fixed direction, and moves in a straight line with a fixed speed.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresgeometrymath
CF 1358D - The Best Vacation

We are given a sequence of months laid out in order, where each month has a fixed length in days. If we flatten the calendar, each day becomes a single linear timeline, but each position still knows its position inside its month, from day 1 up to day $di$.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedyimplementationtwo-pointers
CF 1358E - Are You Fired?

We are effectively given a partially known array of length $n$. The first half (rounded up) is explicitly provided, while the second half is completely uniform and equal to a constant value $x$. So after reading the input, the entire sequence is actually determined.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyimplementation
CF 1355F - Guess Divisors Count

We are given a hidden integer $X$ in each game, but we are never allowed to see it directly. Instead, we can query any integer $Q$, and the judge returns $gcd(X, Q)$.

codeforcescompetitive-programmingconstructive-algorithmsinteractivenumber-theory
CF 1355D - Game With Array

We are asked to construct a positive integer array of length $N$ whose total sum is exactly $S$. After building this array, we also choose an integer $K$ between $0$ and $S$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1354G - Find a Gift

We are given a row of boxes, each box hiding either a valuable gift or a stone. Exactly k boxes contain gifts, and every other box contains stones. The key structural property is about weights.

codeforcescompetitive-programmingbinary-searchinteractiveprobabilities
CF 1354C2 - Not So Simple Polygon Embedding

We are given a regular polygon with $2n$ vertices, all edges equal to 1. The polygon is convex, and we are allowed to rotate it freely. We must place it inside a square, also freely rotatable, such that every point of the polygon lies inside or on the square boundary.

codeforcescompetitive-programmingbinary-searchbrute-forcegeometrymath
CF 1354C1 - Simple Polygon Embedding

We are working with a fixed geometric object: a regular polygon with $2n$ sides, each side having length 1. This polygon is convex and highly symmetric, so its shape is completely determined once we fix how it is oriented and scaled in the plane.

codeforcescompetitive-programmingbinary-searchgeometrymathternary-search
CF 1352B - Same Parity Summands

We are asked to split a given integer $n$ into exactly $k$ positive parts such that all parts share the same parity. This means we must choose either all odd numbers or all even numbers, and these $k$ numbers must sum exactly to $n$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1352A - Sum of Round Numbers

The task is about breaking a given integer into simpler building blocks, where each building block is a number that looks like a single non-zero digit followed only by zeros. These are numbers such as 7, 40, 900, or 3000.

codeforcescompetitive-programmingimplementationmath
CF 1350A - Orac and Factors

We start with a number and repeatedly apply a very specific transformation: find its smallest divisor greater than 1, and add that value to the number. This operation changes the number itself, so the divisor we use may change at every step.

codeforcescompetitive-programmingmath
CF 1348E - Phoenix and Berries

We are given several shrubs, each containing two independent piles of berries: red and blue. From these sources we want to form as many baskets as possible, where every basket must contain exactly $k$ berries.

codeforcescompetitive-programmingbrute-forcedpgreedymath
CF 1348B - Phoenix and Beauty

We are given an array and allowed to insert additional values anywhere inside it, where every inserted value must stay within the same value range as the original array elements.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedysortings
CF 1348C - Phoenix and Distribution

We are given a string made of lowercase letters and we are allowed to split all of its characters into exactly k non-empty groups. Inside each group, we can reorder characters arbitrarily, so each group is effectively just a multiset of letters that we later sort into a string.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortingsstrings
CF 1346I - Pac-Man 2.0

The game world is a directed graph with up to 15 locations, each location containing a fixed number of pellets. From any location you can reach any other, so the graph is strongly connected.

codeforcescompetitive-programming*specialdp
CF 1346C - Spring Cleaning

We are given a row of shelves, each holding some number of books. The goal is to reach a state where every shelf has at most k books. We are allowed to modify the configuration using two operations.

codeforcescompetitive-programming*specialgreedysortings
CF 1346D - Constructing the Dungeon

We are given an undirected connected graph where vertices represent rooms and edges represent tunnels. Each tunnel already has a fixed value, and we must assign a value to every room.

codeforcescompetitive-programming*specialgraphsgreedy
CF 1345B - Card Constructions

We are given a supply of identical cards and we repeatedly build structures called pyramids. A pyramid of height 1 is the smallest possible structure, and every higher pyramid is built in layers: a taller pyramid consists of a smaller pyramid placed on top of a wider base made…

codeforcescompetitive-programmingbinary-searchbrute-forcedpmath
CF 1344E - Train Tracks

The system is a rooted tree of stations, where every node with children behaves like a router that forwards all incoming trains to exactly one of its children.

codeforcescompetitive-programmingdata-structurestrees
CF 1344F - Piet's Palette

We are given a hidden initial configuration of a length-n array. Each position contains either one of three primary colors or is empty. We never observe this initial array directly. Instead, we observe a sequence of operations applied to it over time.

codeforcescompetitive-programmingmatrices
CF 1344D - Résumé Review

We are given several categories of projects, and for each category we know how many projects exist. From each category we choose some number of projects to place on a résumé, with the constraint that the total number of chosen projects is exactly $k$, and we cannot pick more…

codeforcescompetitive-programmingbinary-searchgreedymath
CF 1344C - Quantifier Question

We are given a directed graph on variables $x1, x2, dots, xn$. Each constraint $xj < xk$ behaves like an edge $j to k$, and a full assignment of real values satisfies the formula only if every edge points from a smaller value to a larger value.

codeforcescompetitive-programmingdfs-and-similardpgraphsmath
CF 1343F - Restore the Permutation by Sorted Segments

We are given an unknown permutation of numbers from 1 to n. Instead of seeing it directly, we receive n−1 pieces of information, each piece being a multiset segment taken from the permutation.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdata-structuresgreedyimplementation
CF 1343E - Weights Distributing

We are given a connected undirected graph where each edge represents a road, but the roads do not yet have fixed costs. Instead, we are also given a list of prices, and we must assign exactly one price to each edge.

codeforcescompetitive-programmingbrute-forcegraphsgreedyshortest-pathssortings
CF 1342C - Yet Another Counting Problem

We are working with integers and modular arithmetic, but the structure becomes clearer if we think of the infinite number line as being colored by a periodic rule. For any integer $x$, we compute two values: first we take $x bmod a$, then reduce that result modulo $b$.

codeforcescompetitive-programmingmathnumber-theory
CF 1342B - Binary Period

We are given a binary string and asked to embed it into a larger binary string while preserving order as a subsequence.

codeforcescompetitive-programmingconstructive-algorithmsstrings
CF 1340A - Nastya and Strange Generator

The process builds a permutation from left to right, but the choice at each step is not based on already placed numbers.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedyimplementation
CF 1340C - Nastya and Unexpected Guest

We are given a straight road modeled as integer points from 0 to n. Some of these points are special positions called safety islands, including both endpoints. Denis starts at 0 at time zero and wants to reach n as fast as possible.

codeforcescompetitive-programmingdfs-and-similardpgraphsshortest-paths
CF 1339B - Sorted Adjacent Differences

We are given several independent arrays, and for each one we must reorder its elements into a sequence where the absolute differences between neighboring elements never decrease as we move from left to right.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 1338C - Perfect Triples

We are building an infinite sequence by repeatedly selecting groups of three unused positive integers. Each group must satisfy a strict bitwise condition: the XOR of the three numbers is zero.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsdivide-and-conquermath
CF 1338D - Nested Rubber Bands

We are given a tree, and the problem asks us to think about a geometric construction that can be performed on it. Each vertex becomes a closed non-self-intersecting curve on a plane.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardpmathtrees
CF 1337A - Ichihime and Triangle

We are given four integers in non-decreasing order, and we need to choose three lengths from three separate intervals. The first length must come from the first interval, the second from the second interval, and the third from the third interval.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1336D - Yui and Mahjong Set

We are dealing with a hidden multiset of tiles where each tile carries a value from 1 to n. The hidden configuration can be thought of as an array of frequencies a₁, a₂, …, aₙ, where aᵢ is the number of tiles with value i.

codeforcescompetitive-programmingconstructive-algorithmsinteractive
CF 1336C - Kaavi and Magic Spell

We are given two strings. The first string represents a queue of characters that we will consume from the left. The second string is a target pattern.

codeforcescompetitive-programmingdpstrings
CF 1335E2 - Three Blocks Palindrome (hard version)

Codeforces 1335E2: Three Blocks Palindrome (hard version)

codeforcescompetitive-programmingbrute-forcedata-structuresdptwo-pointers
CF 1335F - Robots on a Grid

Each cell in the grid behaves like a deterministic state in a directed graph. From every cell, there is exactly one outgoing edge pointing to one of its four neighbors, as dictated by the arrow in that cell.

codeforcescompetitive-programmingdata-structuresdfs-and-similardsugraphsgreedymatrices
CF 1335C - Two Teams Composing

We are given a multiset of student skills for each test case. From this pool we must form two disjoint groups of students, both of the same size, say $x$.

codeforcescompetitive-programmingbinary-searchgreedyimplementationsortings
CF 1335D - Anti-Sudoku

We start with a fully valid Sudoku grid. Every row, every column, and every 3 by 3 subgrid contains the digits 1 through 9 exactly once.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1334D - Minimum Euler Cycle

We are asked to construct a walk in a complete directed graph on vertices labeled from 1 to n, where every ordered pair of distinct vertices forms a directed edge. This means between any two different vertices u and v, both directions u → v and v → u exist.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedyimplementation
CF 1334C - Circle of Monsters

We are given a ring of monsters. Each monster has an initial health value, and also a fixed explosion damage value that is applied to its next neighbor when it dies.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedymath
CF 1333B - Kind Anton

We are given two integer arrays of the same length. The first array starts with very restricted values, each position being either negative one, zero, or positive one. The second array can contain arbitrary integers, potentially very large in magnitude.

codeforcescompetitive-programminggreedyimplementation
CF 1333C - Eugene and an array

We are given a sequence of integers and asked to count how many contiguous segments of this sequence are “robust” in a very specific sense. A segment is considered valid if every one of its nonempty contiguous subsegments has a sum that is not zero.

codeforcescompetitive-programmingbinary-searchdata-structuresimplementationtwo-pointers
CF 1332G - No Monotone Triples

We are given an array of numbers and many queries over subsegments. For each query interval $[L, R]$, we must pick a subsequence of indices inside this interval, in increasing order, with length at least 3, such that the chosen values contain no triple of indices $i < j < k$…

codeforcescompetitive-programmingdata-structures
CF 1332E - Height All the Same

We are given a rectangular grid with $n times m$ cells, and each cell starts with some integer height $a{i,j}$. The game allows two types of moves that increase heights: either we add one cube to two adjacent cells at the same time, or we add two cubes to a single cell.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsmathmatrices
CF 1331G - Lingua Romana

We are given a short program written in a heavily stylized “Roman-like” pseudocode language. The program reads a sequence of integers from standard input, and for each integer it computes a numeric function and prints either a formatted value or a special overflow message.

codeforcescompetitive-programming*special
CF 1331D - Again?

We are given a single 7-character number written in a mixed numeral system. The first character is always the letter A, which should be interpreted as the value 10. The remaining six characters are digits from 0 to 9. Together, they form a base-11 number of fixed length 7.

codeforcescompetitive-programming*specialimplementation
CF 1329E - Dreamoon Loves AA

We are given a very long binary string consisting only of the characters A and B, with the guarantee that the first and last characters are always A. In addition to these fixed endpoints, we are given the positions of some other A characters inside the string.

codeforcescompetitive-programmingbinary-searchgreedy
CF 1329D - Dreamoon Likes Strings

We are given a string that evolves under a deletion game. In one move, we are allowed to pick a contiguous substring, but only if that substring is “locally alternating”, meaning no two adjacent characters inside it are equal.

codeforcescompetitive-programmingconstructive-algorithmsdata-structures
CF 1329B - Dreamoon Likes Sequences

We are asked to count how many strictly increasing sequences of integers we can choose from the range $[1, d]$, with an extra constraint that depends on cumulative XORs of the chosen values.

codeforcescompetitive-programmingbitmaskscombinatoricsmath
CF 1329C - Drazil Likes Heap

Codeforces 1329C: Drazil Likes Heap

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyimplementation
CF 1329A - Dreamoon Likes Coloring

We are given a row of cells initially all unpainted. We will perform a sequence of painting operations, where each operation paints a contiguous segment of fixed length, but we are free to choose the starting position of that segment.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 1328F - Make k Equal

Codeforces 1328F: Make k Equal

codeforcescompetitive-programminggreedy
CF 1328D - Carousel

We are given a circular arrangement of positions, each holding an animal type. The positions are connected in a cycle, so after the last position comes the first again. We must assign a color to each position.

codeforcescompetitive-programmingconstructive-algorithmsdpgraphsgreedymath
CF 1328C - Ternary XOR

We are given a ternary string x, meaning each position is a digit among 0, 1, or 2. The task is to split this single number into two ternary numbers a and b, both of the same length as x, such that if we add them digit by digit modulo 3, we recover x.

codeforcescompetitive-programminggreedyimplementation
CF 1327C - Game with Chips

We are given a grid of size $n times m$ with several chips placed on cells. Each chip can be moved simultaneously with all others by applying a single global move in one of four directions: up, down, left, or right.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1327F - AND Segments

We are building an array of length $n$, where each position stores an integer with at most $k$ bits. On top of that, we are given several constraints, each describing a segment $[l, r]$ and a required value for the bitwise AND of all elements in that segment.

codeforcescompetitive-programmingbitmaskscombinatoricsdata-structuresdptwo-pointers
CF 1326E - Bombs

We are given a permutation p, which we can think of as values arriving in a fixed order from position 1 to n. While processing this order, we maintain a multiset A. Each time we process position i, we insert p[i] into A.

codeforcescompetitive-programmingdata-structurestwo-pointers
CF 1326D2 - Prefix-Suffix Palindrome (Hard version)

We are given a string and we want to build the longest possible palindrome that can be formed by taking a prefix of the string, a suffix of the string, or both, and concatenating them in that order.

codeforcescompetitive-programmingbinary-searchgreedyhashingstring-suffix-structuresstrings
CF 1326G - Spiderweb Trees

We are given a geometric tree: each vertex is a point in the plane and edges form a non-crossing tree. This already means the embedding is fixed, so geometric notions like convex hull are meaningful relative to the given drawing.

codeforcescompetitive-programmingdpgeometrytrees
CF 1325E - Ehab's REAL Number Theory Problem

We are given a sequence of integers, and we want to select a subsequence whose product becomes a perfect square. Among all such subsequences, we need the minimum possible length.

codeforcescompetitive-programmingbrute-forcedfs-and-similargraphsnumber-theoryshortest-paths
CF 1325B - CopyCopyCopyCopyCopy

We are given an array and we construct a much larger array by repeating it end-to-end many times. The repetition count is equal to the original length of the array, so the final sequence has size $n cdot n$.

codeforcescompetitive-programminggreedyimplementation
CF 1324A - Yet Another Tetris Problem

We are given a sequence of column heights representing a vertical terrain. Each column has some initial number of blocks stacked on it. The only operation available is to repeatedly choose a column and place a fixed vertical piece that increases that column’s height by 2.

codeforcescompetitive-programmingimplementationnumber-theory
CF 1324D - Pair of Topics

We are given a list of topics, each topic carrying two different scores. One score measures how interesting the topic is for the teacher, and the other measures how interesting it is for students.

codeforcescompetitive-programmingbinary-searchdata-structuressortingstwo-pointers
CF 1323A - Even Subset Sum Problem

We are given several independent arrays of positive integers. For each array, we must select a non-empty group of positions such that the sum of the chosen values is even. If no such group exists, we report failure.

codeforcescompetitive-programmingbrute-forcedpgreedyimplementation
CF 1322F - Assigning Fares

We are given a tree with $n$ stations and $n-1$ tunnels, so between any two stations there is exactly one simple path. On this tree, we are also given $m$ special routes.

codeforcescompetitive-programmingdptrees
CF 1322A - Unusual Competitions

We are given a string consisting only of parentheses, and we are allowed to modify it using an operation that picks any contiguous segment and permutes its characters arbitrarily. The cost of such an operation equals the length of the chosen segment.

codeforcescompetitive-programminggreedy
CF 1321C - Remove Adjacent

We are given a string of lowercase letters. We repeatedly remove characters under a local rule: a character can be deleted only if at least one of its current neighbors is exactly one letter earlier in the alphabet than itself.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedystrings
CF 1320D - Reachable Strings

We are given a fixed binary string, and we repeatedly consider two kinds of local transformations on any contiguous segment of length three: swapping 011 into 110, or the reverse swap 110 into 011.

codeforcescompetitive-programmingdata-structureshashingstrings
CF 1320B - Navigation System

We are given a directed graph where intersections are nodes and roads are one-way edges. We also know a fixed simple route Polycarp actually drives from his home to his work.

codeforcescompetitive-programmingdfs-and-similargraphsshortest-paths
CF 1316F - Battalion Strength

We are given a list of officers, each with a numerical power. From these officers, a battalion is formed by choosing any subset uniformly at random, including the empty set.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerprobabilities
CF 1315C - Restoring Permutation

We are given a sequence of values that are meant to represent the smaller element in each of several disjoint pairs. In the final construction, we must build an array of length 2n using every number from 1 to 2n exactly once, and then split it into n consecutive pairs.

codeforcescompetitive-programminggreedy
CF 1315B - Homecoming

We are given a one-dimensional town represented as a line of crossroads indexed from 1 to n. Each position has exactly one type of transport station: either type A (bus-compatible segment marker) or type B (tram-compatible segment marker). The string s encodes this layout.

codeforcescompetitive-programmingbinary-searchdpgreedystrings