brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1761F1 - Anti-median (Easy Version)

We are asked to construct permutations of integers from 1 to (n) with a specific property: no subarray of odd length greater than or equal to three can have its middle element equal to the median of that subarray.

codeforcescompetitive-programmingdpmath
CF 1761D - Carry Bit

We are asked to count how many pairs of non-negative integers $a$ and $b$, each less than $2^n$, produce exactly $k$ carry bits when summed in binary.

codeforcescompetitive-programmingcombinatoricsmath
CF 1761C - Set Construction

We are given a binary $n times n$ matrix, and our task is to construct $n$ distinct non-empty sets of integers between $1$ and $n$.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsgreedy
CF 1761B - Elimination of a Ring

We are given a cyclic sequence, which means the first and last positions are also adjacent. Initially, no two adjacent elements are equal. At any moment, Muxii may choose one element and erase it. After that erasure, the ring checks whether equal values have become adjacent.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1761A - Two Permutations

We are not asked to construct the permutations. We only need to decide whether two permutations of length n can exist such that they share exactly a positions at the beginning and exactly b positions at the end. Think about two permutations p and q.

codeforcescompetitive-programmingbrute-forceconstructive-algorithms
CF 1762G - Unequal Adjacent Elements

We are given an array of values and asked to reorder indices, not values, into a permutation. The permutation must satisfy two simultaneous constraints. First, every element from the third position onward must be strictly larger than the element two positions before it.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 1762C - Binary Strings are Fun

We are given a binary string s. For every prefix of s, we define a value f(prefix). To compute f(x), we look at all possible extensions of x. If x has length k, an extension has length 2k-1.

codeforcescompetitive-programmingcombinatoricsmath
CF 1762F - Good Pairs

We are asked to count the number of "good pairs" in an array. A pair of positions $(l, r)$ is good if we can move from index $l$ to $r$ by hopping forward in the array along a sequence of indices where each consecutive pair differs by at most $k$.

codeforcescompetitive-programmingbinary-searchdata-structuresdp
CF 1762E - Tree Sum

We are asked to consider edge-weighted trees with vertices numbered from 1 to $n$, where each edge has weight either $1$ or $-1$. A tree is called good if for every vertex, the product of the weights of all edges incident to that vertex equals $-1$.

codeforcescompetitive-programmingcombinatoricsmathtrees
CF 1762D - GCD Queries

We are asked to find an index of the element 0 in a hidden permutation of integers from 0 to n-1. The permutation is not given directly, but we can ask for the greatest common divisor (GCD) of any two distinct elements in the array.

codeforcescompetitive-programmingconstructive-algorithmsinteractivenumber-theory
CF 1762B - Make Array Good

We are asked to transform an array of positive integers into one that is "good" according to a divisibility property: for every pair of elements, the larger must be divisible by the smaller.

codeforcescompetitive-programmingconstructive-algorithmsimplementationnumber-theorysortings
CF 1762A - Divide and Conquer

We are given an array of positive integers and we are asked to make its sum even using a special operation: pick any element and replace it with its integer half, the floor of dividing by two.

codeforcescompetitive-programminggreedymathnumber-theory
CF 1763B - Incinerate

We are fighting a set of monsters. Every monster has a health value and a power value. Genos repeatedly performs attacks. If the current attack strength is k, every monster that is still alive loses k health simultaneously.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresimplementationmathsortings
CF 1763E - Node Pairs

We are given a directed graph on an unknown number of vertices. The graph is required to satisfy a structural condition: among all ordered pairs of vertices, there are exactly (p) pairs ((u,v)) with (u < v) such that both vertices can reach each other.

codeforcescompetitive-programmingdpgraphsmathnumber-theory
CF 1763F - Edge Queries

Codeforces 1763F: Edge Queries

codeforcescompetitive-programmingdata-structuresdfs-and-similardpdsugraphstrees
CF 1763D - Valid Bitonic Permutations

We are asked to count the number of permutations of the numbers from 1 to n that are bitonic and satisfy two fixed positions. A bitonic permutation is one that strictly increases up to a certain peak index, then strictly decreases afterward.

