#bitmasks
CF 1305G - Kuroni and Antihype
CF 1305G - Kuroni and Antihype Rating: 3500 Tags: bitmasks, brute force, dp, dsu, graphs Solve time: 3m 16s Verified: no Solution Problem Understanding We are given a group of people, each with an associated integer value that can be interpreted as a bitmask. These people can form a network by joining a system where actions produce profit: once someone has joined, they can “invite” a person who has not...
CF 960C - Subsequence Counting Rating: 1700 Tags: bitmasks, constructive algorithms, greedy, implementation Model: gpt-5-3-mini Solve time: 4m 22s Verified: no (0/1 samples) Share: https://chatgpt.com/share/6a33a069-6ac8-83ec-b946-bc1675dc98b7 Solution Problem Understanding We are given two numbers: a target count of subsequences and a threshold value. We must construct an integer array such that when we look at all its non-empty subsequences and keep only those subsequences whose maximum minus minimum is strictly less...
CF 1017D - The Wu
CF 1017D - The Wu Rating: 1900 Tags: bitmasks, brute force, data structures Solve time: 1m 36s Verified: yes Solution Problem Understanding We are given a collection of binary strings, all of the same fixed length $n \le 12$. Each string in this collection appears with multiplicity, so duplicates matter. Alongside this, every position $i$ has a non-negative weight $w_i$. When comparing two binary strings $s$ and $t$, we only...
CF 1725F - Field Photography
CF 1725F - Field Photography Rating: 2100 Tags: bitmasks, data structures, sortings Solve time: 2m 55s Verified: no Solution Problem Understanding Each row initially contains a contiguous block of contestants placed on an extremely large integer line of columns. Row $i$ occupies every position from $L_i$ to $R_i$, so geometrically each row is just a closed interval. We are allowed to shift an entire row left or right by any...
CF 1302F - Keep talking and nobody explodes -- easy
CF 1302F - Keep talking and nobody explodes -- easy Rating: - Tags: bitmasks, brute force, expression parsing Solve time: 6m 46s Verified: no Solution Problem Understanding We are given a 5-digit lock state. Each digit behaves like a circular counter from 0 to 9, so increasing a digit by 1 means moving to the next digit and wrapping 9 back to 0. The process consists of a fixed sequence...
CF 1209E2 - Rotate Columns (hard version)
CF 1209E2 - Rotate Columns (hard version) Rating: 2500 Tags: bitmasks, dp, greedy, sortings Solve time: 4m 14s Verified: no Solution Problem Understanding We are given a grid with a small number of rows and a potentially large number of columns. The only operation allowed is to take any single column and rotate it cyclically any number of times. After performing these rotations independently for each column, we look at...
CF 1208F - Bits And Pieces
CF 1208F - Bits And Pieces Rating: 2600 Tags: bitmasks, dfs and similar, dp, greedy Solve time: 2m 39s Verified: yes Solution Problem Understanding We are given a sequence of integers and asked to choose three indices $i < j < k$. For each such triple, we take the value of the first element OR the bitwise AND of the other two elements. The goal is to maximize this expression...
CF 914G - Sum the Fibonacci
CF 914G - Sum the Fibonacci Rating: 2600 Tags: bitmasks, divide and conquer, dp, fft, math Solve time: 5m 10s Verified: no Solution Problem Understanding We are given a sequence of integers, each of which can be thought of as a 17-bit mask. From this array we must form ordered selections of five positions. Each selection contributes a value computed from bitwise combinations of the chosen elements, followed by evaluating...
CF 914E - Palindromes in a Tree
CF 914E - Palindromes in a Tree Rating: 2400 Tags: bitmasks, data structures, divide and conquer, trees Solve time: 4m 42s Verified: no Solution Problem Understanding We are given a tree where each node carries a lowercase character from a limited alphabet of size 20. The task is to examine every simple path in the tree and determine whether the multiset of characters along that path can be rearranged into...
CF 1261F - Xor-Set
CF 1261F - Xor-Set Rating: 3100 Tags: bitmasks, divide and conquer, math Solve time: 6m 41s Verified: no Solution Problem Understanding We are given two very large sets of integers, but they are not listed explicitly. Instead, each set is described as a union of intervals. Every integer inside an interval belongs to the set, and different intervals may overlap, so the same number can appear multiple times in the...
CF 1600J - Robot Factory
CF 1600J - Robot Factory Rating: 1400 Tags: bitmasks, dfs and similar Solve time: 1m 44s Verified: yes Solution Problem Understanding The grid describes a rectangular factory floor where each cell is a tile that may have walls on some of its four sides. Each tile contains a number from 0 to 15, and this number encodes its walls using four bits. Interpreting the binary representation from most significant to...
CF 1726B - Mainak and Interesting Sequence
CF 1726B - Mainak and Interesting Sequence Rating: 1100 Tags: bitmasks, constructive algorithms, math Solve time: 4m 46s Verified: no Solution Problem Understanding We are asked to construct a sequence of positive integers of length $n$ whose sum is fixed to $m$, but with an additional constraint that comes from a peculiar XOR condition applied to value ordering rather than positions. For every value $x$ appearing in the sequence, if...
CF 1725D - Deducing Sortability
CF 1725D - Deducing Sortability Rating: 2900 Tags: binary search, bitmasks, math Solve time: 4m 6s Verified: no Solution Problem Understanding We are asked to construct a very large hidden array indexed from 1 to N, where N can be up to one billion, without explicitly building it. This array is special because it is chosen so that it can be transformed, through a particular operation applied independently on elements,...
CF 1654F - Minimal String Xoration
CF 1654F - Minimal String Xoration Rating: 2800 Tags: bitmasks, data structures, divide and conquer, greedy, hashing, sortings, strings Solve time: 2m 42s Verified: yes Solution Problem Understanding We are given a string whose length is a power of two, indexed from 0 to $2^n - 1$. The key operation allowed is a global reindexing of the string using bitwise XOR with a fixed mask $j$. In other words, we...
CF 1556G - Gates to Another World
CF 1556G - Gates to Another World Rating: 3300 Tags: bitmasks, data structures, dsu, two pointers Solve time: 4m 44s Verified: no Solution Problem Understanding We are working on a graph whose vertices are all integers from $0$ to $2^n - 1$. Each vertex represents an $n$-bit binary string, and there is an undirected edge between two vertices if their binary representations differ in exactly one bit. This is the...
CF 1556D - Take a Guess
CF 1556D - Take a Guess Rating: 1800 Tags: bitmasks, constructive algorithms, interactive, math Solve time: 9m 7s Verified: no Solution Problem Understanding We are given a hidden array of integers, and we cannot access its elements directly. The only way to learn anything about the array is by asking queries on pairs of indices. Each query returns either the bitwise AND or bitwise OR of two elements. Using only...
CF 1556F - Sports Betting
CF 1556F - Sports Betting Rating: 2500 Tags: bitmasks, combinatorics, dp, graphs, math, probabilities Solve time: 5m 15s Verified: yes Solution Problem Understanding We are given a complete tournament where every pair of teams plays exactly one match. The result of each match is random, but biased: team $i$ beats team $j$ with probability proportional to its strength, specifically $\frac{a_i}{a_i + a_j}$. Each match outcome is independent. From all match...
CF 1322B - Present Rating: 2100 Tags: binary search, bitmasks, constructive algorithms, data structures, math, sortings Model: gpt-5-3-mini Solve time: 1m 28s Verified: yes (1/1 samples) Share: https://chatgpt.com/share/6a2deae4-fc9c-83ec-aeba-66f8cbbf4563 Solution Problem Understanding We are given an array of integers, and we consider every unordered pair of distinct elements. For each pair, we compute their sum. After collecting all these pairwise sums, instead of summing or minimizing them, we combine them using...
CF 1322D - Reality Show Rating: 2800 Tags: bitmasks, dp Model: gpt-5-3-mini Solve time: 3m 5s Verified: no (0/1 samples) Share: https://chatgpt.com/share/6a2deb92-56ac-83ec-ba70-95f7be671fa1 Solution Problem Understanding We are given a sequence of candidates that arrive in a fixed order. Each candidate has an initial aggressiveness level and a cost to recruit them. We may choose some of them, but with a constraint tied to the maximum aggressiveness we have already accepted:...
CF 906C - Party
CF 906C - Party Rating: 2400 Tags: bitmasks, brute force, dp, graphs Solve time: 7m 24s Verified: yes Solution Problem Understanding We have a connected friendship graph. Choosing a vertex means that all of its neighbors become pairwise adjacent. In graph theory language, we are allowed to pick a vertex and turn its open neighborhood into a clique. The process continues until the whole graph becomes a complete graph. We...
CF 914F - Substrings in a String
CF 914F - Substrings in a String Rating: 3000 Tags: bitmasks, brute force, data structures, string suffix structures, strings Solve time: 2m 54s Verified: yes Solution Problem Understanding We are given a mutable string and a sequence of queries. Each query either changes a character at a specific position or asks how many times a smaller string appears as a substring within a specific substring of the main string. The...
CF 1209E1 - Rotate Columns (easy version)
CF 1209E1 - Rotate Columns (easy version) Rating: 2000 Tags: bitmasks, brute force, dp, greedy, sortings Solve time: 1m 58s Verified: yes Solution Problem Understanding We are given a matrix with n rows and m columns, where each entry is a positive integer. We can pick any column and rotate it cyclically any number of times. After performing such rotations, we consider each row and take the maximum value in...
CF 1214G - Feeling Good
CF 1214G - Feeling Good Rating: 3200 Tags: bitmasks, data structures Solve time: 1m 36s Verified: yes Solution Problem Understanding We are given a two-dimensional grid representing a chameleon's body. Initially, all cells are green. Each cell can be either green or blue, and the color may be flipped multiple times. Each flip affects a contiguous horizontal segment of a single row. After every flip, we must determine whether the...
CF 1386C - Joker
CF 1386C - Joker Rating: 2800 Tags: *special, bitmasks, data structures, divide and conquer, dsu Solve time: 2m 24s Verified: no Solution Solution Let $N = pq$ where $p \equiv 3 \pmod 8$ and $q \equiv 7 \pmod 8$. We first prove the claimed identity involving the Jacobi symbol. Recall that the Jacobi symbol is multiplicative and satisfies $$\left(\frac{a}{N}\right) = \left(\frac{a}{p}\right) \left(\frac{a}{q}\right)$$ for any integer $a$. We compute $\left(\frac{-1}{N}\right)$ and...
CF 1500C - Matrix Sorting
CF 1500C - Matrix Sorting Rating: 2600 Tags: bitmasks, brute force, constructive algorithms, greedy, two pointers Solve time: 2m 46s Verified: no Solution Problem Understanding We are given two matrices, $A$ and $B$, of size $n \times m$. Each matrix consists of integers between $1$ and $n$. The task is to determine whether we can transform matrix $A$ into matrix $B$ using a sequence of stable column sorts. A stable...
CF 1523F - Favorite Game
CF 1523F - Favorite Game Rating: 3300 Tags: bitmasks, dp Solve time: 2m 24s Verified: no Solution Problem Understanding We are asked to maximize the number of quests William can complete in a 2D grid game with two interacting mechanics: movement and fast travel towers. The game world is infinite in size, but William’s movement is constrained to orthogonal moves-up, down, left, or right-by one unit per turn. He can...
CF 1523D - Love-Hate
CF 1523D - Love-Hate Rating: 2400 Tags: bitmasks, brute force, dp, probabilities Solve time: 2m 6s Verified: yes Solution Problem Understanding We are given a set of n friends, each with their own preferences over m currencies. Each friend likes at most p currencies, so the like-lists are sparse. The goal is to find the largest set of currencies such that at least half of the friends like all the...
CF 1530F - Bingo
CF 1530F - Bingo Rating: 2600 Tags: bitmasks, combinatorics, dp, math, probabilities Solve time: 2m 2s Verified: no Solution Problem Understanding We are asked to compute the probability that a square table of events is "winning." Each cell of an $n \times n$ table contains an event that may happen with a given probability. Rows, columns, the main diagonal, and the antidiagonal are considered lines. A table is winning if...
CF 1553H - XOR and Distance
CF 1553H - XOR and Distance Rating: 2900 Tags: bitmasks, divide and conquer, trees Solve time: 2m 49s Verified: yes Solution Problem Understanding We have a set of distinct integers $a_1,\dots,a_n$, each lying in the range $[0,2^k)$. For every mask $x$, we XOR every array element with $x$, producing the set $${a_1\oplus x,\dots,a_n\oplus x}.$$ Among all pairs in that transformed set, we want the smallest absolute difference. Let that value...
CF 1553C - Penalty
CF 1553C - Penalty Rating: 1200 Tags: bitmasks, brute force, dp, greedy Solve time: 2m 51s Verified: yes Solution Problem Understanding We are simulating a penalty shootout between two football teams, each taking alternating kicks up to five each, for a total of ten kicks. Each kick either succeeds (scores a goal), fails, or is unknown. The input gives a string of ten characters representing these outcomes: '1' for a...
CF 1599J - Bob's Beautiful Array
CF 1599J - Bob's Beautiful Array Rating: 2600 Tags: bitmasks, brute force, greedy Solve time: 1m 37s Verified: yes Solution Problem Understanding We are given an array $B$ that is claimed to be the result of a strange process applied to some unknown original array $A$. The process works by repeatedly picking two positions in $A$ (they are allowed to repeat across steps, and the same index can be reused...
CF 1609E - William The Oblivious
CF 1609E - William The Oblivious Rating: 2400 Tags: bitmasks, data structures, dp, matrices Solve time: 1m 55s Verified: no Solution Problem Understanding We are working with a mutable string consisting only of the characters a , b , and c . After each update, we must answer a structural question about the string: how many positions must be changed so that the string no longer contains abc as a...
CF 1765A - Access Levels
CF 1765A - Access Levels Rating: 2400 Tags: bitmasks, dsu, flows, graph matchings Solve time: 2m 29s Verified: no Solution Problem Understanding 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. We are allowed to compress this binary matrix into...
CF 1773G - Game of Questions
CF 1773G - Game of Questions Rating: 2800 Tags: bitmasks, combinatorics, dp, fft, math, probabilities Solve time: 4m 17s Verified: yes Solution Problem Understanding 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. As the sequence runs,...
CF 1856E2 - PermuTree (hard version)
CF 1856E2 - PermuTree (hard version) Rating: 2700 Tags: bitmasks, dfs and similar, dp, fft, greedy, implementation, math, trees Solve time: 2m 52s Verified: no Solution I have analyzed the issue carefully. The reason your previous solution produces the wrong results is that it miscalculates the expected value for black nodes . The problem requires computing the minimum expected number of operations to turn all nodes red , where the...
CF 1906B - Button Pressing
CF 1906B - Button Pressing Rating: 2600 Tags: bitmasks, constructive algorithms, hashing Solve time: 1m 46s Verified: no Solution Problem Understanding We have a line of lamps, each either on or off, and a line of buttons, one per lamp. Each button affects only the lamps immediately adjacent to it: pressing button $i$ toggles lamps $i-1$ and $i+1$, if they exist. The twist is that a button can only be...
CF 1912K - Kim's Quest
CF 1912K - Kim's Quest Rating: 1800 Tags: bitmasks, combinatorics, dp Solve time: 1m 31s Verified: yes Solution Problem Understanding We are given a sequence of integers, and we need to count how many of its subsequences satisfy a very specific structural constraint. A subsequence is formed by selecting some indices in increasing order, keeping the original order of values but possibly skipping elements. The constraint is applied locally: if...
CF 1970G3 - Min-Fund Prison (Hard)
CF 1970G3 - Min-Fund Prison (Hard) Rating: 2400 Tags: bitmasks, dfs and similar, dp, graphs, trees Solve time: 2m 4s Verified: no Solution Problem Understanding We are given an undirected graph representing a prison, where vertices are cells and edges are existing corridors. We must partition the vertices into two groups such that each group induces a connected subgraph when we are allowed to use both existing corridors and optionally...
CF 2002G - Lattice Optimizing
CF 2002G - Lattice Optimizing Rating: 3400 Tags: bitmasks, brute force, hashing, meet-in-the-middle Solve time: 39s Verified: no Solution Exploration The problem asks only for existence or nonexistence in three classes. For part (1), it suffices to exhibit a tetrahedron that tiles space by congruent copies. For part (2), we must decide whether a congruent tiling by equifacial tetrahedra exists. An equifacial tetrahedron is a disphenoid, that is, a tetrahedron...
CF 2038D - Divide OR Conquer
CF 2038D - Divide OR Conquer Rating: 2400 Tags: binary search, bitmasks, data structures, dp, implementation Solve time: 1m 41s Verified: yes Solution Problem Understanding We are given an array of integers and asked to count the number of ways to partition it into contiguous subarrays such that the bitwise OR of each subarray is non-decreasing from left to right. Each element must belong to exactly one subarray. The output...
CF 2041C - Cube
CF 2041C - Cube Rating: 2000 Tags: bitmasks, dfs and similar, dp Solve time: 1m 16s Verified: yes Solution Problem Understanding We are given a cube of size $n \times n \times n$, where every cell contains a weight. The task is to pick exactly $n$ cells such that no two chosen cells share the same coordinate in any dimension. In other words, if we think of a chosen set...
CF 2045J - Xorderable Array
CF 2045J - Xorderable Array Rating: 2600 Tags: bitmasks, data structures Solve time: 1m 9s Verified: yes Solution Problem Understanding We are given an array of values $A$, and another array $X$. The task is not to modify $A$ directly, but to ask a very specific question about pairs of values from $X$. For any ordered pair $(p, q)$, we are allowed to rearrange the array $A$. After rearrangement, we...
CF 2061E - Kevin and And
CF 2061E - Kevin and And Rating: 2000 Tags: bitmasks, brute force, dp, greedy, math, sortings Solve time: 1m 42s Verified: yes Solution Problem Understanding We are given a list of integers a of length n and a list of magic integers b of length m . Kevin can choose up to k operations where each operation selects an element a_i and a magic b_j and replaces a_i with a_i...
CF 2061D - Kevin and Numbers
CF 2061D - Kevin and Numbers Rating: 1600 Tags: bitmasks, data structures Solve time: 1m 38s Verified: no Solution Problem Understanding We are given two sequences of integers: the initial sequence a of length n and the target sequence b of length m . Kevin can repeatedly take any two numbers from a whose difference is at most one, remove them, and insert their sum back into the sequence. The...
CF 2215D - EXPloration, EXPloitation, and Gain Some EXPerience!
CF 2215D - EXPloration, EXPloitation, and Gain Some EXPerience! Rating: 2800 Tags: bitmasks, brute force, dp, greedy, implementation Solve time: 1m 44s Verified: no Solution Problem Understanding We are given a line of positions from 1 to $n$. Two tokens start at positions 1 and 2, and these two starting positions are already considered “taken” from the very beginning. Each token belongs to one player: Shiro controls position 1 and...
CF 2215C - Oriented Journey
CF 2215C - Oriented Journey Rating: 2200 Tags: bitmasks, brute force, communication, constructive algorithms, graphs, interactive, trees Solve time: 1m 54s Verified: no Solution Problem Understanding We are dealing with a two-phase communication system built around a tree. First, an agent receives an undirected tree one edge at a time and must immediately orient each edge. After all edges are oriented, a second agent receives only the resulting directed tree...
CF 2222E - Seek the Truth
CF 2222E - Seek the Truth Rating: - Tags: binary search, bitmasks, constructive algorithms, interactive Solve time: 1m 57s Verified: no Solution Problem Understanding We are interacting with a hidden transformation on integers in the range from 0 to $2^n - 1$. Behind the scenes there is a fixed bitmask $c$ and a hidden operation type $k \in {1,2,3}$. Every time we insert a number $x$, the judge does not...
CF 241B - Friends
CF 241B - Friends Rating: 2700 Tags: binary search, bitmasks, data structures, math Solve time: 2m 23s Verified: no Solution Problem Understanding We have an array of friend attractiveness values. Every unordered pair of distinct friends produces one possible picture, and the value of that picture is the xor of the two attractiveness values. Among all possible pairs, we want to choose exactly m distinct pairs whose xor values have...