brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 940E - Cashback

We are given a sequence of numbers, and we need to break it into contiguous segments. Each segment is evaluated independently, and then we sum up the segment scores.

codeforcescompetitive-programmingdata-structuresdpgreedymath
CF 940B - Our Tanya is Crying Out Loud

We start with a single integer value x = n and repeatedly transform it until it becomes 1. Each move either reduces the value by one at a fixed cost A, or divides the current value by k at cost B, but division is only allowed when the current value is exactly divisible by k.

codeforcescompetitive-programmingdpgreedy
CF 946F - Fibonacci String Subsequences

We are given a binary pattern string s and we want to measure how often this pattern appears inside many different strings derived from a very specific construction. The large string we care about is not arbitrary. It comes from a Fibonacci-style concatenation process.

codeforcescompetitive-programmingcombinatoricsdpmatrices
CF 946E - Largest Beautiful Number

We are given a large number represented as a string, and for each query we need to construct a strictly smaller number that satisfies a structural property. A number is considered valid if it has an even number of digits and its digits can be rearranged to form a palindrome.

codeforcescompetitive-programminggreedyimplementation
CF 946A - Partition

We are given a list of integers, and we are allowed to split this list into two groups in any way we like, with the only rule that every element must belong to exactly one of the two groups.

codeforcescompetitive-programminggreedy
CF 946C - String Transformation

We are given a string made of lowercase English letters. We are allowed to perform an operation that only increases a character by one step in the alphabet, for example turning c into d or a into b. Characters cannot decrease, and z is terminal.

codeforcescompetitive-programminggreedystrings
CF 948A - Protect Sheep

The grid can be viewed as a rectangular graph where each cell is a node connected to its four orthogonal neighbors. Some nodes contain sheep, some contain wolves, and the rest are empty.

codeforcescompetitive-programmingbrute-forcedfs-and-similargraphsimplementation
CF 949C - Data Center Maintenance

Codeforces 949C: Data Center Maintenance

codeforcescompetitive-programmingdfs-and-similargraphs
CF 949D - Curfew

There are n rooms arranged in a line. Each room must end up with exactly b students being counted by inspectors, but initially the distribution is arbitrary as an array a[i], and the total number of students equals n · b, so globally there is just enough “mass” to satisfy…

codeforcescompetitive-programmingbinary-searchbrute-forcegreedysortings
CF 949F - Astronomy

We are given 2n lattice points in the plane, each representing a star. Somewhere in the original astronomical configuration there existed a special point, the Moon, with integer coordinates, such that the stars could be partitioned into n pairs with a very rigid geometric…

codeforcescompetitive-programminggeometryprobabilities
CF 949E - Binary Cards

We are allowed to build a multiset of “coins”, where each coin has a value that is either a positive or negative power of two. In every round, a target integer is announced, and we must be able to select some subset of our fixed coins so that their sum equals that target.

codeforcescompetitive-programmingbrute-force
CF 949B - A Leapfrog in the Array

We start with numbers from 1 to $n$. Instead of placing them directly into positions $1$ through $n$, each number $i$ is initially placed at position $2i-1$. So the array of length $2n$ has numbers only in odd positions, while even positions are empty.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 949A - Zebras

We are given a binary string representing a chronological sequence of days, where each character is either 0 or 1.

codeforcescompetitive-programminggreedy
CF 950A - Left-handers, Right-handers and Ambidexters

We are given three groups of players at a training session: people who can only use the left hand, people who can only use the right hand, and ambidextrous players who can be assigned to either hand.

codeforcescompetitive-programmingimplementationmath
CF 950B - Intercepted Message

We are given two sequences of positive integers, each sequence representing how a long stream of bytes was transmitted in chunks. Each sequence is a segmentation of the same total length, but the segmentation points are different.

codeforcescompetitive-programminggreedyimplementation
CF 952E - Cheese Board

We are given a set of cheeses, each cheese has a unique name and a label indicating whether it is soft or hard. The names are just identifiers, but they can still be ordered lexicographically and used to define structure if needed.

codeforcescompetitive-programming*special
CF 952F - 2 + 2 != 4

The input is a short arithmetic expression containing small non-negative integers and only two operations: addition and subtraction. There are no parentheses, no multiplication, and no hidden formatting rules beyond the usual infix notation.

codeforcescompetitive-programming*special
CF 952A - Quirky Quantifiers