codeforcescompetitive-programmingcombinatoricsdpimplementationmathnumber-theory
CF 1763C - Another Array Problem

We are given an array of integers, and we are allowed to repeatedly apply a very specific transformation: pick two positions $i < j$, compute the absolute difference of the values at the ends, and overwrite the entire segment $[i, j]$ with that single value.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedy
CF 1763A - Absolute Maximization

We have an array of integers. An operation allows us to pick any two positions and a bit index, then swap the values of that bit between the two numbers. The crucial detail is that the bit position is fixed during a swap.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedymath
CF 1764G3 - Doremy's Perfect DS Class (Hard Version)

We are given a hidden permutation of integers from 1 to $n$, and our goal is to identify the position of the number 1 with at most 20 interactive queries.

codeforcescompetitive-programmingbinary-searchinteractive
CF 1764G1 - Doremy's Perfect DS Class (Easy Version)

We are asked to locate the position of the number 1 in a hidden permutation of integers from 1 to n. The permutation is fixed, and we can query the permutation by providing a range [l, r] and a divisor k.

codeforcescompetitive-programmingbinary-searchinteractive
CF 1764H - Doremy's Paint 2

We have an array of n buckets, where each bucket initially contains a unique color equal to its 1-based index. There are m paint operations, each defined by a segment [li, ri].

codeforcescompetitive-programmingdata-structures
CF 1764G2 - Doremy's Perfect DS Class (Medium Version)

We are given a hidden permutation of numbers from 1 to n. We cannot see it directly, but we can interactively ask queries.

codeforcescompetitive-programmingbinary-searchinteractive
CF 1764F - Doremy's Experimental Tree

We are given a mysterious tree with n vertices where each edge has a positive integer weight. For every pair (i, j) with 1 ≤ j ≤ i ≤ n, a “virtual experiment” was done: an edge of weight 1 was temporarily added between vertices i and j.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similardsusortingstrees
CF 1764D - Doremy's Pegging Game

We are asked to count the number of sequences in which red pegs on a regular polygon can be removed while maintaining a geometric constraint: the rubber band around the remaining red pegs must not enclose the central blue peg.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1764B - Doremy's Perfect Math Class

We start with a finite set of positive integers. We are allowed to repeatedly pick two numbers, subtract the smaller from the larger, and insert the result if it is not already present. The process continues until no new numbers can be created.

codeforcescompetitive-programmingmathnumber-theory
CF 1764E - Doremy's Number Line

I can write a high-quality editorial only if I can first reconstruct the intended solution and proof. For Codeforces 1764E (rating 2400), the key difficulty is that the solution relies on a fairly intricate DP/greedy argument.

codeforcescompetitive-programmingdpgreedysortings
CF 1764C - Doremy's City Construction

We are asked to build a simple undirected graph with vertices labeled by altitudes. Each vertex has a number representing its altitude, and we may connect pairs of vertices by edges under two constraints. The first is standard: no self-loops or multiple edges.

codeforcescompetitive-programminggraphsgreedy
CF 1764A - Doremy's Paint

We are given an array and asked to choose a contiguous segment. For any chosen segment, we compute two quantities: its length and how many distinct values appear inside it. The score of a segment is the length minus the number of distinct values.

codeforcescompetitive-programminggreedy
CF 1765N - Number Reduction

Codeforces 1765N: Number Reduction

codeforcescompetitive-programminggreedy
CF 1765H - Hospital Queue

Got it. Let’s carefully trace what is happening. The previous solution attempt fails because it misinterprets the keyboard behavior. Mishka’s keyboard alternates between single-letter and double-letter presses globally, not per character. That is the key subtlety.

codeforcescompetitive-programmingbinary-searchgraphsgreedyimplementation
CF 1765M - Minimum LCM

We are asked to split a given integer n into two positive parts a and b so that their sum stays fixed at n. Among all such splits, we want the pair that makes the least common multiple of a and b as small as possible.

codeforcescompetitive-programmingmathnumber-theory
CF 1765L - Project Manager

Codeforces 1765L: Project Manager

