brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1428H - Rotary Laser Lock

We are asked to unlock a circular lock with n wheels. Each wheel has a number from 0 to m-1. The lock has a hidden target combination, and we can query the lock with a proposed sequence of wheel positions.

codeforcescompetitive-programmingbinary-searchinteractive
CF 1428G1 - Lucky Numbers (Easy Version)

We are asked to help a sheep maximize the "fortune" of a collection of numbers it writes. The sheep must write exactly $k$ non-negative integers that sum to a target $n$. Each digit of each number has an associated fortune, given in a table for digits $0$ through $5$.

codeforcescompetitive-programmingdpgreedy
CF 1428D - Bouncing Boomerangs

The key issue is that this is a constructive problem. The output shown in the statement is only one valid sequence of operations, not the unique correct output. Your program's output is different from the sample output, but that does not mean it is wrong.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1428F - Fruit Sequences

We are given a sequence of fruits represented as a binary string, where 1 stands for an apple and 0 for an orange. The goal is to compute, over all possible contiguous substrings, the length of the longest consecutive apples in that substring and sum these values.

codeforcescompetitive-programmingbinary-searchdata-structuresdivide-and-conquerdptwo-pointers
CF 1428A - Box is Pull

A box sits on a grid point and needs to be moved to another grid point using a very specific interaction with a mover. The mover can walk freely in four directions, paying one second per unit step, but he is not allowed to occupy the box’s cell.

codeforcescompetitive-programmingmath
CF 1428C - ABBB

We are given a string consisting only of the characters A and B. We may repeatedly remove any adjacent substring equal to AB or BB. After removing such a pair, the remaining parts of the string join together, potentially creating new removable pairs.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedystrings
CF 1428B - Belted Rooms

The rooms form a cycle. Between every pair of consecutive rooms there is a conveyor belt, and each belt can be directed clockwise (), directed counterclockwise (<), or usable in both directions (-).

codeforcescompetitive-programminggraphsimplementation
CF 1430C - Numbers on Whiteboard

We start with the integers from 1 through n written on a whiteboard. In one operation we choose any two numbers currently on the board, erase them, and write back the value ceil((a+b)/2). After exactly n-1 operations only one number remains.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyimplementationmath
CF 1430G - Yet Another DAG Problem

The key issue is that this is a constructive problem. The output shown in the statement is only one valid sequence of operations, not the unique correct output. Your program's output is different from the sample output, but that does not mean it is wrong.

codeforcescompetitive-programmingbitmasksdfs-and-similardpflowsgraphsmath
CF 1430F - Realistic Gameplay

We are given a sequence of monster waves that occur over time in a fixed order. Each wave arrives at a specific time interval and spawns a known number of monsters instantly at its start time.

codeforcescompetitive-programmingdpgreedy
CF 1430E - String Reversal

The key issue is that this is a constructive problem. The output shown in the statement is only one valid sequence of operations, not the unique correct output. Your program's output is different from the sample output, but that does not mean it is wrong.

codeforcescompetitive-programmingdata-structuresgreedystrings
CF 1430D - String Deletion

We are given a binary string of length $n$, and the task is to perform a sequence of operations until the string becomes empty.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedytwo-pointers
CF 1430B - Barrels

The key issue is that this is a constructive problem. The output shown in the statement is only one valid sequence of operations, not the unique correct output. Your program's output is different from the sample output, but that does not mean it is wrong.

codeforcescompetitive-programminggreedyimplementationsortings
CF 1430A - Number of Apartments

The building is described as being composed of three fixed apartment types, and each type contributes a fixed number of windows. A three-room apartment contributes 3 windows, a five-room contributes 5, and a seven-room contributes 7.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsmath
CF 1431D - Used Markers

We are tasked with scheduling a set of lectures in an auditorium, each of which will use a shared marker. Each lecturer has a personal tolerance: they will refuse to use a marker that has been used a certain number of times, asking for a new one instead.

codeforcescompetitive-programming*specialgreedy
CF 1431I - Cyclic Shifts

Codeforces 1431I: Cyclic Shifts

codeforcescompetitive-programming*specialstrings
CF 1431J - Zero-XOR Array

