brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1143A - The Doors

The problem can be restated as follows. Mr. Black has a house with two sets of doors, each leading to a separate exit: left and right. Each door is initially closed, and we know the exact sequence in which Mr. Black opens them.

codeforcescompetitive-programmingimplementation
CF 1144D - Equalize Them All

We are given a sequence of integers arranged in a line. In one move, we pick two neighboring positions and use the difference between their values to either increase or decrease one of them by exactly that difference.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1144G - Two Merged Sequences

We are given a single sequence, and we are told that it was originally formed by taking two hidden sequences and interleaving them.

codeforcescompetitive-programmingdpgreedy
CF 1144F - Graph Without Long Directed Paths

We are given a connected undirected graph with n vertices and m edges. Our task is to assign a direction to every edge so that the resulting directed graph does not contain any path of length two or more.

codeforcescompetitive-programmingdfs-and-similargraphs
CF 1144E - Median String

We are asked to find the median string between two given strings of the same length, s and t, using lexicographical ordering. Both strings consist only of lowercase Latin letters, and s is guaranteed to be strictly smaller than t.

codeforcescompetitive-programmingbitmasksmathnumber-theorystrings
CF 1144C - Two Shuffled Sequences

We are given a multiset of integers that was created by taking two sequences, one strictly increasing and one strictly decreasing, merging all their elements together, and then shuffling the result. The original order inside the merged array is lost.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 1144B - Parity Alternated Deletions

We are given a sequence of integers, and we are allowed to remove elements one by one under a parity constraint that depends on the previous deletion. The first removed element can be anything.

codeforcescompetitive-programminggreedyimplementationsortings
CF 1144A - Diverse Strings

We are given several short strings, and for each one we need to decide whether it forms a single continuous block of the alphabet without any gaps or repetition. Think of the lowercase alphabet as a line from ‘a’ to ‘z’.

codeforcescompetitive-programmingimplementationstrings
CF 1145F - Neat Words

We are given a single string of uppercase letters with length between 1 and 10. The task is to determine whether this string is "neat." A neat word, in this context, is defined as one where no letter appears more than once at even positions or more than once at odd positions.

codeforcescompetitive-programming*special
CF 1145G - AI Takeover

This is an interactive game against a fixed but unknown opponent program. The opponent chooses one deterministic strategy at the beginning of the test and sticks to it for all 20 rounds.

codeforcescompetitive-programming*specialinteractive
CF 1145D - Pigeon d'Or

We are given a small array of integers, each between 1 and 32, and we are asked to find a certain integer that represents the maximum number of consecutive elements that satisfy a bitwise property.

codeforcescompetitive-programming*specialimplementation
CF 1145E - Fourier Doodles

We are given a small supervised learning task disguised as a programming problem. There are 50 grayscale images indexed from 1 to 50. For the first 20 images, we are given binary labels indicating whether each image is considered a “Fourier doodle” or not.

codeforcescompetitive-programming
CF 1145C - Mystery Circuit

We are given a single integer a between 0 and 15. This integer represents a configuration of a simple 4-bit circuit, where each bit can be either 0 or 1. The task is to compute an output integer based on a mysterious internal rule of the circuit.

codeforcescompetitive-programmingbitmasksbrute-force
CF 1145B - Kanban Numbers

We are asked to determine whether a given number can be represented as the sum of any number of integers equal to 4 or 7. The input is a single integer $a$ between 1 and 99, and the output is either "YES" if such a representation exists, or "NO" otherwise.

codeforcescompetitive-programming*specialbrute-force
CF 1145A - Thanos Sort

We start with an array whose length is a power of two. The allowed operation is very unusual: whenever the current array is not sorted in non-decreasing order, we may delete either its left half or its right half. After that, we repeat the same process on the remaining half.

codeforcescompetitive-programming*specialimplementation
CF 1146H - Satanic Panic

We are given a set of $n$ points on a 2D plane, with the guarantee that no three points are collinear. From these points, we want to count the number of 5-point subsets that can form a pentagram-a star-shaped configuration where the points are connected in a specific…

codeforcescompetitive-programmingdpgeometry
CF 1146F - Leaf Partition

We are given a rooted tree with n nodes, where node 1 is the root. Each node other than the root has a parent specified. A leaf is any node without children.

codeforcescompetitive-programmingdptrees
CF 1146G - Zoning Restrictions

We are asked to assign heights to houses along a street in order to maximize total profit. The street has n available positions, each of which can host a house with an integer height between 0 and h. The profit from a house of height a is a^2. There are m city restrictions.