codeforcescompetitive-programmingbrute-forcedata-structuresimplementation
CF 1765K - Torus Path

We are given a square grid of size $n times n$ where each cell has a non-negative integer. A chip starts at the top-left corner, and we want to move it to the bottom-right corner.

codeforcescompetitive-programminggreedymath
CF 1765I - Infinite Chess

Codeforces 1765I: Infinite Chess

codeforcescompetitive-programmingimplementationshortest-paths
CF 1765J - Hero to Zero

We are given two arrays, a and b, both of length n. From these, we can build a matrix c where each entry c[i][j] is the absolute difference The allowed operations are of two types: we can increment or decrement entire rows or columns, which affects multiple elements…

codeforcescompetitive-programminggraph-matchingsmath
CF 1765G - Guess the String

We are asked to reconstruct a hidden binary string of length $n$, knowing that its first character is always '0'. We cannot read the string directly.

codeforcescompetitive-programmingconstructive-algorithmsinteractiveprobabilities
CF 1765E - Exchange

For input n = 1, k = 1: - Deck: 4 cards, one of each suit. - Sliding window k = 1 means Monocarp looks at the last card drawn (or zero for the first card) and guesses the least frequent suit.

codeforcescompetitive-programmingbrute-forcemath
CF 1765B - Broken Keyboard

We are asked to determine whether a given word could have been typed on a keyboard with a very specific malfunction: every other keystroke produces the letter twice instead of once.

codeforcescompetitive-programminggreedy
CF 1765F - Chemistry Lab

We have a chemistry lab scenario where Monocarp can buy contracts that give him unlimited access to specific solutions of an acid. Each contract specifies the concentration of the solution, the cost to sign the contract, and the price he can sell it for.

codeforcescompetitive-programmingdpgeometryprobabilities
CF 1765D - Watch the Videos

We are given a sequence of videos, each with a download size, and a fixed disk capacity that limits how many megabytes can be stored at once. Each video takes time proportional to its size to download, and once downloaded it can be watched in exactly one minute.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmstwo-pointers
CF 1765C - Card Guessing

We are dealing with a long sequence of independent random experiments: a deck contains exactly four suits, and each suit appears exactly (n) times, so the total length is (4n). The deck is shuffled uniformly at random, so every permutation is equally likely.

codeforcescompetitive-programmingcombinatoricsdpprobabilities
CF 1765A - Access Levels

Each document is described by which developers should be able to open it. So every column of the input matrix is a subset of developers: those rows where the value is one form the “approved set” for that document.

codeforcescompetitive-programmingbitmasksdsuflowsgraph-matchings
CF 1766F - MCF

We are given a directed graph where each edge has a capacity and a cost. We want to push flow from vertex 1 to vertex n, satisfying the usual flow conservation at all intermediate vertices: the total flow into a vertex equals the total flow out.

codeforcescompetitive-programmingflows
CF 1766E - Decomposition

For any array segment, we process its elements from left to right and maintain a list of subsequences. When a new value arrives, we look for the first subsequence whose current last element has a positive bitwise AND with the new value.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdivide-and-conquerdptwo-pointers
CF 1766A - Extremely Round

Input: Expected: Actual: a long list of card distributions So the program is no longer failing with a crash, but producing completely irrelevant output.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1766D - Lucky Chains

We are given a list of pairs of positive integers, and for each pair, we want to explore a sequence of consecutive pairs formed by simultaneously incrementing both numbers.

codeforcescompetitive-programmingmathnumber-theory
CF 1766C - Hamiltonian Wall

We are given a grid with two rows and m columns representing a wall. Each cell is either black (B) or white (W). Monocarp wants to paint all black cells exactly once in a single continuous path that moves only between adjacent cells.

codeforcescompetitive-programmingdpimplementation
CF 1766B - Notepad#

We are asked to type a string s of length n using a text editor that allows two operations: appending a single character or copying a contiguous substring that has already been typed and pasting it at the end.

codeforcescompetitive-programmingimplementation
CF 1767A - Cut the Triangle

The problem gives a triangle in the plane with positive area, specified by three points with integer coordinates.

