brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1662A - Organizing SWERC

Gianni needs to assemble a problem set for SWERC from a pool of problems submitted by judges. Each problem has a beauty score and a difficulty rating from 1 to 10.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1663F - In Every Generation...

There are actually two separate problems. The immediate runtime error is not caused by the algorithm at all. The test harness calls: and inside run it calls: but the code snippet shown in the editorial did not include solve inside the test block.

codeforcescompetitive-programming*specialstrings
CF 1663H - Cross-Language Program

The task is purely about feasibility rather than computation. We are asked to construct a single source file that both C++ (GCC 10.3.1 with C++11 standard) and FreePascal (3.0.4) can compile successfully.

codeforcescompetitive-programming*specialconstructive-algorithms
CF 1663G - Six Characters

The task presents a string of exactly six letters. We are asked to produce another string of six letters that satisfies a hidden constructive property - in this problem, the exact constraints are designed so that a careful choice of repeated characters produces a valid answer.

codeforcescompetitive-programming*specialconstructive-algorithmsstrings
CF 1663D - Is it rated - 3

The problem gives us a string S of length three, consisting of the characters + and -, and a non-negative integer X. The string represents a sequence of operations on an integer: + means increment by 1, - means decrement by 1.

codeforcescompetitive-programming*specialcombinatoricsdpmath
CF 1663E - Are You Safe?

Before I start writing the editorial, I need to clarify something: the problem statement you gave is entirely narrative and does not include any actual rules for “Are You Safe?

codeforcescompetitive-programming*specialimplementation
CF 1663C - Pōja Verdon

I can't write a correct editorial for this problem from the information provided. The current statement for Codeforces 1663C - Pōja Verdon has been intentionally stripped down to: Given an array, output a single number. That version omits the actual task.

codeforcescompetitive-programming*specialimplementationmath
CF 1663B - Mike's Sequence

We are given a single integer $r$, which may be negative, zero, or positive up to 2999. The task is to compute another integer that depends on this value through a hidden construction that is not explicitly described in the statement, but is implicitly defined by the sample…

codeforcescompetitive-programming*specialdivide-and-conquerimplementationmath
CF 1663A - Who Tested?

We are given a set of participants involved in a testing process, where each participant is associated with exactly one “tested by” relationship.

codeforcescompetitive-programming*specialexpression-parsingtrees
CF 1665C - Tree Infection

We are asked to find the minimum time needed to infect all nodes of a rooted tree where infections spread in two ways each second. First, a spreading step allows any node with at least one infected child to infect at most one additional child.

codeforcescompetitive-programmingbinary-searchgreedysortingstrees
CF 1665D - GCD Guess

We are asked to find a hidden positive integer $x$ between 1 and $10^9$. Instead of observing $x$ directly, we can query the greatest common divisor of two numbers shifted by $x$. Specifically, for any two positive integers $a$ and $b$, the interactor returns $gcd(x + a, x + b)$.

codeforcescompetitive-programmingbitmaskschinese-remainder-theoremconstructive-algorithmsgamesinteractivemathnumber-theory
CF 1665E - MinimizOR

We are asked to process multiple subarray queries on an array of non-negative integers. For each subarray defined by indices $l$ and $r$, the task is to find the minimum value of the bitwise OR taken over all pairs of distinct elements in that subarray.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresdivide-and-conquergreedyimplementationtwo-pointers
CF 1665A - GCD vs LCM

The problem asks us to split a given positive integer $n$ into four positive integers $a, b, c, d$ such that the sum $a + b + c + d = n$ holds, and at the same time the greatest common divisor of $a$ and $b$ equals the least common multiple of $c$ and $d$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1665B - Array Cloning Technique

We are given an array of integers, and we can perform two types of operations: cloning an entire array copy, or swapping elements between any two copies. Our goal is to produce at least one array where all elements are identical, using the minimal number of operations.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 1666C - Connect the Points

We are given three distinct points on the 2D plane, and we are asked to connect them with segments that are either horizontal or vertical. The segments can only lie along the coordinate axes, meaning each segment has constant x or constant y.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgeometry
CF 1666L - Labyrinth

We are given a directed graph representing a labyrinth of halls and one-way passages. A traveler starts from a fixed starting hall $s$. We are allowed to choose any other hall $t$ as a meeting point.