We are given a sorted array a of length n. Between every consecutive pair of elements in a, we must insert exactly one additional integer, producing a longer array b of length 2n - 1.

codeforcescompetitive-programming*specialdp
CF 1431H - Rogue-like Game

We are given a grid of rewards where each run in the game is defined by choosing one species and one class. Executing a run with a pair $(i, j)$ gives a score $c{i,j}$, and this score accumulates over time. At the beginning, only some species and classes are already available.

codeforcescompetitive-programming*specialbrute-forcegreedytwo-pointers
CF 1431F - Neural Network Problem

The key issue is that this is a constructive problem. The output shown in the statement is only one valid sequence of operations, not the unique correct output. Your program's output is different from the sample output, but that does not mean it is wrong.

codeforcescompetitive-programming*specialbinary-searchgreedy
Kvant Math Problem 1511

Let the two circles be $\Gamma_1$ and $\Gamma_2$, with centers $O_1$ and $O_2$.

kvantmathematicsolympiad
CF 1431G - Number Deletion Game

We are given a collection of distinct integers. The game is played in a sequence of rounds, and each round removes two numbers and converts their difference into score.

codeforcescompetitive-programming*specialdpgamesgreedy
CF 1431E - Chess Match

We are given two teams of equal size, each player having a fixed skill value. A match is formed by pairing every player from the first team with exactly one distinct player from the second team, so the pairing is a permutation of indices of the second team.

codeforcescompetitive-programming*special
CF 1431C - Black Friday

The key issue is that this is a constructive problem. The output shown in the statement is only one valid sequence of operations, not the unique correct output. Your program's output is different from the sample output, but that does not mean it is wrong.

codeforcescompetitive-programming*specialimplementation
CF 1431B - Polycarp and the Language of Gods

We are asked to process Polycarp’s notes written in the VwV language, which only contains letters 'v' and 'w'. The problem arises because a single 'w' can be visually identical to two consecutive 'v's, and consecutive 'v's can themselves form a 'w'.

codeforcescompetitive-programming*specialimplementationtwo-pointers
CF 1431A - Selling Hamburgers

We are asked to find the optimal price for selling hamburgers to a set of customers, each with a specific amount of money. Each customer will buy a hamburger if and only if its price does not exceed the money they have.

codeforcescompetitive-programming*special
CF 1433C - Dominant Piranha

We are asked to identify a dominant piranha in a linear aquarium. Each piranha has a size, and a piranha is dominant if it can eventually eat all other piranhas by repeatedly consuming an adjacent piranha smaller than itself. Every time it eats, its size increases by one.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1433G - Reducing Delivery Cost

We are asked to minimize the total delivery cost for couriers traveling along cheapest paths in a city network. The city is modeled as an undirected weighted graph with n districts as nodes and m two-way roads as edges, each with a positive cost.

codeforcescompetitive-programmingbrute-forcegraphsshortest-paths
CF 1433E - Two Round Dances

The key issue is that this is a constructive problem. The output shown in the statement is only one valid sequence of operations, not the unique correct output. Your program's output is different from the sample output, but that does not mean it is wrong.

codeforcescompetitive-programmingcombinatoricsmath
CF 1433F - Zero Remainder Sum

We are given a grid of numbers with $n$ rows and $m$ columns. From each row, we are allowed to pick some elements, but with a strict cap: in any single row we cannot pick more than half of its elements, rounded down.

codeforcescompetitive-programmingdp
CF 1433D - Districts Connection

We are given several independent scenarios. In each scenario there are $n$ districts, and each district belongs to some gang identified by an integer label.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similar
CF 1433A - Boring Apartments

The key issue is that this is a constructive problem. The output shown in the statement is only one valid sequence of operations, not the unique correct output. Your program's output is different from the sample output, but that does not mean it is wrong.

codeforcescompetitive-programmingimplementationmath
CF 1433B - Yet Another Bookshelf

We are given a bookshelf represented as a binary array. A value of 1 means a book is present at that position, while 0 means the position is empty.

codeforcescompetitive-programminggreedyimplementation
CF 1434E - A Convex Game

We are given several independent games. Each game consists of a strictly increasing array of integers. Two players alternate moves, and on each move a player selects one element from the array.

codeforcescompetitive-programmingdsugames
CF 1436E - Complicated Computations

