brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1611E2 - Escape The Maze (hard version)

We are given a tree of rooms. Vlad starts from room 1 and tries to escape by reaching any leaf node that is not room 1. A leaf is a room with exactly one corridor. At the same time, several friends are placed on distinct nodes.

codeforcescompetitive-programmingdfs-and-similardpgreedyshortest-pathstrees
CF 1611C - Polycarp Recovers the Permutation

We are given a sequence a of length n that was generated by repeatedly removing the smallest element from either end of a hidden permutation p of the numbers from 1 to n. If the smallest element is at the left, it is prepended to a; if it is at the right, it is appended to a.

codeforcescompetitive-programmingconstructive-algorithms
CF 1611A - Make Even

We are given a number written in decimal form with no zero digits. The only operation allowed is to take a prefix of the number and reverse the order of digits inside that prefix. The prefix length can be anything from 1 up to the full length of the number.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1611B - Team Composition: Programmers and Mathematicians

We are given two groups of students: programmers and mathematicians. From these students, we want to form as many teams as possible, where every team contains exactly 4 students.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsmath
CF 1612F - Armor and Weapons

In this problem, Monocarp starts with the weakest armor and weapon, labeled 1. He can spend one hour to acquire a new armor set or weapon, but there is a catch: to obtain the $k$-th armor or weapon, he must already possess some armor and weapon combination whose total power is…

codeforcescompetitive-programmingbrute-forcedpgreedyshortest-paths
CF 1612G - Max Sum Array

We are given a multiset of labels, where label i appears exactly ci times. We must arrange all these occurrences into a single array. Once the array is fixed, we look at every pair of identical values and add the distance between their positions.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsgreedysortings
CF 1612E - Messages

We have a group of students, each of whom Monocarp wants to read a specific message in a chat. Every student has a limit on how many messages they will read in a day.

codeforcescompetitive-programmingbrute-forcedpgreedyprobabilitiessortings
CF 1612D - X-Magic Pair

We are given a pair of integers $a$ and $b$, and another integer $x$. We are allowed to repeatedly replace either $a$ or $b$ with the absolute difference $ The constraints allow $a, b, x$ to go up to $10^{18}$, and there can be up to $10^4$ test cases.

codeforcescompetitive-programmingmathnumber-theory
CF 1612A - Distance

We are working on a grid where movement is measured using Manhattan distance, meaning the cost between two points is the sum of horizontal and vertical separations. One point is fixed at the origin, while the second point lies at coordinates $(x, y)$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithms
CF 1612B - Special Permutation

We are asked to construct a permutation of numbers from 1 to n, where n is even. The permutation is split into two equal halves: the first n/2 elements form the left half, and the remaining n/2 elements form the right half. Two conditions must be satisfied simultaneously.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1612C - Chat Ban

We are asked to simulate a chat scenario where a user wants to send an "emote triangle" consisting of messages with increasing then decreasing numbers of emotes.

codeforcescompetitive-programmingbinary-searchmath
CF 1613F - Tree Coloring

We are given a rooted tree where vertex 1 is fixed as the root. The task is to assign a distinct label from 1 to n to every vertex, so the labels form a permutation of 1 to n.

codeforcescompetitive-programmingcombinatoricsdivide-and-conquerfft
CF 1613D - MEX Sequences

We are asked to count subsequences of an array where every prefix of the subsequence behaves in a very specific “MEX-stable” way.

codeforcescompetitive-programmingdpmath
CF 1613E - Crazy Robot

We are given a rectangular grid of size n × m containing three types of cells: free cells, blocked cells, and a single lab. The robot can occupy any free cell, and at each step we can issue one of four commands: move up, down, left, or right.

codeforcescompetitive-programmingdfs-and-similargraphs
CF 1613B - Absent Remainder

We are given a sequence of distinct positive integers. Our task is to construct roughly half as many pairs of numbers as the length of the sequence, where for each pair $(x, y)$, both numbers come from the sequence, they are distinct, and the remainder when $x$ is divided by…

codeforcescompetitive-programminggreedyimplementationsortings
CF 1613A - Long Comparison

Each number in this problem is not given in its expanded form, but as a compact description. Instead of writing the full integer, we are given a base value x and a number of trailing zeros p, meaning the actual number is x × 10^p.

codeforcescompetitive-programmingimplementationmath
CF 1613C - Poisoned Dagger