We are given a single integer a, guaranteed to be a three-digit or two-digit number between 10 and 999. The task is to output either 0 or 1 based on a hidden property of this number.

codeforcescompetitive-programming*specialmath
CF 952B - A Map of the Cat

We are interacting with a single unknown “cat”, but we are not told directly whether it behaves like a normal cat or a grumpy one. Instead, the cat is split into 10 labeled regions from 0 to 9, and we can probe the cat by choosing a region to pet.

codeforcescompetitive-programming*specialbrute-forceinteractive
CF 954F - Runner's Problem

We are given a 3 by m grid where movement is always one column to the right and can also shift vertically by at most one row. The journey starts in the middle row of the first column and must end in the same middle row at the last column.

codeforcescompetitive-programmingdpmatricessortings
CF 954I - Yet Another String Matching Problem

We are given two strings, one long string and one pattern string, both over a very small alphabet of size six. We slide the pattern across the long string, and for each position we take a substring of the same length as the pattern.

codeforcescompetitive-programmingfftmath
CF 954E - Water Taps

Each tap contributes a controllable flow of water, but every tap has a fixed temperature. You are allowed to choose a real-valued flow rate for each tap between zero and its maximum capacity.

codeforcescompetitive-programmingbinary-searchgreedysortings
CF 954B - String Typing

We are given a string that we want to construct starting from an empty string. Each action costs one operation. The basic action is appending a single character to the end of what we already have.

codeforcescompetitive-programmingimplementationstrings
CF 954A - Diagonal Walking

We are given a sequence of moves on a grid where each move is either one step to the right or one step upward. The key operation allowed is merging a right move and an up move when they are adjacent in either order.

codeforcescompetitive-programmingimplementation
CF 955F - Heaps

We are given a rooted tree with $n$ nodes, rooted at node 1. For every node $u$, we consider a family of structures defined by an integer $k$, where a node can be thought of as the root of a “$k$-ary heap of depth $m$” if it has at least $k$ child-subtrees that themselves…

codeforcescompetitive-programmingdptrees
CF 955E - Icicles

We have a line of positions from 1 to n, each position containing an icicle with an initial height a[i]. Over time, two things happen: a sound wave spreads from a chosen starting point T, and the icicles touched by the wave begin to melt downward.

codeforcescompetitive-programming
CF 955A - Feed the cat

Andrew wakes up at a given time of day and realizes his cat is hungry. The cat starts with some initial hunger value, and this hunger grows steadily over time at a fixed rate per minute. Andrew can reduce the cat’s hunger only by buying buns.

codeforcescompetitive-programminggreedymath
CF 955B - Not simply beatiful strings

We are given a single lowercase string. The task is to decide whether we can split its positions into two disjoint subsequences such that each subsequence forms a string that can be rearranged into exactly two contiguous blocks of equal characters, and those two blocks must…

codeforcescompetitive-programmingimplementation
CF 957A - Tritonic Iridescence

We are given a one-dimensional strip of length $n$, where each position is either already painted in one of three colors or left blank. The blank positions must be filled using the same three colors so that no two adjacent positions end up sharing the same color.

codeforcescompetitive-programmingimplementation
CF 958F1 - Lightsabers (easy)

We are given a line of Jedi, each occupying a fixed position in an array, and each Jedi has one of several possible lightsaber colors. Alongside this, we are given a target specification that tells us how many Jedi of each color we must pick.

codeforcescompetitive-programmingimplementation
CF 958E3 - Guard Duty (hard)

We are given two sets of points in the plane, each containing the same number of points. One set represents spaceships, the other represents bases. Every point has a unique location, and no three points lie on a single straight line.

codeforcescompetitive-programminggeometry
CF 958E1 - Guard Duty (easy)

We are given two small point sets in the plane, one representing Rebel ships and the other representing bases. Each ship must be assigned to exactly one base, and each base must also receive exactly one ship, so the assignment is a bijection between the two sets.

codeforcescompetitive-programmingbrute-forcegeometrygreedymath
CF 958B2 - Maximum Control (medium)

We are given a tree with $N$ nodes, meaning every pair of nodes is connected by exactly one simple path. We are allowed to choose $K$ nodes as “active stations”.

codeforcescompetitive-programmingdata-structuresdfs-and-similargraphsgreedytrees
CF 958C2 - Encryption (medium)