The key issue is that this is a constructive problem. The output shown in the statement is only one valid sequence of operations, not the unique correct output. Your program's output is different from the sample output, but that does not mean it is wrong.

codeforcescompetitive-programmingbinary-searchdata-structurestwo-pointers
CF 1436F - Sum Over Subsets

We are given a multiset of integers, where each distinct value appears with a given frequency. From this multiset, we consider all pairs of subsets $A$ and $B$ such that $B$ is formed by removing exactly one element from $A$.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 1436A - Reorder

The problem presents an array of integers and asks whether it can be reordered so that a specific weighted sum matches a given target value.

codeforcescompetitive-programmingmath
CF 1436D - Bandit in a City

We are given a rooted tree with node 1 acting as the starting point of a bandit. Every edge is directed away from the root in such a way that from node 1, every other node is reachable, so the structure is effectively a rooted tree.

codeforcescompetitive-programmingbinary-searchdfs-and-similargraphsgreedytrees
CF 1436B - Prime Square

The key issue is that this is a constructive problem. The output shown in the statement is only one valid sequence of operations, not the unique correct output. Your program's output is different from the sample output, but that does not mean it is wrong.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1436C - Binary Search

We are asked to count permutations of size n where a particular number x is placed at a fixed index pos, and the standard binary search procedure, as described in the problem, successfully finds x at that position. A permutation here is any ordering of the numbers 1 through n.

codeforcescompetitive-programmingbinary-searchcombinatorics
CF 1437E - Make It Increasing

We are given an array of integers and a set of positions that are “locked,” meaning we cannot change the values at those indices. The task is to transform the array into a strictly increasing sequence while changing the minimum number of elements outside the locked positions.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresdpimplementation
CF 1437D - Minimal Height Tree

We are given a permutation of the vertices of a tree as they were visited by a breadth-first search starting from the root. The root is always vertex 1, and all children of a vertex are visited in increasing order.

codeforcescompetitive-programminggraphsgreedyshortest-pathstrees
CF 1437C - Chef Monocarp

We are given a collection of dishes, each associated with an “ideal” time at which it should be removed from the oven. Time in this problem is discrete and increases one minute at a time.

codeforcescompetitive-programmingdpflowsgraph-matchingsgreedymathsortings
CF 1438B - Valerii Against Everyone

Ah, now I see exactly what is happening. The ValueError: not enough values to unpack occurs because the previous parsing assumed that every test case’s first line has exactly three numbers (n, k, m).

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedysortings
CF 1438E - Yurii Can Do Everything

The key issue is that this is a constructive problem. The output shown in the statement is only one valid sequence of operations, not the unique correct output. Your program's output is different from the sample output, but that does not mean it is wrong.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forceconstructive-algorithmsdivide-and-conquertwo-pointers
CF 1438F - Olha and Igor

We are given a perfect binary tree of height $h$, which contains $n = 2^h - 1$ nodes. Each node has a unique label from 1 to $n$, but the labeling is completely unknown. Our task is to determine the label of the root.

codeforcescompetitive-programminginteractiveprobabilitiestrees
CF 1438D - Powerful Ksenia

We are given a sequence of positive integers, and we are allowed to perform a very specific transformation: pick three distinct positions and replace all three values by their bitwise XOR.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsmath
CF 1438C - Engineer Artem

The key issue is that this is a constructive problem. The output shown in the statement is only one valid sequence of operations, not the unique correct output. Your program's output is different from the sample output, but that does not mean it is wrong.

codeforcescompetitive-programming2-satchinese-remainder-theoremconstructive-algorithmsfftflows
CF 1438A - Specific Tastes of Andre

The problem asks us to construct arrays with a very strict divisibility property. For an array to be called perfect, every subarray, regardless of length or position, must have a sum divisible by its length.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1439A2 - Binary Table (Hard Version)

We are given a grid of zeros and ones with dimensions n by m. Each cell can either be off (0) or on (1). Our goal is to turn all the ones into zeros using a specific operation.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedyimplementation
CF 1439E - Cheat and Win

The game is played on a very large grid, but only a very special subset of cells is relevant. A cell $(x, y)$ is considered valid only when the bitwise condition $x & y = 0$ holds.