codeforcescompetitive-programmingimplementation
CF 1767D - Playoff

We are looking at a tournament structured as a perfect binary tree. At the start there are $2^n$ teams, each assigned a distinct skill value from 1 to $2^n$.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsdpgreedymath
CF 1767F - Two Subtrees

We are given a rooted tree where every vertex stores an integer label. For each query, we are given two vertices, and we must look at two subtrees rooted at these vertices.

codeforcescompetitive-programmingdata-structurestrees
CF 1767E - Algebra Flash

We are given a linear sequence of platforms, each with a fixed color, and a cost associated with activating all platforms of each color. Initially, all platforms are deactivated. You can only jump from a platform to the next one or skip one to the platform after that.

codeforcescompetitive-programmingbitmasksbrute-forcedpgraphsmathmeet-in-the-middletrees
CF 1767C - Count Binary Strings

We are given an $n times n$ upper-triangular table of constraints on substrings of a binary string $s$ of length $n$. For every interval $[i, j]$, we are told whether that segment must be constant, must contain both 0 and 1, or is unconstrained.

codeforcescompetitive-programmingdata-structuresdp
CF 1767B - Block Towers

We are given several towers, each containing a certain number of blocks. The goal is to maximize the number of blocks on the first tower by moving blocks from towers that have more blocks than others.

codeforcescompetitive-programmingdata-structuresgreedysortings
CF 1768F - Wonderful Jump

Input: Expected: Two different configurations (two different games), each printed as a pair of 18-card hands. Actual output: Two identical blocks: This means: - Your program does print two cases - But they are not correctly separated as distinct constructions in memory - Or…

codeforcescompetitive-programmingdpgreedy
CF 1768D - Lucky Permutation

We are given a permutation of integers from 1 to $n$, and we can swap any two elements to change the permutation. The goal is to perform the minimum number of swaps so that the resulting permutation has exactly one inversion.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsgreedy
CF 1768E - Partial Sorting

We are given a permutation of size 3n, which is an array containing every integer from 1 to 3n exactly once in some order. We have two allowed operations: we can either sort the first 2n elements or sort the last 2n elements.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 1768B - Quick Sort

We are given a permutation, meaning a rearrangement of numbers from 1 to n. In one move, we pick any k elements, remove them from the array, sort just those chosen elements, and append them back to the end. The rest of the array keeps its relative order.

codeforcescompetitive-programminggreedymath
CF 1768A - Greatest Convex

The problem asks us to find the largest integer x less than a given integer k such that the sum of x! and (x-1)! is divisible by k. In plain language, we want a number just below k where adding its factorial to the factorial of the previous number gives a multiple of k.

codeforcescompetitive-programminggreedymathnumber-theory
CF 1768C - Elemental Decompress

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationsortings
CF 1769D2 - Игра в Девятку II

We are dealing with a deterministic two-player card game played with a fixed 36-card deck. The deck is split between two players, and the game evolves by repeatedly placing cards onto a shared table under strict adjacency rules: a card can only be played if it either is a nine…

codeforcescompetitive-programming*specialbrute-force
CF 1769D3 - Игра в Девятку III

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programming*specialbrute-force
CF 1769D1 - Игра в Девятку I

We have a two-player card game using a 36-card deck, where each player gets 18 cards. The cards are numbered 6 through Ace in four suits. Alice moves first. On their turn, a player can play: - Any 9, at any time.

codeforcescompetitive-programming*specialbrute-forcedp
CF 1769C2 - Подкрутка II

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programming*specialdp
CF 1769A - Узкая дорога

We are given a line of scooters sorted by their initial distance to a destination point. Scooter $1$ starts closest, scooter $n$ farthest. Each scooter has a fixed nominal speed equal to its index, so higher-index scooters try to move faster.

codeforcescompetitive-programming*specialmath
CF 1769C1 - Подкрутка I

We are given a multiset of “events”, where each event originally belongs to a specific day. The array is sorted, and each value tells us on which day a commit happened.

codeforcescompetitive-programming*specialbrute-forcedpgreedy
CF 1769B2 - Копирование файлов II