codeforcescompetitive-programmingdpflowsgraphs
CF 1146D - Frog Jumping

A frog starts at position 0 on a number line. From any position, it can move forward by adding a or move backward by subtracting b. However, during the process of exploring what is reachable, we only allow it to stay within the segment [0, x] when computing f(x).

codeforcescompetitive-programmingdfs-and-similarmathnumber-theory
CF 1146E - Hot is Cold

We are given an array of integers and a series of queries. Each query instructs us to flip the sign of numbers in the array that satisfy a comparison: either all numbers greater than a threshold or all numbers less than a threshold.

codeforcescompetitive-programmingbitmasksdata-structuresdivide-and-conquerimplementation
CF 1146C - Tree Diameter

We are asked to determine the diameter of an unknown weighted tree. The tree has n nodes connected by n-1 edges, each with a positive integer weight at most 100. We do not have direct access to the edges.

codeforcescompetitive-programmingbitmasksgraphsinteractive
CF 1147F - Zigzag Game

The game is played on a complete bipartite graph with two equal groups of vertices. Every vertex on the left side connects to every vertex on the right side, and each such edge has a unique weight.

codeforcescompetitive-programminggamesinteractive
CF 1147E - Rainbow Coins

We are given a hidden assignment of colors to numbered coins, where each coin is exactly one of three colors. The goal is to partition the coins into three groups so that each group contains coins of a single color, but we do not know the colors directly.

codeforcescompetitive-programminginteractive
CF 1147D - Palindrome XOR

We are given a binary string pattern s consisting of '1', '0', and '?', with the guarantee that the first character is '1'.

codeforcescompetitive-programmingdfs-and-similargraphs
CF 1147A - Hide and Seek

We are working on a line of $n$ cells where a token starts somewhere and may move over time. Bob asks a sequence of queries, each query naming a cell, and Alice must always answer “NO” to every query.

codeforcescompetitive-programminggraphs
CF 1147C - Thanos Nim

We are asked to analyze a two-player game played on an array of piles, each containing some number of stones. There are $n$ piles, and $n$ is guaranteed to be even.

codeforcescompetitive-programminggames
CF 1147B - Chladni Figure

The problem gives a rectangular grid of characters representing a pattern on a metal plate, where each cell contains either a . (empty) or a (filled). The task is to find the smallest rectangle that contains all the characters.

codeforcescompetitive-programmingbrute-forcestrings
CF 1148H - Holy Diver

We are asked to maintain an array that grows dynamically. On each operation, we append a new element to the array and immediately count the number of contiguous subarrays (segments) within a given range [l, r] whose mex equals a given number k.

codeforcescompetitive-programmingdata-structures
CF 1148G - Gold Experience

We are given an array of integers placed on vertices of a complete set of labels. Between any two vertices we implicitly define an undirected edge if the two associated values share a nontrivial common divisor, meaning their gcd is greater than one.

codeforcescompetitive-programmingconstructive-algorithmsgraphsmathnumber-theoryprobabilities
CF 1148C - Crazy Diamond

We are given a permutation of the numbers from 1 to $n$, where $n$ is guaranteed to be even. A permutation means each number appears exactly once in the array. The task is to sort this permutation in ascending order.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 1148F - Foo Fighters

We are given a collection of objects, each contributing a signed value and a binary mask. We must choose a positive integer s. Once s is fixed, each object is either kept as-is or flipped in sign depending on a parity condition computed from s and its mask.

codeforcescompetitive-programmingbitmasksconstructive-algorithms
CF 1148E - Earth Wind and Fire

We are given two multisets of integer positions on a number line. One multiset describes where stones start, the other describes where we want them to end.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathsortingstwo-pointers
CF 1148A - Another One Bites The Dust

We are given three pools of building blocks. There are a pieces of the letter string "a", b pieces of "b", and c pieces of "ab". We are allowed to select any subset of these blocks and concatenate them in any order we want.

codeforcescompetitive-programminggreedy
CF 1148D - Dirty Deeds Done Dirt Cheap

We are given a collection of $n$ disjoint pairs of integers. Every integer from $1$ to $2n$ appears exactly once across all pairs, so each number belongs to exactly one pair and there is no overlap.

codeforcescompetitive-programminggreedysortings
CF 1148B - Born This Way

We are given two sorted timelines of flights forming a mandatory two-leg journey. A passenger first chooses a flight from A to B, spending a fixed travel time, and then immediately connects to a flight from B to C, again with a fixed travel time.

