brain

tamnd's digital brain — notes, problems, research

43815 notes

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
CF 985B - Switches and Lamps

We are given a collection of switches, each of which controls a subset of lamps. When a switch is pressed, every lamp connected to it turns on permanently. Once a lamp is on, it never turns off again, even if other switches affecting it are pressed later.

codeforcescompetitive-programmingimplementation
CF 985A - Chess Placing

We are given a line of length $n$, where $n$ is even, and each position is either empty or contains exactly one chess piece. The board is colored in an alternating pattern starting with black at position 1, so positions look like B, W, B, W, and so on.

codeforcescompetitive-programmingimplementation
CF 986F - Oppa Funcan Style Remastered

We are asked whether it is possible to design a function on a very large set of positions, up to $10^{18}$, that behaves like a deterministic jump rule applied every second. Each position points to exactly one next position, and every element moves according to this fixed rule.

codeforcescompetitive-programminggraphsmathnumber-theoryshortest-paths
CF 986A - Fair

We are given a connected undirected graph of towns. Each town produces exactly one type of goods, and there are at most 100 distinct types overall. For any pair of towns, moving goods between them costs the shortest-path distance in the graph, where each road has unit length.

codeforcescompetitive-programminggraphsgreedynumber-theoryshortest-paths
CF 986B - Petr and Permutations

We are given a permutation of size $n$, and we are told it was produced by one of two random procedures. Both procedures start from the identity permutation $[1, 2, 3, dots, n]$, then repeatedly pick two distinct positions uniformly at random and swap them.

codeforcescompetitive-programmingcombinatoricsmath
CF 987B - High School: Become Human

We are given two positive integers $x$ and $y$, and we are asked to compare the values of two exponentials: $x^y$ and $y^x$.

codeforcescompetitive-programmingmath
CF 987C - Three displays

We are given a sequence of displays arranged along a line. Each display has a fixed position in this order, a font size, and a rental cost.

codeforcescompetitive-programmingbrute-forcedpimplementation
CF 988F - Rain and Umbrellas

We are given a line from position 0 to position $a$. Polycarp moves only to the right, one unit at a time. Some disjoint intervals on this line are rainy, and if he traverses an edge fully contained inside any rainy interval, he must carry at least one umbrella during that…

codeforcescompetitive-programmingdp
CF 988C - Equal Sums

We are given several independent integer arrays. From each array we are allowed to remove exactly one element, and this creates a “modified sum” for that array, meaning the original sum minus the removed element.

codeforcescompetitive-programmingimplementationsortings
CF 988B - Substrings Sort

We are given a collection of strings, and we are allowed to rearrange them in any order. After rearranging, we want a very specific nesting property: every string must contain all strings that appear before it as substrings.

codeforcescompetitive-programmingsortingsstrings
CF 989D - A Shade of Moonlight

We are given several “clouds” moving along a line. Each cloud is a segment of fixed length $l$, initially placed at position $xi$, and then moving over time with constant velocity $vi + w$, where $vi$ is either $+1$ or $-1$, and $w$ is a global wind parameter we are allowed…

codeforcescompetitive-programmingbinary-searchgeometrymathsortingstwo-pointers
CF 989C - A Mist of Florescence

We are asked to construct a rectangular grid and fill it with four letters, each representing a type of flower. The grid should be designed so that when we look at each letter separately, counting connected components using edge adjacency, the number of components for the four…

codeforcescompetitive-programmingconstructive-algorithmsgraphs
CF 989A - A Blend of Springtime

We are given a short string representing a row of cells. Each cell is either empty or contains exactly one flower of one of three types, encoded as the letters A, B, and C.

codeforcescompetitive-programmingimplementationstrings
CF 990C - Bracket Sequences Concatenation Problem

We are given a collection of strings, each consisting only of opening and closing parentheses. Think of each string as a small “building block” of a larger bracket expression.

codeforcescompetitive-programmingimplementation
CF 990E - Post Lamps

We are placing lamps along a one-dimensional street that runs from position 0 up to position n. Some positions are forbidden, meaning we are not allowed to place a lamp there, but otherwise we may choose any allowed position as a base.

codeforcescompetitive-programmingbrute-forcegreedy
CF 990A - Commentary Boxes

We are given an initial number of commentary boxes and a required number of delegations. Every delegation must receive exactly the same number of boxes, and all existing boxes must be used so that nothing remains idle.

codeforcescompetitive-programmingimplementationmath
CF 991D - Bishwock

We are given a board with two rows and $n$ columns, so each cell is either empty or blocked. A blocked cell cannot be used. Our task is to place as many fixed L-shaped pieces as possible on the board, where each piece occupies exactly three cells in one of four orientations.

codeforcescompetitive-programmingdpgreedy
CF 991F - Concise and clear