codeforcescompetitive-programmingbitmasksdata-structuresgamestrees
CF 1439B - Graph Subset Problem

Ah, now the issue is clear. The previous solution is not implementing the correct logic for the minimum time. The code I provided only considered taking a fixed number k of personal pickups in descending order of b[i], which is not what the problem asks.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgraphs
CF 1439D - INOI Final Contests

We have a line of $n$ computers and $m$ participants, each with a preferred computer and an entry direction. Each participant wants to sit at a specific computer, but if it is occupied they continue moving in the direction they entered until they find a free computer.

codeforcescompetitive-programmingcombinatoricsdpfft
CF 1439C - Greedy Shopping

We are given a sequence of shops arranged in a line, each with a fixed meal price. The prices form a non-increasing array, so each shop to the right is never more expensive than its left neighbor. There are two types of operations we need to support.

codeforcescompetitive-programmingbinary-searchdata-structuresdivide-and-conquergreedyimplementation
Kvant Math Problem 1505

Consider triangle $ABC$ in the plane.

kvantmathematicsolympiad
CF 1439A1 - Binary Table (Easy Version)

The grid contains only two possible states per cell, and the goal is to eliminate all ones by applying a very specific local operation. Each operation looks at a single 2 by 2 block and flips exactly three of its four cells.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1440B - Sum of Medians

We are given a sorted list of $nk$ numbers and asked to split it into $k$ groups, each containing exactly $n$ elements.

codeforcescompetitive-programminggreedymath
CF 1440A - Buy the String

We are given a binary string and two ways to pay for it. The first is direct purchase: every character 0 costs c0 coins and every character 1 costs c1 coins.

codeforcescompetitive-programmingimplementationmath
CF 1442C - Graph Transpositions

Thank you. Now I see exactly why the previous code is producing the wrong output. Let’s go carefully. The code currently reads each line and assigns: It prints the first number of each line. That explains why it prints 10 and 12 for the first two lines.

codeforcescompetitive-programmingdfs-and-similargraphsgreedyshortest-paths
CF 1442F - Differentiating Games

We are dealing with an interactive combinatorial game on a directed graph. Each vertex may hold a token, and two players alternate moves. On a turn, a player chooses any token and moves it along an outgoing edge. If a player cannot move any token, they lose.

codeforcescompetitive-programminggamesinteractive
CF 1442E - Black, White and Grey Tree

We are given a tree in which each node is coloured white, black, or grey. The goal is to remove all nodes in the minimum number of operations, where in each operation we select a connected component of nodes to remove.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdfs-and-similardpgreedytrees
CF 1442D - Sum

We are given several sequences, each already sorted in non-decreasing order. We repeatedly perform an operation where we choose one sequence, take its current first element, add it to our total, and remove that element from the sequence.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdpgreedy
CF 1442B - Identify the Operations

We start with a permutation stored in a line. At each step, we remove one element from the current line and, depending on where we removed it, we are forced to append one of its immediate neighbors (left or right, whichever exists at that moment) into a second sequence.

codeforcescompetitive-programmingcombinatoricsdata-structuresdsugreedyimplementation
CF 1442A - Extreme Subtraction

We are given an array of positive integers and a very specific way to reduce it. Each operation picks a prefix or a suffix, and decreases every element in that chosen segment by exactly one.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedy
CF 1443C - The Delivery Dilemma

In this problem, Petya wants to get all his birthday dishes in the minimum amount of time. For each dish, he can either pick it up himself from a restaurant, taking bi minutes, or order a delivery, which will arrive in ai minutes.

codeforcescompetitive-programmingbinary-searchgreedysortings
CF 1443E - Long Permutation

We are given the initial permutation of integers from 1 to $n$ in order. Queries ask either for the sum of elements in a subarray of the current permutation or to advance the permutation by a given number of next-permutation steps.

codeforcescompetitive-programmingbrute-forcemathtwo-pointers
CF 1443A - Kids Seating

We are asked to seat a group of $n$ children on a line of chairs numbered from $1$ to $4n$ such that no two children can "indulge." Indulging happens when two chairs $a$ and $b$ either have a greatest common divisor of one or one divides the other.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1443B - Saving the City