codeforcescompetitive-programmingdfs-and-similargraphs
CF 1666K - Kingdom Partition

We are asked to partition a kingdom's towns into three districts, A, B, and C, corresponding to Adrian, Beatrice, and Cecilia. Adrian's castle must be in district A, Beatrice's castle in district B, and Cecilia has no castle.

codeforcescompetitive-programmingflows
CF 1666J - Job Lookup

We are asked to organize a team of n members into a binary search tree (BST) hierarchy that minimizes communication cost. Each team member has a unique number from 1 to n representing their position in a front-end to back-end spectrum.

codeforcescompetitive-programmingconstructive-algorithmsdpshortest-pathstrees
CF 1666I - Interactive Treasure Hunt

We are given a grid of size $n times m$ where two treasures are hidden in distinct cells. The goal is to locate both treasures using a combination of two operations: DIG r c and SCAN r c.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgeometryinteractivemath
CF 1666H - Heroes of Might

We are given a sequence of integer strengths representing heroes. Each hero can defeat monsters of strength equal to their own or weaker.

codeforcescompetitive-programmingmath
CF 1666G - Global Warming

In this problem, we are given a set of points on a two-dimensional plane, each representing a temperature measurement at a specific location.

codeforcescompetitive-programminggeometrymath
CF 1666F - Fancy Stack

The problem gives us a sequence of integers representing operations on a stack. Each integer can be seen as either pushing a new element onto the stack or performing a "fancy" operation that removes some elements from the top in a way governed by the problem's rules.

codeforcescompetitive-programmingcombinatoricsdpimplementation
CF 1666E - Even Split

We are given a one-dimensional segment representing the entire country, stretching from position 0 to position l. Inside this segment there are n citizens, each located at a distinct integer coordinate ai, sorted in increasing order.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedymath
CF 1666D - Deletive Editing

We are given two strings for each test case, an initial word and a target word. We repeatedly perform an operation where we are allowed to choose a character and delete its leftmost occurrence from the current word.

codeforcescompetitive-programminggreedy
CF 1666B - Budget Distribution

We are asked to distribute extra budget money over several topics, each consisting of a small number of items. For each topic, the optimal relative fractions of money for its items are given, and some money is already assigned to items and cannot be removed.

codeforcescompetitive-programming
CF 1666A - Admissible Map

We are given a string over four symbols, each symbol encoding a move in a grid: up, left, down, or right. Any substring of this string can be interpreted as a flattened matrix if we choose a height and width whose product equals the substring length, reading the substring row…

codeforcescompetitive-programming
CF 1667C - Half Queen Cover

The task is to place the minimum number of half-queens on an $n times n$ chessboard such that every square is either occupied or attacked. A half-queen attacks all cells in its row, its column, and the diagonal going from top-left to bottom-right that passes through its position.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1667F - Yin Yang

We are given a grid where some cells are already fixed as black or white, and the rest are empty. The goal is to assign a color to every empty cell so that, after filling, all black cells form a single connected region using 4-directional movement, and all white cells also…

codeforcescompetitive-programmingimplementation
CF 1667E - Centroid Probabilities

We are asked to count, for each vertex in a special class of labeled trees, how many trees have that vertex as a centroid. The trees have $n$ vertices labeled $1$ through $n$, with the restriction that each vertex $i ge 2$ is connected to exactly one vertex with a smaller index.

codeforcescompetitive-programmingcombinatoricsdpfftmath
CF 1667D - Edge Elimination

We are given a tree, which is a connected graph with no cycles, and we are asked to remove all its edges following a very particular rule: an edge can be removed only if it is adjacent to an even number of remaining edges. Two edges are adjacent if they share exactly one vertex.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardptrees
CF 1667A - Make it Increasing

We are asked to construct an array $b$ from an array $a$ such that each element of $b$ is obtained from zero by either adding or subtracting a multiple of the corresponding element in $a$.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1667B - Optimal Partition

We are asked to partition an array of integers into contiguous subarrays in order to maximize a custom score. Each subarray contributes to the total sum based on its sum: if the sum is positive, its contribution is the length of the subarray; if zero, it contributes nothing…

codeforcescompetitive-programmingdata-structuresdp
CF 1668B - Social Distance