We are given a sequence of integers and asked to cut it into exactly $k$ contiguous non-empty segments. Each element must belong to exactly one segment, and the order of elements is preserved. For any segment, we take the sum of its elements, then reduce that sum modulo $p$.

codeforcescompetitive-programmingdp
CF 958A2 - Death Stars (medium)

We are given two rectangular grids of characters. The first grid has size $N times M$, while the second grid has size $M times N$.

codeforcescompetitive-programminghashingstrings
CF 958A3 - Death Stars (hard)

We are given two separate point clouds in the plane. Each cloud contains many points, and both clouds include the same set of “true” points, but mixed with additional noise points.

codeforcescompetitive-programming
CF 959E - Mahmoud and Ehab and the xor-MST

We are given a complete graph on vertices labeled from 0 to n − 1. Every pair of distinct vertices is connected, and the weight of the edge between u and v is the bitwise XOR of their labels.

codeforcescompetitive-programmingbitmasksdpgraphsimplementationmath
CF 959C - Mahmoud and Ehab and the wrong algorithm

We are given a tree with n vertices and asked to construct two different trees on the same number of vertices, each meant to expose the failure or correctness of a specific heuristic for minimum vertex cover. The heuristic is extremely simple.

codeforcescompetitive-programmingconstructive-algorithmstrees
CF 959A - Mahmoud and Ehab and the even-odd game

The game starts with a single integer value, and two players alternately reduce it. On Mahmoud’s turn, he is only allowed to subtract an even positive number that does not exceed the current value.

codeforcescompetitive-programminggamesmath
CF 960G - Bandit Blues

We are given a permutation of the numbers from 1 to N, and we simulate a simple “record-breaking” process on it. We start with a virtual value 0.

codeforcescompetitive-programmingcombinatoricsdpfftmath
CF 960E - Alternating Tree

We are given a tree with a value attached to every node. Between any two nodes $u$ and $v$, there is exactly one simple path, and we assign a score to that directed path by taking the node values along the path and alternating their signs, starting with a positive sign at the…

codeforcescompetitive-programmingcombinatoricsdfs-and-similardivide-and-conquerdpprobabilitiestrees
CF 960B - Minimize the error

We are working with two integer arrays of equal length. Each position contributes independently to a total “error”, where the error of an index is the square of the difference between the two values at that index.

codeforcescompetitive-programmingdata-structuresgreedysortings
CF 960A - Check the string

We are given a string made only of the characters a, b, and c. This string is claimed to have been constructed in a very specific way: it starts with one or more a characters, then some b characters are appended, and finally some c characters are appended at the end.

codeforcescompetitive-programmingimplementation
CF 961F - k-substrings

We are given a string $s$ of length $n$, and we consider all of its suffixes. For each starting position $k$, the corresponding substring is $s[k..n]$. The task is to analyze each of these suffixes independently.

codeforcescompetitive-programmingbinary-searchhashingstring-suffix-structures
CF 961G - Partitions

We are given $n$ weighted elements. Each element $i$ has a weight $wi$. We consider all ways to split these $n$ elements into exactly $k$ non-empty groups. Each such grouping is an unordered partition, so only the membership structure matters, not any labeling of groups.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 961C - Chessboard

We are given four separate square fragments of a chessboard, each fragment being an $n times n$ grid where every cell is already colored either black or white. The value $n$ is odd, and the goal is to assemble these four pieces into a larger $2n times 2n$ chessboard.

codeforcescompetitive-programmingbitmasksbrute-forceimplementation
CF 961A - Tetris

We are simulating a process where squares arrive one by one and stack up in columns. There are n columns, and each incoming square chooses a column and lands on top of whatever is already there, increasing that column’s height by one.

codeforcescompetitive-programmingimplementation
CF 962F - Simple Cycles Edges

We are given an undirected simple graph and asked to identify which edges are “exclusive” to a single simple cycle.

codeforcescompetitive-programmingdfs-and-similargraphstrees
CF 962G - Visible Black Areas

We are given a simple orthogonal polygon, meaning its edges are horizontal or vertical and it never self-intersects. The interior of this polygon is considered “black”. We also have a fixed axis-aligned rectangular window. The window is static and we look only through it.

codeforcescompetitive-programmingdata-structuresdsugeometrytrees
CF 962C - Make a Square

We are given a single positive integer written in decimal form. We are allowed to repeatedly remove digits from it, with the only restriction that the remaining number must always stay positive and must not acquire leading zeros.