codeforcescompetitive-programmingbinary-searchbrute-forcetwo-pointers
CF 1149D - Abandoning Roads

We are given a small island country with n settlements and m bidirectional roads connecting them. Each road has a travel time which is either a or b seconds. The roads are initially connected in such a way that every settlement is reachable from every other settlement.

codeforcescompetitive-programmingbrute-forcedpgraphsgreedy
CF 1149E - Election Promises

Working

codeforcescompetitive-programminggamesgraphs
CF 1149C - Tree Generator™

We are given a string of parentheses that encodes a rooted tree via an Euler tour traversal. Every opening bracket corresponds to walking down an edge in the rooted tree, and every closing bracket corresponds to walking back up that same edge.

codeforcescompetitive-programmingdata-structuresimplementationtrees
CF 1149B - Three Religions

We are given a fixed base string, which we can think of as a long “universe sequence” of characters. Alongside it, there are three evolving strings, one per group.

codeforcescompetitive-programmingdpimplementationstrings
CF 1149A - Prefix Sum Primes

We are given a bag of tiles, each labeled with either a 1 or a 2. Our task is to arrange all the tiles into a sequence so that when we calculate the prefix sums - that is, the sum of the first element, the sum of the first two elements, and so on - the number of sums that are…

codeforcescompetitive-programmingconstructive-algorithmsgreedymathnumber-theory
CF 1150B - Tiling Challenge

We are given an $n times n$ square board, where some cells are occupied and others are free. The goal is to completely tile the free cells using identical pentomino pieces shaped like a cross: a center square with four adjacent squares, one in each cardinal direction.

codeforcescompetitive-programminggreedyimplementation
CF 1150A - Stock Arbitraging

We are given a very simple two-phase trading scenario. In the morning, there are several sellers offering unlimited quantities of the same stock at different buy prices. You can pick any one of these prices and buy as many shares as you want at that price.

codeforcescompetitive-programminggreedyimplementation
CF 1151D - Stas and the Queue at the Buffet

We have a queue of students, each with two personal characteristics: $ai$, which measures how much they dislike people in front of them, and $bi$, which measures how much they dislike people behind them.

codeforcescompetitive-programminggreedymathsortings
CF 1151E - Number of Components

We are given a tree of n vertices arranged in a simple line, where each vertex has a value ai. Conceptually, this is just an array of numbers connected consecutively by edges.

codeforcescompetitive-programmingcombinatoricsdata-structuresdpmath
CF 1151F - Sonya and Informatics

We are asked to determine the probability that an array consisting of zeros and ones becomes sorted in non-decreasing order after performing a fixed number of random swaps. Each swap selects two distinct positions in the array uniformly at random and exchanges their values.

codeforcescompetitive-programmingcombinatoricsdpmatricesprobabilities
CF 1151C - Problem for Nazar

The process generates a single infinite sequence by repeatedly appending blocks of numbers, where each block alternates between odd and even numbers and doubles in size each time.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1151B - Dima and a Bad XOR

We are given a grid of integers where each row represents a set of choices, and from every row we must pick exactly one number. After picking one number per row, we compute the bitwise XOR of all chosen numbers.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsdp
CF 1151A - Maxim and Biology

We are given a string of uppercase Latin letters of length at least 4, and we want to transform some of its letters so that the substring "ACTG" appears somewhere.

codeforcescompetitive-programmingbrute-forcestrings
CF 1152F2 - Neko Rules the Catniverse (Large Version)

We are asked to count sequences of planet visits with strong structural constraints. A path starts at any planet from 1 to n, and then performs exactly k − 1 moves.

codeforcescompetitive-programmingbitmasksdpmatrices
CF 1152F1 - Neko Rules the Catniverse (Small Version)

We are asked to count ordered sequences of distinct planets visited by a character who starts on any planet and then makes exactly $k-1$ moves.

codeforcescompetitive-programmingbitmasksdpmatrices
CF 1152C - Neko does Maths

We are given two starting integers. From both numbers, we are allowed to shift them upward by the same non-negative amount $k$, producing the pair $a+k$ and $b+k$. For each such shift, we can compute the least common multiple of the two resulting numbers.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1152D - Neko and Aki's Prank

The problem describes a full trie built from all correct bracket sequences of length $2n$. Every node in this trie corresponds to a prefix of some valid sequence, and edges correspond to appending either an opening or closing bracket while maintaining validity.

codeforcescompetitive-programmingdpgreedytrees
CF 1152E - Neko and Flashback