We are given a sequence of attack times and a dragon with h hit points. Each attack applies a poison that lasts k seconds and deals 1 damage per second. If the dragon is already poisoned when a new attack lands, the poison timer resets.

codeforcescompetitive-programmingbinary-search
CF 1614B - Divan and a New Project

- a = [3,1,4,9,2,5,6] - The edges form a path: 1→2→3→4→5→6→7 - res = a[:] = [3,1,4,9,2,5,6] - Process topologically: 1. Node 1 → Node 2: res[1] = min(1,3) = 1 OK 2.

codeforcescompetitive-programmingconstructive-algorithmssortings
Kvant Physics Problem 35

The physical system consists of a satellite in low Earth orbit photographing the surface of the Earth.

kvantphysics
CF 1614E - Divan and a Cottage

We are asked to simulate the evolution of the temperature inside Divan's cottage over a sequence of days, where the temperature adjusts by one unit per day towards the outside temperature.

codeforcescompetitive-programmingbinary-searchdata-structures
Kvant Physics Problem 34

A hollow insulated conducting sphere of radius $R$ is charged by water drops falling from a vertical tube.

kvantphysics
CF 1614D2 - Divan and Kostomuksha (hard version)

We are given a multiset of positive integers and allowed to permute them in any order. After choosing an order, we repeatedly take prefixes of this order and compute the gcd of each prefix, then sum all those gcd values.

codeforcescompetitive-programmingdpnumber-theory
CF 1614D1 - Divan and Kostomuksha (easy version)

We are given a list of positive integers, and we are allowed to reorder them arbitrarily. After fixing an order, we look at all prefixes of this order.

codeforcescompetitive-programmingdpnumber-theory
CF 1614C - Divan and bitwise operations

We are asked to reconstruct the sum of XORs over all non-empty subsequences of an array, knowing only the bitwise OR of several contiguous segments of that array. Each array element appears in at least one segment, so every element contributes to the OR values we are given.

codeforcescompetitive-programmingbitmaskscombinatoricsconstructive-algorithmsdpmath
CF 1614A - Divan and a Store

Divan wants to buy chocolate bars under three constraints: he only considers bars within a price range [l, r], and he cannot exceed his total budget k.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedy
CF 1615H - Reindeer Games

Your input: Structure: - t = 4 - Each test case: - one integer n - one line with n integers So format is consistent: Expected: Now observe carefully: [1, 7] → 1 [1, 5, 4] → -1 [12345678, 87654321, 20211218, 23571113] → 4 [1,2,3,4,18,19,5,6,7] → 2 So the output is: not…

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresdivide-and-conquerflowsgraphsshortest-paths
Kvant Physics Problem 31

Consider a sphere of radius $R$ illuminated by a parallel beam of sunlight.

kvantphysics
CF 1615G - Maximum Adjacent Pairs

We are given an array with some fixed integers and some positions marked as zero. Each zero must be replaced by any integer from 1 to n, and different zero positions can be filled independently, even with the same value.

codeforcescompetitive-programmingconstructive-algorithmsgraph-matchings
CF 1615D - X(or)-mas Tree

We are given a tree with n nodes and n-1 edges, where each edge can store a non-negative integer representing lights, or -1 if the value is unknown.

codeforcescompetitive-programmingbitmasksdfs-and-similardsugraphstrees
CF 1615F - LEGOndary Grandmaster

We are given a one-dimensional Lego strip of length n, where some positions may or may not contain a Lego block. Our memory of the starting and ending configurations is partial: for each position we either know it has a block (1), we know it is empty (0), or we don't remember (?

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1615E - Purple Crayon

We are given a rooted tree with $n$ nodes, rooted at node 1, where all nodes start white. Two players, Red and Blue, take turns coloring nodes. Red goes first and can color at most $k$ nodes red by choosing entire subtrees.

codeforcescompetitive-programmingdata-structuresdfs-and-similargamesgraphsgreedymathsortingstrees
CF 1615C - Menorah

We have a row of candles on a Hanukkah menorah, and each candle is either lit or unlit. The current state is given as a binary string a, where 1 indicates a lit candle and 0 indicates unlit. We are asked to reach a target configuration b using a special operation.

codeforcescompetitive-programmingbrute-forcegraphsgreedymath
Kvant Physics Problem 32