We are given a circular arrangement of $m$ seats and a list of $n$ people. Each person has a personal “exclusion radius” $ai$: if they sit on some seat, then the closest $ai$ seats on both sides around the circle must remain empty.

codeforcescompetitive-programminggreedymathsortings
CF 1668A - Direction Change

We are walking on a very large rectangular grid starting from the top-left cell and trying to reach the bottom-right cell.

codeforcescompetitive-programmingimplementationmath
CF 1669B - Triple

The problem asks us to find any number in an array that occurs at least three times. We are given multiple test cases, and for each test case, an array of integers is provided. The integers are guaranteed to be between 1 and the size of the array.

codeforcescompetitive-programmingimplementationsortings
CF 1669H - Maximal AND

We are given an array of integers, and we are allowed to “turn on” bits in individual elements. Each operation picks one element and sets one previously-zero bit to one. We may do this at most k times across the entire array.

codeforcescompetitive-programmingbitmasksgreedymath
CF 1669G - Fall Down

We are given a rectangular grid of size $n times m$ consisting of empty cells, stones, and obstacles. Stones are represented by '', empty cells by '.', and obstacles by 'o'.

codeforcescompetitive-programmingdfs-and-similarimplementation
CF 1669F - Eating Candies

We are given a sequence of candy weights laid out in a straight line. Two people, Alice and Bob, consume candies under a strict constraint: Alice can only take a prefix from the left end, while Bob can only take a suffix from the right end.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedytwo-pointers
CF 1669E - 2-Letter Strings

We are given a collection of short strings, each consisting of exactly two lowercase letters from a small alphabet.

codeforcescompetitive-programmingdata-structuresmathstrings
CF 1669D - Colorful Stamp

We are given a line of cells that starts completely empty, and we are allowed to apply a special operation that always acts on exactly two adjacent positions. Each application recolors those two cells into different colors, one red and one blue, in either order.

codeforcescompetitive-programmingimplementation
CF 1669C - Odd/Even Increments

We are given an array of integers where we are allowed to repeatedly apply two global operations. One operation increments every element at odd positions, and the other increments every element at even positions.

codeforcescompetitive-programminggreedyimplementationmath
CF 1669A - Division?

Each test case gives a single integer representing a Codeforces user rating, and the task is to classify that rating into one of four fixed intervals, each corresponding to a division number. The mapping is purely threshold-based.

codeforcescompetitive-programmingimplementation
CF 1670C - Where is the Pizza?

We are given two permutations of size $n$, which are arrays containing each integer from $1$ to $n$ exactly once. From these two permutations, a third array is constructed by choosing for each position either the value from the first permutation or from the second permutation.

codeforcescompetitive-programmingdata-structuresdfs-and-similardsugraphsimplementationmath
CF 1670E - Hemose on the Tree

We are given a tree with $n = 2^p$ vertices. We must assign distinct integers from $1$ to $2n-1$ to all vertices and edges, so in total we label exactly $2n-1$ objects. After fixing these labels, we also choose a root.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdfs-and-similartrees
CF 1670F - Jee, You See?

Working

codeforcescompetitive-programmingbitmaskscombinatoricsdp
CF 1670D - Very Suspicious

We are working with an infinite hexagonal grid, where each hexagon shares edges with six neighbors. The task is to add straight lines along the directions of the hexagon edges to form equilateral triangles.

codeforcescompetitive-programmingbinary-searchbrute-forcegeometrygreedyimplementationmath
CF 1670A - Prof. Slim

We are given an array of non-zero integers, and we are allowed to repeatedly swap the signs of any two elements that have opposite signs. The goal is to determine whether we can make the array non-decreasing with this operation.

codeforcescompetitive-programminggreedyimplementationsortings
CF 1670B - Dorms War

We are given a string that represents a password and a set of special characters. A transformation program can be applied repeatedly to the string.

codeforcescompetitive-programmingbrute-forceimplementationstrings
CF 1671F - Permutation Counting

We are counting permutations of size $n$ with two simultaneous structural constraints. The first constraint fixes the total number of inversions, meaning how many pairs $(i, j)$ with $i < j$ appear in reversed order in the permutation.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpfftmath
CF 1671D - Insert a Progression