codeforcescompetitive-programmingbrute-forceimplementationmath
CF 962A - Equator

We are given a sequence of days, and on each day Polycarp solves a fixed number of problems. If we look at the entire training period, there is a total number of problems solved across all days.

codeforcescompetitive-programmingimplementation
CF 963C - Cutting Rectangle

We are given a final collection of axis-aligned rectangles that come from cutting an unknown larger rectangle using only straight cuts parallel to its sides. Every cut is either horizontal or vertical, so the original rectangle is partitioned into a grid.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 963B - Destruction of a Tree

We are given a tree where each vertex has an associated current degree that changes as vertices are removed. A vertex is eligible for removal only when its degree is even at the moment we choose it.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardpgreedytrees
CF 964A - Splits

We are working with ways of writing an integer $n$ as a nonincreasing sequence of positive integers. In other words, we break $n$ into parts that never increase as we move to the right, and all parts must be positive.

codeforcescompetitive-programmingmath
CF 964B - Messages

We are given a sequence of messages that arrive over time. Each message arrives at a known minute and starts with a fixed value.

codeforcescompetitive-programmingmath
CF 965E - Short Code

We are given a collection of distinct lowercase strings, each representing a variable name. For each original name, we must choose a non-empty prefix of that string to act as its new shortened identifier.

codeforcescompetitive-programmingdata-structuresdpgreedystringstrees
CF 965B - Battleship

We are given an $n times n$ grid where each cell is either forbidden or allowed. Forbidden cells are marked with and can never be part of a ship. Allowed cells are marked with . and may be part of a ship.

codeforcescompetitive-programmingimplementation
CF 965C - Greedy Arkady

We are given a linear stream of $n$ candies and a fixed number of people $k$. A single parameter $x$ determines how the candies are distributed: candies are processed in consecutive blocks of size $x$.

codeforcescompetitive-programmingmath
CF 967B - Watering System

We are given a system of pipe holes, each hole having a fixed size that determines how much water it can drain when water is poured into the system. Arkady pours a fixed amount of water, but only one hole, the first one, is considered useful to him.

codeforcescompetitive-programmingmathsortings
CF 967A - Mind the Gap

We are given a timeline of scheduled landings, each occupying exactly one minute, already sorted in increasing order. We must insert one additional event, a takeoff that also lasts one minute, into this timeline. The key restriction is safety spacing.

codeforcescompetitive-programmingimplementation
CF 975E - Hag's Khashba

We are given a rigid strictly convex polygon with fixed geometry in the plane. Its vertices are labeled in order, and initially the polygon already sits in some stable position.

codeforcescompetitive-programminggeometry
CF 975B - Mancala

We are given a circular board with 14 positions. Each position contains some number of stones. One move consists of picking a single position that has stones, removing all stones from it, and then distributing those stones one by one into subsequent positions moving clockwise…

codeforcescompetitive-programmingbrute-forceimplementation
CF 975A - Aramic script

Each word in the input is meant to describe an object, but the language has a normalization rule: two words represent the same object if they contain exactly the same set of distinct letters, ignoring how many times each letter appears and ignoring order.

codeforcescompetitive-programmingimplementationstrings
CF 976E - Well played!

Each creature starts with a fixed health value and a fixed damage value. We are allowed to improve the army using two global operations. One operation increases a creature’s health by doubling it, and the other operation overwrites a creature’s damage with its current health.

codeforcescompetitive-programminggreedysortings
CF 976A - Minimum Binary Number

We are given a binary string that is already in a valid canonical form, meaning it represents a non-negative integer in binary without unnecessary leading zeros.

codeforcescompetitive-programmingimplementation
CF 976C - Nested Segments

We are given a collection of closed intervals on a number line. Each interval represents a segment with a left endpoint and a right endpoint, and we need to determine whether there exists a pair of distinct segments such that one is fully contained inside the other.

codeforcescompetitive-programminggreedyimplementationsortings
CF 977F - Consecutive Subsequence

We are given a sequence of integers in the order they appear. From this sequence we want to pick some elements while preserving order, but we are only allowed to keep a subsequence that looks like a run of consecutive integers increasing by exactly one each step, such as $x…

codeforcescompetitive-programmingdp
CF 977D - Divide by three, multiply by two

We are given a multiset of integers that originally came from a single starting value that Polycarp repeatedly transformed. Each transformation either doubles the current number or divides it by three when it is divisible.