Let the side length of the square cross section be $a$.

kvantphysics
CF 1615B - And It's Non-Zero

We are given many test cases, and each test case describes a contiguous array of integers from $l$ to $r$. The array is not arbitrary, it is always a full interval with no gaps.

codeforcescompetitive-programmingbitmasksgreedymath
CF 1615A - Closing The Gap

We have a row of towers, each with a certain number of blocks stacked vertically. The goal is to make the heights of all towers as close as possible. On any day, we can take a block from one tower and place it on another tower.

codeforcescompetitive-programminggreedymath
CF 1616G - Just Add an Edge

The problem presents a directed acyclic graph (DAG) where every edge points from a smaller-numbered vertex to a larger-numbered one.

codeforcescompetitive-programmingdfs-and-similardpgraphs
CF 1616H - Keep XOR Low

We are asked to count all non-empty subsets of an array where the XOR of every pair of elements does not exceed a given number x. Concretely, if we take any subset of indices from the array, and compute the XOR for every pair of values in that subset, each XOR must be ≤ x.

codeforcescompetitive-programmingbitmaskscombinatoricsdata-structuresdivide-and-conquerdpmath
CF 1616D - Keep the Average High

We are given an array of integers and a target value x. The task is to select as many elements as possible from this array, with a constraint on consecutive selected elements: any contiguous subarray of length at least two that is entirely selected must have an average at…

codeforcescompetitive-programmingdpgreedymath
CF 1616F - Tricolor Triangles

We are given a small undirected graph where every edge is supposed to end up painted with one of three colors. Some edges are already fixed with a color, while others start uncolored and must be assigned a value in {1, 2, 3}.

codeforcescompetitive-programmingbrute-forcegraphsmathmatrices
CF 1616E - Lexicographically Small Enough

We are given two strings of equal length, and we are allowed to modify the first string only by swapping adjacent characters. Each swap costs one operation.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedystrings
CF 1616A - Integer Diversity

We are given a list of integers and we are allowed to negate any subset of them. The goal is to maximize the number of distinct integers in the array after possibly negating some elements.

codeforcescompetitive-programmingimplementation
CF 1616B - Mirror in the String

A valid output is constructed by choosing a split point k in a string. After choosing k, the visible string becomes the prefix s[1..k] followed by its reverse. So every candidate answer is a palindrome that is “built from a prefix”.

codeforcescompetitive-programminggreedystrings
CF 1616C - Representative Edges

We are given an array of integers, and we are allowed to freely replace elements with any real numbers. The goal is to transform the array so that a very strong structural property holds: every subarray must satisfy a linear averaging condition that ties its sum only to its…

codeforcescompetitive-programmingbrute-forcegeometryimplementationmath
CF 1617C - Paprika and Permutation

Your “actual output” is: That means the program likely: - crashed early, or - never entered the solve loop, or - mis-parsed the first token and exited silently Now look at the input: Your code almost certainly does: So it reads: Correct.

codeforcescompetitive-programmingbinary-searchgreedymathsortings
CF 1617E - Christmas Chocolates

We are given a box of chocolates, each with a distinct type represented by a non-negative integer. Icy wants to make at least one pair of chocolates have the same type, but before any exchanges, she chooses two chocolates, say at indices $x$ and $y$.

codeforcescompetitive-programmingdfs-and-similardpgamesgraphsimplementationmathnumber-theoryshortest-pathstrees
CF 1617D2 - Too Many Impostors (hard version)

We are given a group of n players, each labeled from 1 to n, where n is always a multiple of 3. Some of these players are impostors, and the rest are crewmates. We do not know the number of impostors k in advance, but we are guaranteed that it is strictly between n/3 and 2n/3.

codeforcescompetitive-programmingconstructive-algorithmsimplementationinteractivemath
CF 1617D1 - Too Many Impostors (easy version)

We are given a set of players, each of whom is either an impostor or a crewmate. The total number of players, $n$, is divisible by three.

codeforcescompetitive-programmingconstructive-algorithmsimplementationinteractive
Kvant Physics Problem 33

Two beads of masses $m_1$ and $m_2$ move without friction on a smooth horizontal circular wire ring of circumference $L$.

kvantphysics
CF 1617B - GCD Problem