We are given an array of integers a and a set of extra integers {1, 2, …, x}. The task is to insert all these extra integers into a in any order and at any positions, including at the beginning or end.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedy
CF 1671A - String Building

The input to the system is well-formed but the observed failure pattern is not a mathematical or logical inconsistency of the task; it is a structural defect: the program produces no output at all for multiple independent test cases, indicating that the core loop does not…

codeforcescompetitive-programmingimplementation
CF 1671E - Preorder

We are given a complete binary tree of size $2^n - 1$, where every internal node has exactly two children and all leaves lie on the same level. Each node carries a label, either A or B.

codeforcescompetitive-programmingcombinatoricsdivide-and-conquerdpdsuhashingsortingstrees
CF 1671B - Consecutive Points Segment

We are given a set of points on a number line, already sorted in increasing order. Each point is allowed to “wiggle” by at most one unit, meaning its final position can be its original coordinate, one step left, or one step right.

codeforcescompetitive-programmingbrute-forcemathsortings
CF 1671C - Dolce Vita

We have a scenario where you want to buy sugar packs from several shops over consecutive days, with each shop selling one pack per day. Each shop has an initial price for its pack, and every day the price increases by one.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedymath
CF 1672I - PermutationForces

Codeforces 1672I: PermutationForces

codeforcescompetitive-programmingdata-structuresgreedy
CF 1672H - Zigu Zagu

We are given a binary string and many queries on substrings. For each query interval, we repeatedly delete contiguous pieces of the current substring.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 1672G - Cross Xor

We are asked to construct a binary grid of size $r times c$ by applying a specific row-column flip operation multiple times starting from an all-zero grid. The operation allows us to pick any cell and flip all values in its row and column using XOR with 1.

codeforcescompetitive-programmingconstructive-algorithmsgraphsmathmatrices
CF 1672B - I love AAAB

We are asked to represent each integer in the range from $-10$ to $10$ using the numeral system with radix $-2$. In this system, every integer $N$ is written in the form $$N = sum{i=0}^{k} di (-2)^i,$$ where each digit $di in {0,1}$ and the representation is chosen so that the…

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1672F2 - Checker for Array Shuffling

We are given two arrays of the same length. The first array represents the “original” configuration, and the second array is a shuffled version of it, meaning it contains exactly the same multiset of values but possibly in a different order.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphs
CF 1672F1 - Array Shuffling

We are given an array that contains values in the range from 1 to n, possibly with repetitions. Think of this array as a multiset of labeled tokens.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedy
CF 1672E - notepad.exe

We are dealing with a hidden array of word lengths, and the only way to learn anything about it is by querying a hypothetical text editor.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedyinteractive
CF 1672D - Cyclic Rotation

We are given two arrays, a and b, of the same length n. The goal is to determine whether we can transform a into b using a specific operation.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationtwo-pointers
CF 1672A - Log Chopping

We are asked to determine the winner in a simple two-player game with logs of integer lengths. There are $n$ logs, and two players take turns splitting a single log into two positive integer pieces. The first player unable to make a move loses.

codeforcescompetitive-programminggamesimplementationmath
CF 1672C - Unequal Array

We are given an array of integers and asked to minimize consecutive repetitions. Formally, we define the equality of an array as the number of positions where two consecutive elements are equal.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1673C - Palindrome Basis

The runtime error ValueError: min() arg is empty comes from trying to compute min(arr) when arr is empty. The root cause is that the input parsing logic does not match the problem's actual input format.

codeforcescompetitive-programmingbrute-forcedpmathnumber-theory
CF 1673F - Anti-Theft Road Planning

We are asked to design a system of roads on an $n times n$ grid of buildings where each road has a positive integer length and the sum of all road lengths does not exceed 48,000.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdivide-and-conquergreedyinteractivemath
CF 1673E - Power or XOR?

We are given a sequence of integers $B1, B2, dots, Bn$. Each value $Bi$ represents a power of two, so we can think of the underlying numbers as $Ai = 2^{Bi}$.

codeforcescompetitive-programmingbitmaskscombinatoricsmathnumber-theory
CF 1673D - Lost Arithmetic Progression

We are given two arithmetic progressions, $B$ and $C$. The progression $C$ contains all numbers that are common to some unknown progression $A$ and $B$. Our goal is to count how many finite arithmetic progressions $A$ could exist that satisfy this property.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 1673B - A Perfectly Balanced String?