We are given a single integer $n$ up to $10^{10}$. The task is not to compute anything from it, but to rewrite it as a mathematical expression using only digits, plus, multiplication, and exponentiation.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmath
CF 991A - If at first you don't succeed...

We are given summary statistics about how students in a group behaved after an exam. Every student belongs to exactly one of four categories: they either visited only BugDonalds, only BeaverKing, both restaurants, or stayed at home because they failed the exam.

codeforcescompetitive-programmingimplementation
CF 991C - Candies

We are given an initial pile of candies and a fixed daily rule that transforms this pile over time. Each morning Vasya chooses a constant number k.

codeforcescompetitive-programmingbinary-searchimplementation
CF 992A - Nastya and an Array

We are given a list of integers, and we are allowed to repeatedly apply an operation that changes the array in a very specific way: in one move, we choose an integer value and add it to every element that is currently non-zero. Zeros stay untouched during that operation.

codeforcescompetitive-programmingimplementationsortings
CF 992B - Nastya Studies Informatics

We are given four integers $l, r, x, y$. The task is to count ordered pairs $(a, b)$ such that both numbers lie inside the interval $[l, r]$, and their greatest common divisor is exactly $x$ while their least common multiple is exactly $y$.

codeforcescompetitive-programmingmathnumber-theory
CF 993F - The Moral Dilemma

We are given a fixed logical circuit built in two layers above a set of binary input features. The first layer contains a small number of gates, each reading exactly two input variables and producing a boolean output using one of four operations: AND, OR, NAND, or NOR.

codeforcescompetitive-programming
CF 993E - Nikita and Order Statistics

We are given an array and a threshold value x. For every possible integer k from 0 to n, we need to count how many subarrays have exactly k elements strictly smaller than x.

codeforcescompetitive-programmingchinese-remainder-theoremfftmath
CF 993B - Open Communication

Two people each receive a secret pair of distinct digits from 1 to 9. The two hidden pairs are linked by a single property: they share exactly one common number. You are not given the hidden pairs directly.

codeforcescompetitive-programmingbitmasksbrute-force
CF 993D - Compute Power

We are given a collection of tasks. Each task has a “power” value and a “processor requirement”. A machine can run at most two tasks, but there is a strict ordering rule if it runs two: the first task assigned to a machine is allowed to be arbitrary, while the second…

codeforcescompetitive-programmingbinary-searchdpgreedy
CF 993C - Careful Maneuvering

We are given two sets of enemy ships, all lying on two vertical lines: one group is fixed at $x=-100$, the other at $x=100$. Each ship has an integer $y$-coordinate, and multiple ships may share the same $y$.

codeforcescompetitive-programmingbitmasksbrute-forcegeometry
CF 994B - Knights of a Polygonal Table

Each knight comes with two attributes, a fighting strength and a stash of coins. A knight is only able to defeat knights with strictly smaller strength, and every victory transfers the defeated knight’s coins to the winner.

codeforcescompetitive-programminggreedyimplementationsortings
CF 994A - Fingerprints

The input describes a fixed sequence of digits, like a recorded keypad history, and a separate set of digits that correspond to keys with fingerprints.

codeforcescompetitive-programmingimplementation
CF 995F - Cowmpany Cowmpensation

We are given a rooted tree of employees where employee 1 is the CEO. Every other employee has exactly one direct superior, forming a hierarchy.

codeforcescompetitive-programmingcombinatoricsdpmathtrees
CF 995A - Tesla

We are given a parking grid with 4 rows and $n le 50$ columns. Each cell either holds a car or is empty. Cars are uniquely labeled from $1$ to $k$, with $k le 2n$. The middle two rows contain the cars in their starting positions.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 995B - Suit and Tie

We are given a lineup of $2n$ people where each integer label from $1$ to $n$ appears exactly twice. Each label represents a couple, so the goal is to rearrange the line so that both occurrences of every number sit next to each other.

codeforcescompetitive-programminggreedyimplementationmath
CF 996A - Hit the Lottery

We are given a single integer representing the total amount of money Allen wants to withdraw. The bank only dispenses cash using fixed denominations: 1, 5, 10, 20, and 100.

codeforcescompetitive-programmingdpgreedy
CF 997E - Good Subsegments

We are given a permutation, meaning every value from 1 to n appears exactly once in an array. For any contiguous segment of this array, we call it good when it has a very strong structural property: if you take the smallest and largest values inside that segment, then every…

codeforcescompetitive-programmingdata-structures
CF 997C - Sky Full of Stars

We are working with an $n times n$ grid where each cell independently takes one of three colors. A coloring is considered “good” if at least one full row or at least one full column ends up monochromatic, meaning every cell in that row or column shares the same color.

codeforcescompetitive-programmingcombinatoricsmath