We are asked to construct three distinct positive integers $a$, $b$, and $c$ such that their sum equals a given integer $n$ and the greatest common divisor of the first two numbers equals the third: $gcd(a, b) = c$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsmathnumber-theory
CF 1617A - Forbidden Subsequence

We are given a string S of arbitrary lowercase letters and a string T that is always a permutation of "abc". The task is to rearrange the letters of S into a new string S' that is the lexicographically smallest possible while ensuring that T does not appear as a subsequence.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortingsstrings
CF 1618A - Polycarp and Sums of Subsequences

Thanks. Now we have more clarity. The previous solution was using brute-force divisor counting, which explains why: - Small numbers like 10 → 4 and 1 → 1 worked. - 25 → 3 (wrong) because brute-force counted divisors incorrectly.

codeforcescompetitive-programmingmathsortings
Kvant Physics Problem 30

A car moves along a straight road with its wheels rolling without slipping.

kvantphysics
CF 1618F - Reverse

We are allowed to repeatedly transform a positive integer by operating directly on its binary representation. In one move, we take the current binary string of the number, append either a 0 or a 1 at the end, reverse the entire resulting string, strip leading zeros, and…

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdfs-and-similarimplementationmathstrings
CF 1618G - Trader Problem

In this problem, Monocarp has a set of items, each with an integer price, and he can trade these items with another character’s items.

codeforcescompetitive-programmingdata-structuresdsugreedysortings
CF 1618E - Singers' Tour

We have a circular arrangement of $n$ towns, each with a singer who has an initial repertoire of $ai$ minutes. Every singer tours all towns in clockwise order, performing in each town.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1618D - Array and Operations

We are given a multiset of integers. We repeatedly remove two elements exactly $k$ times, and each removal produces a value that is added to a running score. After these $k$ operations, whatever elements remain are also added directly to the score.

codeforcescompetitive-programmingdpgreedymath
Kvant Physics Problem 29

The solution correctly addresses the exercise.

kvantphysics
CF 1618C - Paint the Array

We are given an array of positive integers. The task is to pick a positive integer $d$ and color the elements of the array in two colors: red for elements divisible by $d$, and blue for elements not divisible by $d$.

codeforcescompetitive-programmingmath
CF 1618B - Missing Bigram

We are given a sequence of overlapping two-letter strings, or bigrams, derived from a word consisting of only 'a' and 'b'.

codeforcescompetitive-programmingimplementation
CF 1619B - Squares and Cubes

Now we can clearly separate the real issue from all the noise in earlier attempts. Your “solution” is not consistently failing on a single algorithmic idea.

codeforcescompetitive-programmingimplementationmath
CF 1619G - Unusual Minesweeper

Each test case gives a set of mines placed on a 2D grid. Every mine has a position and a “natural lifetime”, meaning it will explode automatically after a given number of seconds if nothing triggers it earlier. The key twist is that explosions propagate.

codeforcescompetitive-programmingbinary-searchdfs-and-similardsugreedysortings
CF 1619H - Permutation and Queries

We are given a permutation of integers from 1 to $n$. Conceptually, this is an array of length $n$ in which every integer from 1 to $n$ appears exactly once, so every index maps to a unique value. On top of this array, we have two types of queries.

codeforcescompetitive-programmingbrute-forcedata-structuresdivide-and-conquertwo-pointers
CF 1619F - Let's Play the Hat?

We are asked to organize a fair schedule for a multi-table game. There are $n$ players, $m$ tables, and $k$ rounds. Each round, every table must host either $lfloor n/m rfloor$ or $lceil n/m rceil$ players.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedymath
CF 1619E - MEX and Increments

We are given an array of non-negative integers and we can increment any element by 1 any number of times. The task is to determine for each integer from 0 up to the array length whether it is possible to transform the array so that its MEX (minimum excluded value) equals that…

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdpgreedyimplementationmathsortings
CF 1619D - New Year's Problem

We are given several independent scenarios. In each scenario, Vlad has a fixed number of friends and a fixed number of shops. Each shop offers a value for every friend, representing how much joy that friend would get if their gift is bought there.

codeforcescompetitive-programmingbinary-searchgreedysortings
CF 1619A - Square String?

We are given several strings, and we need to determine for each whether it is a square string. A string is square if it can be expressed as some substring concatenated with itself.

codeforcescompetitive-programmingimplementationstrings
CF 1619C - Wrong Addition