The problem defines a very strong constraint on a string: every substring must have almost equal counts of all characters that appear in the full string.

codeforcescompetitive-programmingbrute-forcegreedystrings
CF 1673A - Subtle Substring Subtraction

We are given several independent rounds. In each round, Alice and Bob repeatedly delete contiguous parts of a string until nothing remains. The deleted characters contribute to their personal scores, where each letter has a fixed value from 1 for a up to 26 for z.

codeforcescompetitive-programminggamesgreedystrings
CF 1674A - Number Transformation

Thank you for providing the detailed sample input and output. I carefully traced the prefix-suffix logic from the previous solution, and the bug is clear. The previous approach misaligns indices when determining which friends could be thieves. Specifically: 1.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1674G - Remove Directed Edges

We are given a directed acyclic graph where each vertex has some number of incoming and outgoing edges. We are allowed to delete edges, but only under a very specific local rule: a vertex can lose edges only if it actually had at least one edge of that type before, unless it…

codeforcescompetitive-programmingdfs-and-similardpgraphs
CF 1674F - Desktop Rearrangement

We are given a 2D grid representing a desktop with icons marked as '' and empty cells as '.'. The desktop is considered "good" if the icons occupy a compact rectangle starting from the top-left corner: all icons fill some number of complete columns, and possibly a prefix of…

codeforcescompetitive-programmingdata-structuresgreedyimplementation
CF 1674D - A-B-C Sort

We are given an array a of integers and need to simulate a two-step procedure to form a new array c. The first step repeatedly moves elements from the end of a into the middle of a second array b.

codeforcescompetitive-programmingconstructive-algorithmsimplementationsortings
CF 1674E - Breaking the Wall

We are given a row of wall segments, each with some durability. A segment is considered destroyed once its durability drops to zero or below.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsgreedymath
CF 1674B - Dictionary

We are given a tiny language where every valid word consists of exactly two different lowercase English letters. Because the alphabet is fixed and small, every possible word can be generated by picking an ordered pair of distinct letters, such as ab, ac, ba, and so on.

codeforcescompetitive-programmingcombinatoricsmath
CF 1674C - Infinite Replacement

The problem gives you two strings for each test case: a string s composed entirely of the letter 'a' and another string t composed of arbitrary lowercase letters. You are allowed to repeatedly replace any single 'a' in s with the string t.

codeforcescompetitive-programmingcombinatoricsimplementationstrings
CF 1675C - Detective Task

We observe a sequence of visitors entering a room one after another. Exactly one of them stole a painting at some moment, but we do not know when the theft happened.

codeforcescompetitive-programmingimplementation
CF 1675G - Sorting Pancakes

The array represents stacks of pancakes placed on a row of dishes. You are allowed to repeatedly pick a single pancake and move it one step to an adjacent dish, paying a cost of one per such move.

codeforcescompetitive-programmingdp
CF 1675F - Vlad and Unfinished Business

We are given a city structured as a tree with n houses connected by n-1 roads, which guarantees there is exactly one simple path between any two houses.

codeforcescompetitive-programmingdfs-and-similardpgreedytrees
CF 1675D - Vertical Paths

We are given a rooted tree, but the root is not explicitly provided. Instead, every node tells us its parent, and exactly one node is its own parent. That node is the root. From this structure, we must partition all nodes into several directed paths.

codeforcescompetitive-programminggraphsimplementationtrees
CF 1675E - Replace With the Previous, Minimize

We are given a string made of lowercase English letters, and we are allowed to repeatedly perform a global transformation on it.

codeforcescompetitive-programmingdsugreedystrings
CF 1675B - Make It Increasing

We are given several independent arrays. For each array, we are allowed to repeatedly shrink elements, where one operation picks a position and replaces its value with half of it rounded down. No swapping is allowed, so the order of elements is fixed.

codeforcescompetitive-programminggreedyimplementation
CF 1675A - Food for Animals

We are given a situation in a pet store where there are three types of food: dog food, cat food, and universal food that can feed either dogs or cats. Polycarp owns a certain number of dogs and cats. Our task is to decide if the store has enough food to satisfy all of his pets.