codeforcescompetitive-programmingdfs-and-similarmathsortings
CF 977C - Less or Equal

We are given a list of integers and asked to construct a value $x$ between 1 and $10^9$ such that exactly $k$ elements of the list are less than or equal to $x$. If no such value exists, we must output $-1$.

codeforcescompetitive-programmingsortings
CF 977B - Two-gram

We are given a string of uppercase English letters, and we are asked to look at every adjacent pair of characters in it. Each such adjacent pair forms a “two-letter pattern”, for example the string “ABAC” contains “AB”, “BA”, and “AC”.

codeforcescompetitive-programmingimplementationstrings
CF 977A - Wrong Subtraction

The task describes a very specific way of reducing a positive integer repeatedly. Instead of simply subtracting one in the usual arithmetic sense, the operation depends on the last digit of the number.

codeforcescompetitive-programmingimplementation
CF 978G - Petya's Exams

We are given a timeline of $n$ days and a set of $m$ exams, each fixed to happen on exactly one specific day. Every exam also comes with a preparation window that starts after its announcement day and ends the day before the exam itself, plus a required number of preparation…

codeforcescompetitive-programminggreedyimplementationsortings
CF 978F - Mentors

We are given a set of programmers, each with a fixed skill value. For any programmer $i$, we want to count how many other programmers $j$ they can “mentor”.

codeforcescompetitive-programmingbinary-searchdata-structuresimplementation
CF 978D - Almost Arithmetic Progression

We are given a sequence of integers, and we are allowed to slightly “tweak” each element independently by choosing to either decrease it by one, increase it by one, or leave it unchanged.

codeforcescompetitive-programmingbrute-forceimplementationmath
CF 978E - Bus Video System

We are given a sequence of recorded changes in the number of passengers on a bus. Each value tells us how the passenger count changes after a stop, so if we denote the starting number of passengers by $x$, then after each stop we repeatedly add the given deltas and obtain a…

codeforcescompetitive-programmingcombinatoricsmath
CF 978A - Remove Duplicates

We are given a sequence of integers and asked to compress it by removing duplicates, but with a specific rule: for every distinct value, only its last occurrence in the array must remain.

codeforcescompetitive-programmingimplementation
CF 978B - File Name

We are given a short string representing a file name. The only constraint that matters is that the substring "xxx" is forbidden anywhere inside the final string.

codeforcescompetitive-programminggreedystrings
CF 978C - Letters

We are given several dormitories arranged in a line. Each dormitory contains a known number of rooms, and all rooms across all dormitories are conceptually concatenated into one long sequence.

codeforcescompetitive-programmingbinary-searchimplementationtwo-pointers
CF 979E - Kuro and Topological Parity

We are given a line of numbered positions from 1 to n. Some positions already have a fixed color, either 0 or 1, while others are uncolored and must be assigned one of these two values.

codeforcescompetitive-programmingdp
CF 979D - Kuro and GCD and XOR and SUM

We are maintaining a dynamic multiset of positive integers. The structure supports insertions, and after each insertion phase we may receive queries asking us to pick one previously inserted value that satisfies three simultaneous constraints with respect to a fixed query triple.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcedata-structuresdpdsugreedymathnumber-theorystringstrees
CF 979C - Kuro and Walking Route

We are given a tree, meaning a connected graph with exactly one simple path between any two towns. Every ordered pair of distinct towns defines a walking route that follows that unique path. Among all possible ordered pairs of towns, some are considered invalid.

codeforcescompetitive-programmingdfs-and-similartrees
CF 979B - Treasure Hunt

We are given three strings of equal length, each representing a ribbon owned by one of three players. In one move, a player can change exactly one character in their string to any other letter.

codeforcescompetitive-programminggreedy
CF 979A - Pizza, Pizza, Pizza!!!

We are given a number of friends attending a pizza party, and the host must divide a circular pizza into exactly equal slices so that there are one slice per person, including the host. If there are $n$ friends, the pizza must be split into $n + 1$ equal parts.

codeforcescompetitive-programmingmath
CF 980F - Cactus to Tree

We are given a connected undirected graph with a special structure: every vertex can belong to at most one simple cycle. This means the graph looks like a tree where some disjoint cycles have been added, and those cycles never intersect at a vertex.

codeforcescompetitive-programmingdpgraphstrees
CF 980E - The Number Games