The problem gives us two integers, a and s, and asks us to find a number b such that if we "add" a and b in Tanya's unusual way, we obtain s.

codeforcescompetitive-programmingimplementation
CF 1620C - BA-String

Ah! Now I understand exactly what’s happening. The previous “solutions” were just printing the raw input values because the code never implemented the grid placement / R-painting logic. That explains why your actual output is literally the input.

codeforcescompetitive-programmingbrute-forcedpgreedyimplementationmath
CF 1620G - Subsequences Galore

We are given up to 23 strings. Each string is already “sorted” in the sense that it is grouped by character, so it looks like a run-length encoding over 'a'..'z', for example "aaabccczzz". Now consider any subset of these strings.

codeforcescompetitive-programmingbitmaskscombinatoricsdp
CF 1620F - Bipartite Array

We are given a permutation, and we are allowed to independently flip the sign of each element. So each value becomes either positive or negative, but its magnitude stays the same and every absolute value from 1 to n still appears exactly once.

codeforcescompetitive-programmingdpgreedy
CF 1620E - Replace the Numbers

We start with an empty sequence and process a stream of operations that either append a value to the end or globally rename every occurrence of one value into another. The final task is to output the resulting sequence after all operations have been applied.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdsuimplementation
CF 1620A - Equal or Not Equal

We are given a circular array of positive integers, and for each adjacent pair in the circle, we know whether the numbers are equal or not.

codeforcescompetitive-programmingconstructive-algorithmsdsuimplementation
CF 1620D - Exact Change

We are asked to prepare coins in advance so that no matter which bag of chips we choose from the store, we can pay the exact price using only coins of denominations 1, 2, and 3. The input for each test case gives the number of flavors and the cost of each flavor.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedy
CF 1620B - Triangles on a Rectangle

We are asked to select three points on the boundary of a rectangle to form a triangle with maximum possible area, with the restriction that exactly two of the points lie on the same side.

codeforcescompetitive-programminggeometrygreedymath
CF 1621I - Two Sequences

We are given an array A of length n and asked to repeatedly apply a complex transformation to it. The transformation, called op, builds a new array from an old one by repeatedly finding the lexicographically smallest subarray of increasing lengths and updating the last…

codeforcescompetitive-programmingdata-structureshashingstring-suffix-structures
Kvant Physics Problem 26

A small block moves without friction on a smooth surface consisting of two horizontal half-planes separated in height by a vertical distance $h$.

kvantphysics
CF 1621A - Stable Arrangement of Rooks

Ah! That last error is simple: the code tries to use sys.stdin.buffer.read() but forgot to import sys. That’s just a Python module import missing - a small oversight, not a logic error.

codeforcescompetitive-programmingconstructive-algorithms
CF 1621H - Trains and Airplanes

We are given a connected undirected graph with n nodes. Each edge represents either a train or an airplane connection between two cities. Trains have a travel cost of 1, and airplanes have a travel cost of 0.

codeforcescompetitive-programmingdfs-and-similargraphsshortest-pathstrees
CF 1621G - Weighted Increasing Subsequences

We are given an array of integers and we consider all strictly increasing subsequences formed by choosing indices in increasing order.

codeforcescompetitive-programmingdata-structuresdpmath
CF 1621F - Strange Instructions

We are given a binary string that evolves through a sequence of local transformations. Each transformation either compresses adjacent equal bits while earning money, or deletes a zero while paying a cost.

codeforcescompetitive-programmingdata-structuresgreedyimplementation
CF 1621E - New School

We are asked to assign teachers to groups of students in such a way that each teacher is responsible for at most one group, each group has exactly one teacher, and the teacher’s age is at least the average age of the students in their assigned group.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedyimplementationsortings
CF 1621D - The Winter Hike

We are given a square grid of size $2n times 2n$. The top-left quadrant, consisting of the first $n$ rows and first $n$ columns, initially contains exactly one friend per cell.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1621B - Integers Shop

Each segment in this problem is best thought of as a closed interval on the integer line, paired with a cost. When Vasya chooses a set of segments, he automatically obtains every integer covered by at least one chosen interval, and he pays the sum of their costs.

codeforcescompetitive-programmingdata-structuresgreedyimplementation
CF 1621C - Hidden Permutations

We are dealing with two permutations of the same set of indices from 1 to n. One permutation, call it p, is hidden and fixed.