codeforcescompetitive-programminggreedymath
CF 1676H1 - Maximum Crossings (Easy Version)

We are given two parallel rows of segments, top and bottom, both of length $n$. Each segment on the top row has a wire connecting it to a specific segment on the bottom row, defined by an array $a$, where $ai$ is the bottom segment connected to top segment $i$.

codeforcescompetitive-programmingbrute-force
CF 1676H2 - Maximum Crossings (Hard Version)

We are given a collection of wires, one per index, where wire i starts at position i on the upper rail and ends at position a[i] on the lower rail.

codeforcescompetitive-programmingdata-structuresdivide-and-conquersortings
CF 1676B - Equal Candies

We are given a set of boxes, each containing some number of candies. There is exactly one box for each friend, and the goal is to make all boxes contain the same number of candies so that no friend feels left out. We can only eat candies from a box; we cannot add any.

codeforcescompetitive-programminggreedymathsortings
CF 1676G - White-Black Balanced Subtrees

We are given a rooted tree where vertex 1 is the root. Every vertex is colored either black or white. For any vertex, its subtree consists of the vertex itself and all nodes that have it on their path up to the root, meaning all descendants in the rooted structure.

codeforcescompetitive-programmingdfs-and-similardpgraphstrees
CF 1676F - Longest Strike

We are given an array of integers and a threshold number $k$. Our goal is to find a contiguous range of integers $[l, r]$ such that every integer in this range appears at least $k$ times in the array.

codeforcescompetitive-programmingdata-structuresgreedyimplementationsortingstwo-pointers
CF 1676D - X-Sum

We are given a two-dimensional grid representing a chessboard where each cell contains a non-negative integer. A bishop can be placed on any cell, and it attacks all cells along the four diagonals that intersect at its position. The cell the bishop occupies counts as attacked.

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 1676E - Eating Queries

We are given multiple independent scenarios, each describing a collection of candies where each candy has a fixed amount of sugar.

codeforcescompetitive-programmingbinary-searchgreedysortings
CF 1676C - Most Similar Words

We are given a collection of words where each word has the same length. Our task is to measure how “far apart” any two words are in terms of the minimum number of single-letter changes needed to make them identical.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmathstrings
CF 1676A - Lucky?

We are given a sequence of short strings, each representing a six-digit ticket number. Each ticket should be split into two halves of equal length. The task is to decide whether the sum of digits in the left half matches the sum of digits in the right half.

codeforcescompetitive-programmingimplementation
CF 1677B - Tokitsukaze and Meeting

We are asked to simulate a dynamic seating scenario. There is a hall with n rows and m columns, and students arrive one by one, each either serious or naughty.

codeforcescompetitive-programmingdata-structuresimplementationmath
CF 1677F - Tokitsukaze and Gems

We are given a line of positions, and each position contributes a stack of identical gems of a specific type. Position i holds ai gems of type i.

codeforcescompetitive-programmingdpmath
CF 1677D - Tokitsukaze and Permutations

We are given a permutation that undergoes a very specific transformation: one “operation” is a full left-to-right bubble pass where adjacent inversions are fixed once. After applying this operation exactly $k$ times, we obtain a permutation $a$.

codeforcescompetitive-programmingdpmath
CF 1677E - Tokitsukaze and Beautiful Subsegments

We are given a permutation of integers from 1 to $n$, and we are asked multiple queries about contiguous subsegments of this permutation. A subsegment is called beautiful if its maximum value can be expressed as the product of two elements inside that segment.

codeforcescompetitive-programmingdata-structures
CF 1677C - Tokitsukaze and Two Colorful Tapes

Each color appears exactly once on two parallel tapes, so every color can be seen as a pair of positions: one index on the first tape and one index on the second tape.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsgreedy
CF 1677A - Tokitsukaze and Strange Inequality

We are given a permutation of integers from 1 to n and asked to count how many quadruples of indices [a, b, c, d] satisfy two inequalities: the first element is smaller than the third (pa < pc) and the second element is larger than the fourth (pb pd).

codeforcescompetitive-programmingbrute-forcedata-structuresdp
CF 1678B2 - Tokitsukaze and Good 01-String (hard version)

We are given a binary string of even length and asked to transform it into a "good" string. A good string is defined by two rules.

codeforcescompetitive-programmingdpgreedyimplementation