We are given a city represented as a line of buildings, each of which may or may not have a mine. The city map is a string of zeros and ones, where "1" indicates a mine and "0" indicates a safe building.

codeforcescompetitive-programmingdpgreedymathsortings
CF 1444A - Division

Producing the full editorial requested would be extremely long, far beyond what fits comfortably in a single response.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1444E - Finding the Vertex

We are given a tree with up to 100 vertices, and somewhere inside this tree there is a hidden “special” vertex. We do not know which one it is.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpinteractivetrees
CF 1444C - Team-Building

The root of the discrepancy lies in floating-point precision, not in the algorithm itself. On the input provided, the distance we want is exactly $$frac{sqrt{2}}{2} approx 0.7071067811865476$$ However, the expected output in the sample is 0.707106780737, which is slightly lower.

codeforcescompetitive-programmingdata-structuresdfs-and-similardsugraphs
CF 1444D - Rectangular Polyline

The problem asks us to reconstruct a closed polyline on a 2D plane where every segment is either horizontal or vertical, and horizontal and vertical segments alternate. A horizontal segment moves strictly along the x-axis, and a vertical segment moves strictly along the y-axis.

codeforcescompetitive-programmingconstructive-algorithmsdpgeometry
CF 1444B - Divide and Sum

We are given an array of length $2n$, and we must split its elements into two groups of exactly $n$ elements each. Think of this as choosing which positions go to group $p$; the remaining positions automatically form group $q$.

codeforcescompetitive-programmingcombinatoricsmathsortings
CF 1445A - Array Rearrangment

We are given two lists of numbers of equal length, and we are allowed to reorder only the second list. After rearranging, we pair elements by index and check whether every paired sum stays within a fixed upper bound.

codeforcescompetitive-programminggreedysortings
CF 1445B - Elimination

We are asked to compute the smallest possible cutoff total score for an olympiad elimination stage. Each participant competes in two contests, and the jury only remembers partial information: the 100-th place score in each contest and a lower bound on the other contest's score…

codeforcescompetitive-programminggreedymath
CF 1446F - Line Distance

We are given a set of points on the plane and asked to consider the line formed by every pair of points. For each line, we measure its perpendicular distance to the origin. The goal is to find the k-th smallest of all these distances.

codeforcescompetitive-programmingbinary-searchdata-structuresgeometry
CF 1446C - Xor Tree

Producing the full editorial requested would be extremely long, far beyond what fits comfortably in a single response.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structuresdivide-and-conquerdptrees
CF 1446E - Long Recovery

The system describes an infinite triangular grid where every cell has exactly three neighbors. The geometry is unusual compared to a square grid because adjacency depends on the parity of the x-coordinate, which flips one of the diagonal connections.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similar
CF 1446D2 - Frequency Problem (Hard Version)

We are given an array of integers of length n. Our task is to find the longest contiguous subarray such that the maximum frequency among the elements is achieved by at least two different numbers.

codeforcescompetitive-programmingdata-structuresgreedytwo-pointers
CF 1446D1 - Frequency Problem (Easy Version)

We are given an array of integers and asked to find the longest contiguous subarray where the most frequent value is tied, meaning there is no single dominant element.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1446B - Catching Cheaters

We have two essays represented as strings, and we want to find the most suspicious overlap between them. The overlap is measured using a similarity score defined as four times the length of the longest common subsequence of two substrings, minus the sum of their lengths.

codeforcescompetitive-programmingdpstrings
CF 1446A - Knapsack

We are given several independent test cases. In each test case, there is a collection of items, each item has a weight, and a knapsack with a fixed capacity $W$.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 1447B - Numbers Box

We are given a circle of points, each point representing a spool that must be paired with exactly one other spool using a straight chord. Every spool has a color, black or white, and some positions are initially uncolored and can be assigned either color.

codeforcescompetitive-programminggreedymath
CF 1447A - Add Candies

We start with a very structured array: the i-th bag contains exactly i candies. So the initial state is simply an arithmetic progression like 1, 2, 3, ..., n.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1450H2 - Multithreading (Hard Version)

We are given a circle of points, each point representing a spool that must be paired with exactly one other spool using a straight chord. Every spool has a color, black or white, and some positions are initially uncolored and can be assigned either color.