We are asked to model copying multiple files sequentially from one server to another, tracking progress in two ways: per-file and overall. Each file has a size in bytes, and we simulate copying byte by byte.

codeforcescompetitive-programming*specialbinary-searchbrute-forcemath
CF 1769B1 - Копирование файлов I

We are asked to simulate the progress of copying multiple files from one server to another. Each file has a size in bytes, and copying is sequential, one byte at a time.

codeforcescompetitive-programming*specialbrute-forceimplementationmath
CF 1770H - Koxia, Mahiru and Winter Festival

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingconstructive-algorithms
CF 1770F - Koxia and Sequence

We are asked to work with sequences of non-negative integers of length $n$. Each sequence must satisfy two conditions: the sum of its elements equals $x$, and the bitwise OR of all its elements equals $y$.

codeforcescompetitive-programmingbitmaskscombinatoricsdpmathnumber-theory
CF 1770G - Koxia and Bracket

We are given a string composed entirely of opening and closing parentheses, and we are asked to make it balanced by removing the fewest possible characters.

codeforcescompetitive-programmingdivide-and-conquerfftmath
CF 1770E - Koxia and Tree

We are given a tree with $n$ vertices and $k$ butterflies initially located on distinct vertices. Each edge in the tree will be randomly directed, and butterflies can move along edges if the starting vertex has a butterfly and the target vertex is empty.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardpdsumathprobabilitiestrees
CF 1770D - Koxia and Game

We are given two arrays, a and b, each of length n, with elements between 1 and n. We have to choose a third array c of the same length so that a constructed game is won by Koxia. The game proceeds in n rounds.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdfs-and-similardsuflowsgamesgraph-matchingsgraphsimplementation
CF 1770A - Koxia and Whiteboards

We start with an array of numbers placed on whiteboards. Then we are given a sequence of replacement values. Each replacement operation allows us to pick any one whiteboard and overwrite its current value with the new value from the operation.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1770B - Koxia and Permutation

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingconstructive-algorithms
CF 1770C - Koxia and Number Theory

We are given an array of positive integers and we are allowed to choose a single positive shift value $x$. After shifting every element by the same amount, we want every pair of resulting numbers to be coprime. Equivalently, we transform the array into $bi = ai + x$.

codeforcescompetitive-programmingbrute-forcechinese-remainder-theoremmathnumber-theory
CF 1771D - Hossam and (sub-)palindromic tree

We are given a tree with $n$ vertices, each labeled with a lowercase English letter. For any two vertices $v$ and $u$, define the string $s(v,u)$ as the sequence of letters along the unique path connecting them.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similardpstringstrees
CF 1771F - Hossam and Range Minimum Query

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structureshashingprobabilitiesstringstrees
CF 1771E - Hossam and a Letter

We are given an n × m grid representing Hossam's ground. Each cell has a quality: perfect (.), medium (m), or bad (). Hossam wants to draw the letter 'H' by placing walls on some cells. The letter consists of two vertical lines and one horizontal line connecting them.

codeforcescompetitive-programmingbrute-forcedpimplementationtwo-pointers
CF 1771B - Hossam and Friends

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdptwo-pointers
CF 1771C - Hossam and Trainees

This is a Type C (optimization) problem. The requirements are to establish an upper bound on the boundary length $L$ between horizontal and vertical dominoes and to exhibit a construction that achieves the maximal possible $L$.

codeforcescompetitive-programminggreedymathnumber-theory
CF 1771A - Hossam and Combinatorics

We are given an array for each test case, and we are asked to focus only on pairs of positions in that array. From every ordered pair of distinct indices, we can compute the absolute difference between the two values.

codeforcescompetitive-programmingcombinatoricsmathsortings
CF 1772G - Gaining Rating

Monocarp wants to increase his chess rating from x to y by playing a set of n opponents with fixed ratings. Each game affects only Monocarp's rating: if his current rating is at least the opponent's, he wins and gains 1; otherwise, he loses and drops 1.