The task is to reconstruct an array of positive integers, a, given two arrays b' and c'. These arrays were generated from a through two stages: first, by taking all consecutive pairs in a to form b and c, where each bi is the minimum and each ci is the maximum of the pair (ai…

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphs
CF 1152B - Neko Performs Cat Furrier Transform

We are given a positive integer x representing the "number" of a cat. Our goal is to transform x into a number of the form 2^m - 1 for some non-negative integer m. These numbers in binary consist entirely of 1s, such as 0 (empty longcat), 1, 3, 7, 15, and so on.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdfs-and-similarmath
CF 1152A - Neko Finds Grapes

We are given a collection of treasure chests and a collection of keys. Each chest has a number written on it and each key also has a number written on it. A key can open a chest only when the sum of their numbers is odd.

codeforcescompetitive-programminggreedyimplementationmath
CF 1153F - Serval and Bonus Problem

We are asked to consider a line segment of length $l$. We randomly choose $n$ subsegments on this line. Each subsegment is determined by picking two points uniformly at random on the segment, so their endpoints may be non-integer.

codeforcescompetitive-programmingcombinatoricsdpmathprobabilities
CF 1153E - Serval and Snake

We are given a hidden simple path drawn on an $n times n$ grid. The path represents a snake: it visits distinct cells, each consecutive pair shares a side, and the two ends of the path are special cells called the head and the tail. We cannot see the path directly.

codeforcescompetitive-programmingbinary-searchbrute-forceinteractive
CF 1153D - Serval and Rooted Tree

We are given a rooted tree where every node either behaves like a minimum aggregator or a maximum aggregator. The leaves do not compute anything; they simply hold values.

codeforcescompetitive-programmingbinary-searchdfs-and-similardpgreedytrees
CF 1153B - Serval and Toy Bricks

We are given a 3-dimensional arrangement of unit bricks arranged in an $n times m$ grid. The height of bricks at position $(i,j)$ is unknown, but we are provided with three partial views: the front, the left, and the top.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1153C - Serval and Parenthesis Sequence

We are given a string consisting of three types of characters: open parenthesis "(", close parenthesis ")", and question marks "?". Our goal is to replace each "?

codeforcescompetitive-programminggreedystrings
CF 1153A - Serval and Bus

Serval is going to the bus station at a specific time t. There are n bus routes, each with a first bus arriving at si minutes and subsequent buses every di minutes. Serval will take the first bus that comes after or exactly at time t.

codeforcescompetitive-programmingbrute-forcemath
CF 1154E - Two Teams

We are given a row of n students, each with a distinct programming skill ranging from 1 to n. Two coaches take turns picking students to form their teams. On a coach's turn, they select the student with the highest skill remaining in the row.

codeforcescompetitive-programmingdata-structuresimplementationsortings
CF 1154G - Minimum Possible LCM

We are given an array of integers and asked to find a pair of indices (i, j) such that the least common multiple (LCM) of the two numbers at these indices is as small as possible. The array can contain up to one million elements, and each number can be as large as ten million.

codeforcescompetitive-programmingbrute-forcegreedymathnumber-theory
CF 1154F - Shovels Shop

We have a shop with n shovels, each with a specific price. Misha wants to buy exactly k shovels, possibly in multiple purchases. The twist is that the shop offers special deals: if you buy exactly xj shovels in a single purchase, the yj cheapest among those shovels are free.

codeforcescompetitive-programmingdpgreedysortings
CF 1154D - Walking Robot

We control a robot that starts at position 0 on a one-dimensional axis and must try to walk up to position n. The robot has two power sources: a battery with capacity b and an accumulator (charged by a solar panel) with capacity a.

codeforcescompetitive-programminggreedy
CF 1154A - Restoring Three Numbers

We are given four numbers that represent three pairwise sums of unknown positive integers $a$, $b$, $c$ and the sum of all three numbers. These four numbers are in no particular order. Our task is to reconstruct the original three integers $a$, $b$, $c$ from these sums.

codeforcescompetitive-programmingmath
CF 1154C - Gourmet Cat

Polycarp has a cat with a strict weekly eating schedule. The cat consumes fish food on Mondays, Thursdays, and Sundays; rabbit stew on Tuesdays and Saturdays; and chicken stakes on Wednesdays and Fridays.

codeforcescompetitive-programmingimplementationmath
CF 1154B - Make Them Equal

We are given an array of integers. We must choose a single non-negative value D and then, independently for each element, either add D, subtract D, or leave it unchanged. The goal is to make every element become the same value after these operations.

codeforcescompetitive-programmingmath
CF 1155F - Delivery Oligopoly

We are given a simple undirected graph that is already 2-edge-connected. By Menger's theorem, this means every pair of vertices has two edge-disjoint paths between them, which is exactly the condition required by the two delivery companies.

codeforcescompetitive-programmingbrute-forcedpgraphs
CF 1155A - Reverse a Substring

We are given a single string made of lowercase English letters. We are allowed to choose one contiguous segment inside this string and reverse that segment exactly once. After performing this single reversal, we obtain a new string.

codeforcescompetitive-programmingimplementationsortingsstrings
CF 1155E - Guess the Root

The problem gives us a hidden polynomial of degree at most 10 with integer coefficients, each strictly less than $10^6 + 3$. The task is to find an integer $x0$ such that the polynomial evaluates to zero modulo $10^6 + 3$.

codeforcescompetitive-programmingbrute-forceinteractivemath
CF 1155D - Beautiful Array

We are given a sequence of integers and allowed to optionally pick exactly one contiguous segment and multiply every element inside it by a fixed value x.

codeforcescompetitive-programmingbrute-forcedata-structuresdivide-and-conquerdpgreedy
CF 1155C - Alarm Clocks Everywhere

We are given several event times, already sorted in increasing order. Ivan wants to configure an alarm clock that rings periodically. Once the first ring happens at minute y, the clock continues ringing at times: y, y + p, y + 2p, y + 3p, ...

codeforcescompetitive-programmingmathnumber-theory
CF 1155B - Game with Telephone Numbers

We are given a digit string of odd length, and two players alternately delete single characters from it. The process continues until only 11 characters remain.

codeforcescompetitive-programminggamesgreedyimplementation
CF 1156G - Optimizer

We are given a program written in a strange language where each variable has a short name of up to four alphanumeric characters, with the first character not being a digit.

codeforcescompetitive-programminggraphsgreedyhashingimplementation
CF 1156F - Card Bag

We are repeatedly drawing cards from a multiset of values, without replacement. The only thing that matters is the sequence of drawn values, and how each value compares to the previous drawn value. The game behaves like this: the first drawn card just sets a baseline value.

codeforcescompetitive-programmingdpmathprobabilities
CF 1156E - Special Segments of Permutation

We are given a permutation of the numbers from 1 to n. For every subarray [l, r], we look at its maximum value. The subarray is called special when the sum of the two endpoint values equals that maximum: $$pl + pr = max(pl,dots,pr)$$ The task is to count how many subarrays…

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdsutwo-pointers
CF 1156D - 0-1-Tree

We are given a tree with n vertices, where each edge is labeled either 0 or 1. We need to count all ordered pairs of distinct vertices (x, y) such that, when walking along the unique path from x to y, we never traverse a 0-edge after we have already traversed a 1-edge.

codeforcescompetitive-programmingdfs-and-similardivide-and-conquerdpdsutrees
CF 1156B - Ugly Pairs

We are given a short string of lowercase letters and we are allowed to reorder its characters arbitrarily. The goal is to produce an arrangement where no two adjacent characters differ by exactly one position in the alphabet.

codeforcescompetitive-programmingdfs-and-similargreedyimplementationsortingsstrings
CF 1156A - Inscribed Figures

We are given a sequence of geometric figures. Each number represents one of three shapes: - 1 = circle - 2 = isosceles triangle whose height equals its base length - 3 = square Every figure is inscribed into the previous one and is chosen with the largest possible size.

codeforcescompetitive-programminggeometry
CF 1156C - Match Points

We are given a collection of points placed on a number line, and the goal is to form as many disjoint pairs as possible.

codeforcescompetitive-programmingbinary-searchgreedysortingsternary-searchtwo-pointers
CF 1157G - Inverse of Rows and Columns

We are given an $n times m$ matrix containing only zeros and ones. We may flip any row and any column any number of times. Flipping means replacing every value in that row or column by its opposite. After all chosen flips are applied, the matrix is read in row-major order.

codeforcescompetitive-programmingbrute-forceconstructive-algorithms
CF 1157F - Maximum Balanced Circle

We are given a multiset of integers representing heights of people standing in a line. From these people, we must choose a subset and then reorder the chosen elements into a circular arrangement.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedytwo-pointers
CF 1157C2 - Increasing Subsequence (hard version)

We are given a sequence of integers and must construct the longest possible strictly increasing sequence by repeatedly taking either the leftmost or the rightmost element. Each time we take a number, it is appended to our growing sequence and removed from the original sequence.

codeforcescompetitive-programminggreedy
CF 1157D - N Problems During K Days

We need to distribute exactly n solved problems across k consecutive days. Let a[i] be the number of problems solved on day i. Every day must contain at least one problem.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1157E - Minimum Array

We are given two arrays a and b, each of length n, containing integers from 0 to n-1. We can reorder b arbitrarily. After choosing an order for b, we construct a new array c where each element is (ai + bi) % n.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedy
CF 1157A - Reachable Numbers

We are asked to explore numbers generated by repeatedly applying a particular transformation function. For a number $x$, we first add one to it. If the resulting number has trailing zeros, we remove them all until none remain. This defines the function $f(x)$.

codeforcescompetitive-programmingimplementation
CF 1157B - Long Number

We are given a number as a string of digits from 1 to 9 and a mapping f from each digit to another digit in the same range. The task is to maximize the resulting number by selecting at most one contiguous segment of digits and replacing each digit x in that segment with f(x).

codeforcescompetitive-programminggreedy
CF 1157C1 - Increasing Subsequence (easy version)

We are given a permutation of size $n$. Think of it as a row of cards where every value from 1 to $n$ appears exactly once. At each move, we are only allowed to remove a card from either the far left or far right end of the current row, and we record the removed value.

codeforcescompetitive-programminggreedy
CF 1158F - Density of subarrays

We are given an array of positive integers, each bounded by a number $c$. The task is to examine all subsequences of this array and classify them by a number called their density.

codeforcescompetitive-programmingdpmath
CF 1158E - Strange device

We are asked to reconstruct an unknown tree with $n$ vertices by interacting with a device that allows a single type of query. Each vertex of the tree has a lamp, and the device lets us propose a set of distances $d1, d2, dots, dn$.

codeforcescompetitive-programmingbinary-searchinteractivemathtrees
CF 1158C - Permutation recovery

We are asked to reconstruct a permutation of numbers from 1 to n given a partially known array called next. Each element next[i] represents the smallest index j greater than i such that p[j] p[i]. If no such j exists, next[i] is set to n+1. If next[i] is unreadable, it is -1.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdfs-and-similargraphsgreedymathsortings
CF 1158D - Winding polygonal line

We are given a set of $n$ distinct points on the plane, with the guarantee that no three points are collinear. We need to order these points into a polygonal line such that two conditions hold: it never intersects itself, and at each internal vertex, the turn direction matches…

codeforcescompetitive-programmingconstructive-algorithmsgeometrygreedymath
CF 1158A - The Party and Sweets

We have a party with $n$ boys and $m$ girls. Each boy gives some number of sweets to every girl, forming an $n times m$ matrix of integers. For each boy, the minimum number of sweets he gives to any girl is specified as $bi$.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedyimplementationmathsortingstwo-pointers
CF 1158B - The minimal unique substring

We are asked to construct a binary string of length n such that the shortest substring appearing exactly once has length k. A substring is a consecutive segment of the string, and it is unique if it occurs in exactly one position.

codeforcescompetitive-programmingconstructive-algorithmsmathstrings
CF 1159B - Expansion coefficient of the array

We are given an array of non-negative integers. We define a property called a $k$-extension: an array is a $k$-extension if for every pair of elements $ai$ and $aj$, the inequality $k cdot The input consists of the length $n$ of the array, up to 300,000, and the array elements…

codeforcescompetitive-programmingimplementationmath
CF 1162A - Zoning Restrictions Again

We have a street with n building positions. Every position can contain a house whose height is an integer between 0 and h. The profit from a house of height a is a², so taller houses are always better. The city imposes m zoning rules.

codeforcescompetitive-programmingimplementation
CF 1163D - Mysterious Code

We are given a string c which represents a partially unreadable code. Some positions in c are readable lowercase letters, and others are asterisks representing unknown characters.

codeforcescompetitive-programmingdpstrings
CF 1163C2 - Power Transmission (Hard Edition)

We are given a set of points on a plane, each representing a power pole. Every pair of poles defines a straight infinite line, and that line is considered a “wire”.

codeforcescompetitive-programmingdata-structuresgeometryimplementationmath
CF 1163B2 - Cat Party (Hard Edition)

We are given a sequence of colors arriving over time, one per day. Each day contributes one occurrence of a color.

codeforcescompetitive-programmingdata-structuresimplementation