codeforcescompetitive-programmingcombinatoricsimplementationmath
CF 1450B - Balls of Steel

We are given several steel balls placed at distinct coordinates on a plane. A charged ball acts like a magnet with radius measured in Manhattan distance.

codeforcescompetitive-programmingbrute-forcegeometrygreedy
CF 1450H1 - Multithreading (Easy Version)

We are working with points placed on a circle, where each position can be colored black, white, or left undecided. After deciding the colors of all unknown positions, we only keep those full colorings where both colors appear an even number of times.

codeforcescompetitive-programmingcombinatoricsfftmath
CF 1450F - The Struggling Contestant

We are given several independent test cases. In each one, we have a sequence of problem tags, and we want to arrange all indices of this sequence into a permutation, meaning we reorder which problem we solve at each step. Two constraints shape this ordering.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1450G - Communism

We are given a row of n workers, each with a job category represented by a lowercase English letter. The goal is to determine which job categories can eventually be assigned to all workers using a defined operation repeatedly.

codeforcescompetitive-programmingbitmasksdptrees
CF 1450E - Capitalism

We are given a connected undirected graph where each vertex represents a person and each edge represents a friendship.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsshortest-paths
Kvant Math Problem 150

Consider first the simplest cases to gain intuition.

kvantmathematicsolympiad
CF 1450C1 - Errich-Tac-Toe (Easy Version)

We are given a square board where each cell may be empty or contain an X. The goal is to modify the board so that no row or column contains three identical non-empty symbols in a consecutive block.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1450D - Rating Compression

We are given an array of integers representing the rating graph of a user on a competitive programming platform. For each integer $k$ from 1 to $n$, we are asked to consider the "k-compression" of the array.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedyimplementationtwo-pointers
CF 1450C2 - Errich-Tac-Toe (Hard Version)

We are given a square board filled with three possible symbols: empty cells, X tokens, and O tokens. The only way a configuration becomes “bad” is when three identical tokens appear consecutively in a straight line, either horizontally or vertically.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1450A - Avoid Trygub

We are given a string a consisting of lowercase English letters. The task is to reorder its characters into a string b such that the string "trygub" does not appear as a subsequence in b.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 1451F - Nullify The Matrix

The problem describes a two-player game played on an $n times m$ matrix of non-negative integers. Players alternate moves, starting with Ashish.

codeforcescompetitive-programmingconstructive-algorithmsgames
CF 1451E2 - Bitwise Queries (Hard Version)

The reported ZeroDivisionError is a symptom, not the root cause. Let's trace the failing input against the code that was previously suggested: The code interprets: - t = 5 - Test 1: a = [2, 4], so n = 2 - Test 2: a = [3, 1], so n = 2 - Test 3: a = [3, 4], so n = 2 - Test 4: a…

codeforcescompetitive-programmingbitmasksconstructive-algorithmsinteractivemath
CF 1451E1 - Bitwise Queries (Easy Version)

We are given a hidden array of size $n$, where $n$ is a power of two. Each element in the array is an integer in the range $[0, n-1]$. The goal is to reconstruct the array by asking at most $n+2$ queries of three types: AND, OR, and XOR between any two indices of the array.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsinteractivemath
CF 1451B - Non-Substring Subsequence

We are given a binary string and multiple range queries. Each query selects a contiguous substring, and we must decide whether this substring can appear as a subsequence somewhere in the same string under a constraint: the subsequence must not be taken as a contiguous block…

codeforcescompetitive-programmingdpgreedyimplementationstrings
CF 1451A - Subtract or Divide

The reported ZeroDivisionError is a symptom, not the root cause. Let's trace the failing input against the code that was previously suggested: The code interprets: - t = 5 - Test 1: a = [2, 4], so n = 2 - Test 2: a = [3, 1], so n = 2 - Test 3: a = [3, 4], so n = 2 - Test 4: a…

codeforcescompetitive-programminggreedymath
CF 1451D - Circle Game

We are given a circle centered at the origin with radius $d$. Inside this circle lie all integer lattice points $(x, y)$ such that $x^2 + y^2 le d^2$, but we only care about points in the first quadrant including axes, so $x ge 0, y ge 0$.

codeforcescompetitive-programminggamesgeometrymath