codeforcescompetitive-programmingbinary-searchgreedyimplementationmathsortingstwo-pointers
CF 1772E - Permutation Game

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programminggames
CF 1772F - Copy of a Copy of a Copy

We are given a sequence of black-and-white pictures, each represented as an $n times m$ matrix of zeros and ones.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsimplementationsortings
CF 1772D - Absolute Sorting

We are given a sequence of integers. We are allowed to pick a single real number $x$, and then every element $ai$ is transformed into its distance from $x$, namely $ The task is to determine whether there exists such a choice of $x$, and if it exists, output one valid value.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1772C - Different Differences

We are asked to build a strictly increasing sequence of length $k$, where every element lies between $1$ and $n$. Among all such sequences, we are not maximizing the values themselves but a derived quantity based on consecutive differences.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1772A - A+B?

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingimplementation
CF 1772B - Matrix Rotation

We are asked to consider domino tilings of an $8times8$ board. Each domino occupies exactly two adjacent cells and has an orientation, horizontal or vertical.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1773K - King's Puzzle

Thank you for the clarification. Let’s carefully trace why the previous solution produced 2.0 instead of 1.0 for the input: Participant 1 is Genie. The mask of the only question is: So mask = 0b11010 = 26. The initial alive set is all participants: S = 0b11111 = 31.

codeforcescompetitive-programmingconstructive-algorithms
CF 1773G - Game of Questions

Each test case gives a binary matrix with up to 17 columns and up to 2⋅10^5 rows. Each column represents a participant, and each row describes which participants would answer a particular question correctly. The questions are randomly permuted before being asked.

codeforcescompetitive-programmingbitmaskscombinatoricsdpfftmathprobabilities
CF 1773D - Dominoes

Now we finally see a real logical failure rather than a wrapper issue. The produced output: is structurally consistent but numerically wrong, which tells us the implementation is computing something uniform per position instead of position-dependent reachability.

codeforcescompetitive-programmingcombinatoricsflowsgraph-matchingsgreedy
CF 1773C - Cactus Meets Torus

We are given a grid of integers with n rows and m columns. Each row represents a cactus, and each column represents a torus.

codeforcescompetitive-programming
CF 1774H - Maximum Permutation

We are given a deck of cards numbered from 1 to $n$, and we are asked to construct a permutation of these numbers such that a certain value is maximized. The value of a permutation is defined as the minimum sum of any contiguous subarray of length $k$.

codeforcescompetitive-programmingconstructive-algorithms
CF 1774F1 - Magician and Pigs (Easy Version)

We are given a sequence of operations that act on a set of pigs. Each pig has a Health Point value. The operations can either create a new pig with a certain health, reduce the health of all existing pigs by a fixed amount, or repeat all previous operations.

codeforcescompetitive-programmingbrute-forcedata-structuresimplementation
CF 1774F2 - Magician and Pigs (Hard Version)

We are given a sequence of operations a magician performs. The magician has pigs, each with a certain Health Point (HP). The operations can create pigs, reduce the HP of all pigs, or repeat all previous operations.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresimplementation
CF 1774G - Segment Covering

We are given a collection of intervals on a huge number line and many queries, each asking about a fixed target interval $[l, r]$.

codeforcescompetitive-programmingbrute-forcecombinatoricsconstructive-algorithmsdata-structuresdptrees
CF 1774C - Ice and Fire

We have a tournament with players numbered from 1 to $n$, where each player has a "temperature" equal to their number. Battles happen in environments labeled 0 or 1. In environment 0, the lower-temperature player wins, and in environment 1, the higher-temperature player wins.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedy
CF 1774E - Two Chess Pieces

We have a rooted tree with root at node 1. Two chess pieces start at the root. Piece A must visit every node from a given set A, piece B must visit every node from another set B. The order is arbitrary. After all required visits are completed, both pieces must return to the root.

codeforcescompetitive-programmingdfs-and-similardpgreedytrees
CF 1774D - Same Count One

We have n binary rows, each of length m. A single operation chooses two rows and one column, then swaps the values in that column between those two rows. Because the swap happens inside the same column, the total number of 1s in the whole matrix never changes.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedyimplementationtwo-pointers