We are given a tree with $n$ nodes. Each node represents a district, and the road system guarantees there is exactly one simple path between any two districts.

codeforcescompetitive-programmingdata-structuresgreedytrees
CF 980B - Marlin

We are given a city shaped like a very small grid: it has exactly 4 rows and an odd number of columns. Two pairs of locations matter: the first journey starts at the top-left corner and wants to reach the bottom-right corner, while the second journey starts at the bottom-left…

codeforcescompetitive-programmingconstructive-algorithms
CF 980A - Links and Pearls

We are given a circular arrangement made of two kinds of characters: pearls represented by o and links represented by -. Because the structure is a necklace, the string is considered cyclic, meaning the last character is adjacent to the first.

codeforcescompetitive-programmingimplementationmath
CF 981H - K Paths

We are given a tree and we choose an ordered list of $k$ simple paths, where each path is defined by two endpoints in the tree. Because paths are on a tree, each pair of vertices determines a unique simple path.

codeforcescompetitive-programmingcombinatoricsdata-structuresdpfftmath
CF 981E - Addition on Segments

We start with an array of length $n$ filled with zeros. There are $q$ operations, each operation adds a positive value $xi$ to every position in a contiguous segment $[li, ri]$. We are not forced to apply all operations.

codeforcescompetitive-programmingbitmasksdata-structuresdivide-and-conquerdp
CF 981C - Useful Decomposition

We are given an undirected tree, and we must split all its edges into a collection of simple paths so that every edge belongs to exactly one path. The extra requirement is global and restrictive: if we pick any two of these paths, they must share at least one common vertex.

codeforcescompetitive-programmingimplementationtrees
CF 981A - Antipalindrome

We are given a single short string made of lowercase English letters. From this string, we are allowed to choose any contiguous substring. Among all such substrings, we are interested in those that are not palindromes, meaning they do not read the same forwards and backwards.

codeforcescompetitive-programmingbrute-forceimplementationstrings
CF 982E - Billiard

We are given a rectangular billiard table with corners at $(0,0)$, $(n,0)$, $(0,m)$, and $(n,m)$. A point-like ball starts from $(x,y)$ and moves in a straight line with direction components restricted to $-1, 0, 1$, meaning it travels horizontally, vertically, or along a…

codeforcescompetitive-programminggeometrynumber-theory
CF 982C - Cut 'em all!

We are given a tree, meaning a connected graph with no cycles, and every edge is available for us to potentially remove. The operation we are allowed to perform is cutting edges so that the graph splits into smaller connected components.

codeforcescompetitive-programmingdfs-and-similardpgraphsgreedytrees
CF 982A - Row

We are given a line of chairs, each either occupied by a person or empty. The configuration is represented as a binary string where 1 means a person is sitting and 0 means the seat is empty. A seating arrangement is considered valid only if no two people sit next to each other.

codeforcescompetitive-programmingbrute-forceconstructive-algorithms
CF 983E - NN country

The road network forms a tree of cities, so between any two cities there is exactly one simple path. On top of this fixed tree structure, there are additional “bus routes” between pairs of cities.

codeforcescompetitive-programmingbinary-searchdata-structurestrees
CF 983C - Elevator

We are controlling a single elevator in a small building with nine floors, and we must serve a sequence of people in a fixed arrival order. Each person starts on some floor and wants to reach another floor.

codeforcescompetitive-programmingdpgraphsshortest-paths
CF 983B - XOR-pyramid

We are given an array and many queries over its segments. Each query asks us to look at a contiguous part of the array, consider every possible subsegment inside it, and compute a special function on each subsegment.

codeforcescompetitive-programmingdp
CF 984A - Game

We are given a list of integers placed on a board. Two players alternate turns removing exactly one number from the board. After exactly $n-1$ removals, only a single number remains, and that number is the outcome of the game. The players have opposing goals.

codeforcescompetitive-programmingsortings
CF 985F - Isomorphic Strings

We are given a base string and many queries, each query picks two equal-length substrings and asks whether one substring can be transformed into the other by consistently renaming characters, with the restriction that different characters must map to different characters.

codeforcescompetitive-programminghashingstrings
CF 985E - Pencils and Boxes

We are given a sequence of pencil saturation values, and we need to split all pencils into groups called boxes. Every pencil must be placed in exactly one box. Each box that we use must contain at least k pencils.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedytwo-pointers