codeforcescompetitive-programmingdfs-and-similarinteractivemath
CF 1622B - Berland Music

I see exactly what is happening here. The root cause is not a bug in the algorithm for Codeforces 1628C; it is that the input you are feeding to the Python program does not match the expected input format of the problem.

codeforcescompetitive-programmingdata-structuresgreedymathsortings
CF 1622D - Shuffle

We are given a binary string, a sequence of 0s and 1s, and an integer $k$. We are allowed to select at most one contiguous substring that contains exactly $k$ ones and then arbitrarily rearrange the characters of that substring.

codeforcescompetitive-programmingcombinatoricsmathtwo-pointers
CF 1622F - Quadratic Set

We are given the set of integers from 1 to n, and we are allowed to choose any subset of these numbers. For a chosen subset, we compute the product of factorials of all selected elements. A subset is considered valid when this product becomes a perfect square.

codeforcescompetitive-programmingconstructive-algorithmshashingmathnumber-theory
CF 1622E - Math Test

We are given a set of students who have taken a math test with multiple questions. Each student answered some questions correctly and some incorrectly.

codeforcescompetitive-programmingbitmasksbrute-forcegreedy
CF 1622C - Set or Decrease

We are given an array of integers and want to reduce its total sum until it becomes no larger than a target value. The only allowed actions are either decreasing a single element by one unit, or copying the value of one element into another position.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedysortings
CF 1622A - Construct a Rectangle

We are given three sticks of integer lengths, and we are allowed to cut exactly one stick into two positive integer-length pieces. After this cut, we will have four sticks in total.

codeforcescompetitive-programminggeometrymath
Kvant Physics Problem 24

A body of mass $M$ is initially resting on a stand and attached to a vertical spring of spring constant $k$.

kvantphysics
Kvant Physics Problem 23

Two identical thin-walled tubes, each of mass $m$ and radius $R$, lie on a horizontal plane.

kvantphysics
CF 1623B - Game on Ranges

Ah, now the problem is clear. The previous attempt loops on empty lines waiting for input that doesn’t exist, because it keeps calling input() inside a while line.strip() == '' loop. On large or malformed input, this can hang forever, causing a timeout.

codeforcescompetitive-programmingbrute-forcedfs-and-similarimplementationsortings
CF 1623E - Middle Duplication

We are given a rooted binary tree where each node stores a single lowercase character. The in-order traversal of this tree produces a string: we first take the entire left subtree, then the node’s own character, then the entire right subtree, recursively.

codeforcescompetitive-programmingdata-structuresdfs-and-similargreedystringstrees
CF 1623D - Robot Cleaner Revisit

A robot moves deterministically inside an $n times m$ grid, bouncing off walls like a billiard ball. Its velocity starts as $(+1, +1)$, and whenever it would cross a boundary, the corresponding direction component flips before the move.

codeforcescompetitive-programmingimplementationmathprobabilities
CF 1623C - Balanced Stone Heaps

We are given a sequence of stone piles. In a single left-to-right sweep starting from the third pile, we are allowed to redistribute stones from each pile to the two previous piles in a fixed ratio: if we choose an amount $d$, we remove $3d$ stones from the current pile, add…

codeforcescompetitive-programmingbinary-searchgreedy
CF 1623A - Robot Cleaner

We have a robot moving inside a rectangular room with $n$ rows and $m$ columns. The robot starts at some cell $(rb, cb)$ and moves diagonally: one step down and one step right at a time.

codeforcescompetitive-programmingbrute-forceimplementationmath
CF 1624A - Plus One on the Subset

Now we can carefully trace exactly why the previous attempts failed. The problem is that the "chessboard XOR" must be applied not to the irregular input literally as read, but according to the grid structure, i.e.

codeforcescompetitive-programmingmath
CF 1624G - MinOr Tree

We are given a connected undirected graph where each edge has a positive integer weight. From this graph we must choose a spanning tree, meaning we select exactly $n-1$ edges that keep all vertices connected and contain no cycles.

codeforcescompetitive-programmingbitmasksdfs-and-similardsugraphsgreedy
CF 1624F - Interacdive Problem

We are interacting with a hidden integer $x$, where we are initially told a modulus-like parameter $n$. The only way to influence or observe the hidden state is by issuing commands that add a chosen value $c$ to $x$, after which we are told the value of $lfloor x / n rfloor$.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsinteractive