brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 906B - Seating of Students

We are asked to rearrange students in a classroom so that no two students who were neighbors in the original seating remain neighbors in the new arrangement. The classroom is an n×m grid, and the students are numbered sequentially from 1 to n·m in row-major order.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsmath
CF 906A - Shockers

Valentin is playing a game where a single unknown letter has been chosen, and every time he pronounces a word containing that letter, he gets shocked. He can also make guesses about the letter, and incorrect guesses result in shocks.

codeforcescompetitive-programmingimplementationstrings
CF 903G - Yet Another Maxflow Problem

The graph consists of two directed chains. Vertices $A1,dots,An$ form one chain and $B1,dots,Bn$ form another. Capacities on the $B$-chain are fixed. Capacities on the $A$-chain are updated online.

codeforcescompetitive-programmingdata-structuresflowsgraphs
CF 903F - Clear The Matrix

We are given a 4-row by n-column matrix filled with either asterisks or dots. The asterisks represent tiles that must be cleared. The allowed operation is selecting a square submatrix of size 1×1 up to 4×4 and replacing every asterisk inside it with dots.

codeforcescompetitive-programmingbitmasksdp
CF 903B - The Modcrab

Vova is fighting a monster called the Modcrab. He has a set amount of health, an attack value, and an unlimited supply of healing potions. Each potion restores a fixed number of health points, and crucially, the potion heals more than the Modcrab can deal in a single attack.

codeforcescompetitive-programminggreedyimplementation
CF 903D - Almost Difference

We are given an array of up to 200000 integers. For every pair of positions $(i,j)$ with $ile j$, we evaluate a special function $d(ai,aj)$, and we need the sum over all pairs. The function behaves differently from a normal difference.

codeforcescompetitive-programmingdata-structuresmath
CF 903E - Swapping Characters

We are given $k$ strings of the same length $n$. Each of them was produced from a single unknown original string by performing exactly one swap of two different positions. The swapped characters are allowed to be equal, so a string may remain unchanged after the operation.

codeforcescompetitive-programmingbrute-forcehashingimplementationstrings
CF 903C - Boxes Packing

We are given n cubic boxes, each with a side length specified by an array a. Mishka wants to nest these boxes inside each other according to strict rules: a box can go into another box only if it is strictly smaller and the larger box does not already contain another box.

codeforcescompetitive-programminggreedy
CF 903A - Hungry Student Problem

The task asks whether Ivan can buy exactly x chicken chunks using only small portions of 3 chunks and large portions of 7 chunks.

codeforcescompetitive-programminggreedyimplementation
CF 902B - Coloring a Tree

We are given a rooted tree with n vertices, where vertex 1 is the root. Each vertex must be colored with a target color specified in the input. Initially, all vertices are color 0.

codeforcescompetitive-programmingdfs-and-similardsugreedy
CF 908H - New Year and Boolean Bridges

We are given an unknown directed graph with n nodes. For each pair of nodes u and v, we are told a Boolean condition that involves reachability in the graph: either the AND, OR, or XOR of whether u can reach v and whether v can reach u is true.

codeforcescompetitive-programming
CF 908A - New Year and Counting Cards

We see one side of every card. A visible side can be either a lowercase letter or a digit. The statement we want to verify is: "Whenever a card has a vowel on one side, the other side contains an even digit." We may flip some cards.

codeforcescompetitive-programmingbrute-forceimplementation
CF 909C - Python Indentation

We are given a sequence of program statements. Each statement is either: f , a for statement whose body must contain at least one statement at one indentation level deeper. s , a simple statement that occupies exactly one line and does not create a new block.

codeforcescompetitive-programmingdp
CF 910C - Minimum Sum

We are given several strings made from the letters 'a' through 'j'. Originally, these strings were decimal numbers. A prankster replaced every digit with a unique letter, creating a one-to-one correspondence between the ten digits 0...9 and the ten letters a...j.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 911A - Nearest Minimums

We are given an array of integers. Among all values in the array, there is a smallest value, and the problem guarantees that this minimum value appears at least twice. Our task is to find the smallest distance between any two occurrences of that minimum value.

codeforcescompetitive-programmingimplementation
CF 913B - Christmas Spruce

We are given a rooted tree with vertices numbered from 1 to n. Vertex 1 is always the root. For every other vertex, the input tells us its parent, which completely defines the tree structure. A vertex is considered a leaf if it has no children and is not the root.

codeforcescompetitive-programmingimplementationtrees
CF 914F - Substrings in a String

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.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresstring-suffix-structuresstrings
CF 914B - Conan and Agasa play a Card Game

We have a game where Conan and Agasa take turns removing cards from a pile. Each card has a positive integer written on it. When a player chooses a card, not only does that card get removed, but all cards with strictly smaller numbers are removed as well.

codeforcescompetitive-programminggamesgreedyimplementation
CF 915C - Permute Digits

We are given two integers, a and b. Our task is to rearrange the digits of a to produce the largest possible number that does not exceed b. The resulting number must use all digits of a exactly once and cannot have leading zeros.

codeforcescompetitive-programmingdpgreedy
CF 916B - Jamie and Binary Sequence (changed after round)

We want to represent a positive integer n as a sum of exactly k powers of two: $$n = 2^{a1} + 2^{a2} + cdots + 2^{ak}$$ The exponents may be positive, zero, or even negative. Among all valid sequences of length k, we first minimize the largest exponent that appears.

codeforcescompetitive-programmingbitmasksgreedymath
CF 917A - The Monster

We are given a string consisting of three possible characters: '(', ')', and '?'. For every substring, we ask whether it can be turned into a non-empty correct bracket sequence by replacing each '?' independently with either '(' or ')'. Such a substring is called pretty.

codeforcescompetitive-programmingdpgreedyimplementationmath
CF 918A - Eleven

We are asked to generate a string of length n consisting only of the letter 'O' in uppercase and lowercase, following a rule based on the Fibonacci sequence. The positions in the string that correspond to Fibonacci numbers (1, 2, 3, 5, 8, ...

codeforcescompetitive-programmingbrute-forceimplementation
CF 919B - Perfect Number

A positive integer is called perfect when the sum of all of its decimal digits is exactly 10. We are given an integer k, and we must output the k-th smallest positive integer whose digit sum equals 10. The ordering is the usual numerical ordering.

codeforcescompetitive-programmingbinary-searchbrute-forcedpimplementationnumber-theory
CF 920A - Water The Garden

We are given a linear garden with n consecutive beds and a subset of these beds containing water taps. Each tap, once turned on, waters the bed it occupies immediately, and in each subsequent second it extends its coverage by one bed in both directions.

codeforcescompetitive-programmingimplementation
CF 1089F - Fractions

We are given an integer $n$, and we want to represent a fixed rational number, specifically $1 - frac{1}{n}$, as a sum of several smaller fractions. Each fraction must have a denominator that is a proper divisor of $n$, meaning it divides $n$ but is neither 1 nor $n$.

codeforcescompetitive-programmingmath
CF 1089B - Bimatching

We are given two sets of vertices, each with n nodes, and m edges that connect vertices from the first set to vertices in the second. Each edge has an associated cost.

codeforcescompetitive-programminggraphs
CF 1091F - New Year and the Mallard Expedition

We are given a long one-dimensional route made of consecutive segments. Each segment has a length and a terrain type, either grass, water, or lava. Bob starts just before the first segment and wants to reach the far end after the last segment.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1091B - New Year and the Treasure Geolocation

We are given a set of obelisks on a 2D plane and a set of clues that indicate vectors from obelisks to a hidden treasure. Each obelisk has exactly one clue, but the mapping is scrambled, so we do not know which clue belongs to which obelisk.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedyimplementation
CF 1095F - Make It Connected

We are given n vertices, each with a number ai written on it, and no edges initially. We can connect any two vertices by paying the sum of their numbers ax + ay. Additionally, there are m special offers, each allowing a particular edge to be added at a discounted cost w.

codeforcescompetitive-programmingdsugraphsgreedy
CF 1095B - Array Stabilization

We are given a list of numbers representing an array, and we are allowed to remove exactly one element. After removing it, we look at how “spread out” the remaining numbers are, defined as the difference between the largest and smallest remaining value.

codeforcescompetitive-programmingimplementation
CF 1097F - Alex and a TV Show

We are asked to simulate operations on a set of multisets, each initially empty. The operations are either assigning a single value to a multiset, combining two multisets via union, combining two multisets via a multiset product using greatest common divisors, or querying the…

codeforcescompetitive-programmingbitmaskscombinatoricsnumber-theory
CF 1097A - Gennady and a Card Game

The game Gennady plays involves matching cards either by rank or suit. In practical terms, you are given a single card on the table and a hand of five cards.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1099B - Squares and Segments

We are asked to think about building a figure composed of unit squares drawn on a grid, where every square is outlined by horizontal and vertical unit segments. Each segment can be either horizontal or vertical, and every segment has length exactly one.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsmath
CF 1100C - NN and the Optical Illusion

We are building a very specific circle configuration. There is one central circle of radius $r$. Around it, $n$ identical circles are placed so that they form a ring.

codeforcescompetitive-programmingbinary-searchgeometrymath
CF 1101F - Trucks and Cities

We have a sequence of cities arranged along a single road at increasing distances from the origin. Each truck travels from a starting city to a destination city along this road. The trucks consume fuel linearly with distance and start with a full tank.

codeforcescompetitive-programmingbinary-searchdp
CF 1101B - Accordion

We are given a string containing letters and a few special characters: [, ], :, and The constraints tell us that the string can be up to 500,000 characters long.

codeforcescompetitive-programminggreedyimplementation
CF 1102F - Elongated Matrix

We have a rectangular grid of numbers with $n$ rows and $m$ columns. We are allowed to reorder the rows however we like, but the order of numbers within each row is fixed.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcedpgraphs
CF 1102A - Integer Sequence Dividing

We are given the sequence of integers from 1 to $n$. The task is to divide this sequence into two disjoint sets $A$ and $B$ so that the absolute difference between their sums, $ Since $n$ can be as large as $2 cdot 10^9$, explicitly constructing the sequence or trying all…

codeforcescompetitive-programmingmath
CF 1105C - Ayoub and Lost Array

We are asked to count how many arrays of length $n$ can be formed such that every element lies within a fixed interval $[l, r]$, and the total sum of all elements is divisible by 3.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1106C - Lunar New Year and Number Division

We are given an even-length list of positive integers, and we must partition these numbers into groups. Each group must contain at least two elements, and every number must belong to exactly one group.

codeforcescompetitive-programminggreedyimplementationmathsortings
CF 1107C - Brutality

We are given a fixed sequence of hits, where each hit has a damage value and is associated with a specific button (a lowercase letter). We are allowed to delete any hits from the sequence while keeping the remaining ones in their original order.

codeforcescompetitive-programminggreedysortingstwo-pointers
CF 1107F - Vasya and Endless Credits

Vasya starts with zero burles and wants to buy a car. The bank offers n credit deals, each giving him an initial sum ai immediately and requiring monthly payments of bi for ki months. Vasya can take at most one credit per month, but multiple credits can overlap.

codeforcescompetitive-programmingdpflowsgraph-matchingsgraphssortings
CF 1107G - Vasya and Maximum Profit

Vasya wants to assemble a contest from a sequence of problems, each with a difficulty and a cost. He gains a fixed reward for including any problem, but he also pays two types of costs: the direct payment to each problem’s author and a “gap penalty” based on the largest…

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresdpdsu
CF 1107E - Vasya and Binary String

We are given a binary string that we are allowed to repeatedly compress until nothing remains. A single move consists of picking a contiguous block of identical characters, either all 0s or all 1s, removing that block from the string, and concatenating the remaining parts.

codeforcescompetitive-programmingdp
CF 1107D - Compression

We are given a square matrix of size $n times n$, but instead of being explicitly written as bits, each row is packed into hexadecimal characters. Each hex digit represents four binary cells, so the input is just a compact encoding of a binary matrix.

codeforcescompetitive-programmingdpimplementationmathnumber-theory
CF 1107A - Digits Sequence Dividing

We are given a string of digits, each between 1 and 9. The task is to split this string into at least two consecutive segments so that when we interpret each segment as an integer, the resulting sequence is strictly increasing.

codeforcescompetitive-programminggreedystrings
CF 1107B - Digital root

We are asked to answer multiple independent queries. Each query gives two numbers, a position $k$ and a digit $x$ between 1 and 9. For each query, we need to output the $k$-th positive integer whose digital root equals $x$.

codeforcescompetitive-programmingmathnumber-theory
CF 1108C - Nice Garland

We are given a line of lamps, each painted in one of three colors: R, G, or B. We are allowed to repaint any lamp to any other color.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1108F - MST Unification

We are given a connected undirected graph with n vertices and m edges, each with a positive weight. The goal is to adjust some edge weights by incrementing them, so that the graph's minimum spanning tree (MST) remains the same cost as initially but becomes unique.

codeforcescompetitive-programmingbinary-searchdsugraphsgreedy
CF 1108E2 - Array and Segments (Hard version)

We are given an array of integers and a collection of segments, each defined by a start and end index. Each segment can be applied at most once to decrease all values in that segment by one.

codeforcescompetitive-programmingdata-structuresimplementation
CF 1108E1 - Array and Segments (Easy version)

We are given an integer array and a collection of intervals over its indices. Each interval represents an operation: if we select it, every position inside that range is decreased by exactly one.

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 1108D - Diverse Garland

We are given a linear sequence of lamps, each painted either red, green, or blue. The task is to change as few of them as possible so that no two consecutive lamps have the same color.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedy
CF 1108A - Two distinct points

We are given two line segments on the number line, each defined by its endpoints. For each query, we need to pick one integer point from the first segment and one integer point from the second segment such that the points are different.

codeforcescompetitive-programmingimplementation
CF 1108B - Divisors of Two Integers

We are given a shuffled list of integers, each representing a divisor of one of two unknown positive integers, which we can call x and y. If a number divides both x and y, it appears twice in the list. Our task is to reconstruct any pair (x, y) that could have produced this list.

codeforcescompetitive-programmingbrute-forcegreedymathnumber-theory
CF 1109C - Sasha and a Patient Friend

The problem models a “patience bowl” which has an initial amount of patience that can grow or shrink over time depending on the tap’s speed. The tap’s speed can be changed at discrete times by events.

codeforcescompetitive-programmingbinary-searchdata-structuresimplementation
CF 1109F - Sasha and Algorithm of Silence's Sounds

We are given an $n times m$ grid where every cell contains a unique value from $1$ to $nm$. These values impose a global order on the cells, and we should think of the grid as being revealed gradually: first the cell with value 1 appears, then 2, and so on.

codeforcescompetitive-programmingdata-structurestrees
CF 1109D - Sasha and Interesting Fact from Graph Theory

We are asked to count how many different weighted trees can be built on $n$ labeled vertices when every edge weight is an integer between $1$ and $m$, under a single global constraint involving two distinguished vertices $a$ and $b$.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpmathtrees
CF 1109E - Sasha and a Very Easy Test

We are maintaining an array of integers that is repeatedly modified and queried. The array starts fixed, but over time we apply operations that either scale a contiguous segment, shrink a single element by dividing it, or ask for the sum over a segment.

codeforcescompetitive-programmingdata-structuresnumber-theory
CF 1109B - Sasha and One More Name

We are given a string that is already a palindrome, and our goal is to transform it into a different palindrome by cutting it into some number of contiguous pieces and then reordering these pieces. The task is to find the minimum number of cuts required to achieve this.

codeforcescompetitive-programmingconstructive-algorithmshashingstrings
CF 1109A - Sasha and a Bit of Relax

We are asked to find "funny pairs" in an array of integers. A pair of indices $(l, r)$ is funny if the subarray from $l$ to $r$ has even length and the XOR of the first half equals the XOR of the second half.

codeforcescompetitive-programmingdpimplementation
CF 1110H - Modest Substrings

We are asked to construct a digit string of fixed length n. Every substring of this string is interpreted as a number (ignoring leading zeros), and we get a score of 1 for a substring if that number lies in the inclusive interval [l, r].

codeforcescompetitive-programmingdpstrings
CF 1110A - Parity

The problem gives a number $n$ not in decimal form, but in some arbitrary base $b$. The digits of $n$ are listed from the most significant to the least significant, and the task is to decide whether $n$ is even or odd in decimal.

codeforcescompetitive-programmingmath
CF 1110G - Tree-Tac-Toe

We are asked to analyze a game of tic-tac-toe played on a tree. Each vertex is either uncolored or already white. Two players alternate coloring vertices, starting with white. The first player to complete a path of three vertices in their color wins.

codeforcescompetitive-programmingconstructive-algorithmsgamestrees
CF 1110F - Nearest Leaf

We are given a rooted tree where the parent of each node is fixed by input order: node i connects to some earlier node pi, forming a rooted structure at node 1.

codeforcescompetitive-programmingdata-structurestrees
CF 1110D - Jongmah

We are given a multiset of tiles, where each tile carries an integer value between 1 and m. The goal is to repeatedly pick disjoint groups of exactly three tiles and form as many such groups as possible.

codeforcescompetitive-programmingdp
CF 1110E - Magic Stones

We are given an array of integers representing charges on a line of stones. A single operation picks any interior position and replaces its value using its two neighbors: the new value becomes the sum of the left and right neighbors minus its old value.

codeforcescompetitive-programmingconstructive-algorithmsmathsortings
CF 1110B - Tape

We are given a sorted list of positions on a long line segment where damage has occurred. Each damaged position must be covered by tape, but the tape does not need to avoid healthy positions, it can freely cover anything in between.

codeforcescompetitive-programminggreedysortings
CF 1110C - Meaningless Operations

We are given a number $a$. For this number we are allowed to pick any $b$ such that $1 le b < a$. For each choice of $b$, we compute two values derived from bitwise operations: one is $a oplus b$, the other is $a & b$. We then take the gcd of these two results.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 1111A - Superhero Transformation

We are given two lowercase strings representing superhero names. A transformation is allowed if every vowel can be changed into any other vowel, and every consonant can be changed into any other consonant. The actual letters do not matter.

codeforcescompetitive-programmingimplementationstrings
CF 1111D - Destroy the Colony

We are given a row of holes, each containing exactly one villain, and each villain has a type represented by a character. The string representing the colony is of even length, so it can naturally be divided into two halves.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1111E - Tree

We are given a tree with n nodes and multiple queries. Each query provides a subset of k nodes, a maximum number of groups m, and a root r.

codeforcescompetitive-programmingdata-structuresdfs-and-similardpgraphstrees
CF 1111B - Average Superhero Gang Power

We are given a group of superheroes, each with an initial power value. We are allowed to modify this group using two types of operations: we can either remove a superhero from the group (as long as at least two remain), or we can increase the power of a chosen superhero by one.

codeforcescompetitive-programmingbrute-forceimplementationmath
CF 1111C - Creative Snap

We are given a linear base of length $2^n$, where some positions contain avengers. Thanos wants to destroy the entire base using minimum power.

codeforcescompetitive-programmingbinary-searchbrute-forcedivide-and-conquermath
CF 1113B - Sasha and Magnetic Machines

We are given an array of integers representing the power of n magnetic machines. Each machine contributes positively to the total power of the farm.

codeforcescompetitive-programminggreedynumber-theory
CF 1113A - Sasha and His Trip

Sasha wants to drive from city 1 to city n along a straight line of cities. Each city is exactly one kilometer apart, and all roads go forward, so he cannot move backward. His car consumes one liter of fuel per kilometer and starts with an empty tank.

codeforcescompetitive-programmingdpgreedymath
CF 1114A - Got Any Grapes?

We have three people with different grape preferences and three piles of grapes. Andrew wants exactly the first type of grape, green grapes. If he needs x grapes, all of them must come from the green pile. Dmitry dislikes black grapes. He can eat green or purple grapes.

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 1114F - Please, another Queries on Array?

We have an array of integers, each between 1 and 300, and we need to process two types of queries. The first query multiplies a contiguous segment of the array by a given number.

codeforcescompetitive-programmingbitmasksdata-structuresdivide-and-conquermathnumber-theory
CF 1114E - Arithmetic Progression

We are given a hidden array of size $n$, but the array is not directly accessible and is permuted arbitrarily. The only structural guarantee is that if we sort its elements, they form a perfect arithmetic progression with a strictly positive common difference.

codeforcescompetitive-programmingbinary-searchinteractivenumber-theoryprobabilities
CF 1114D - Flood Fill

We are given a row of n colored squares, each labeled with an integer representing its color. The goal is to recolor the entire row into a single color using a series of "flood fill" operations.

codeforcescompetitive-programmingdp
CF 1114B - Yet Another Array Partitioning Task

We are given a sequence of integers a of length n, and two parameters: m, the number of largest elements we consider when computing the "beauty" of a subarray, and k, the number of contiguous subarrays we must partition a into.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 1114C - Trailing Loves (or L'oeufs?)

We are asked to compute the number of trailing zeros in the factorial of a number when represented in an arbitrary base. More precisely, given integers $n$ and $b$, we want the number of digits equal to zero at the end of the base-$b$ representation of $n!$.

codeforcescompetitive-programmingbrute-forceimplementationmathnumber-theory
CF 1115U1 - Anti-diagonal unitary

We are asked to implement a quantum operation on an array of qubits. The operation must correspond to a unitary matrix whose only non-zero entries lie on the anti-diagonal. For a system of $N$ qubits, the state space has dimension $2^N$.

codeforcescompetitive-programming*special
CF 1115U3 - Block unitary

We are asked to implement a quantum unitary operation on $N$ qubits, where $N$ is small, between 2 and 5. The operation is represented by a $2^N times 2^N$ matrix with a specific block structure. The matrix can be visualized as four quarters: 1.

codeforcescompetitive-programming*special
CF 1115U2 - Chessboard unitary

We are asked to implement a unitary operation on $N$ qubits, where $2 le N le 5$. The operation is represented by a $2^N times 2^N$ matrix with a chessboard-like pattern of zeros and non-zero elements.

codeforcescompetitive-programming*special
CF 1115G2 - OR oracle

We are given a small quantum register of at most eight qubits that encode an input bitstring $x0, x1, dots, x{N-1}$, along with one extra qubit $y$ that acts as an output wire.

codeforcescompetitive-programming*special
CF 1115G3 - Palindrome checker oracle

We are asked to implement a quantum oracle acting on a small register of qubits. The oracle receives an input string encoded in quantum form, represented by an array of up to eight qubits, plus one additional qubit that serves as the output bit.

codeforcescompetitive-programming*special
CF 1115G1 - AND oracle

We are asked to implement a quantum operation that computes the logical AND of an array of qubits. Concretely, we have a set of $N$ qubits, each representing a binary value (0 or 1, though they can be in superposition), and a single output qubit.

codeforcescompetitive-programming*special
CF 1116D6 - Hessenberg matrix

We are asked to implement a quantum operation on a small number of qubits (2 to 4) such that the unitary matrix representing it has an upper Hessenberg form.

codeforcescompetitive-programming*special
CF 1116D5 - Creeper

We are given a very specific 8×8 pattern describing where a 3-qubit unitary matrix has non-negligible entries. The matrix is not arbitrary, it is extremely sparse and structured, and the task is to implement any quantum circuit on 3 qubits whose unitary matches this sparsity…

codeforcescompetitive-programming*special
CF 1116D4 - TIE fighter

We are asked to implement a quantum operation on an array of $N$ qubits, where $N$ ranges from 2 to 5. The core requirement is that the operation's unitary matrix has a very particular pattern: a central 2x2 submatrix filled with non-zero values, anti-diagonals in the top-left…

codeforcescompetitive-programming*special
CF 1116D3 - X-wing fighter

We are asked to implement a unitary operation on a quantum register consisting of $N$ qubits, where $2 le N le 5$. The unitary is represented as a $2^N times 2^N$ matrix, and it must have non-zero entries only on the main diagonal and the anti-diagonal.

codeforcescompetitive-programming*special
CF 1116D2 - Pattern of increasing blocks

We are asked to construct a quantum operation on $N$ qubits whose matrix, in the computational basis, has a very rigid block structure. The full unitary is a $2^N times 2^N$ matrix, and we are not required to compute or print it explicitly.

codeforcescompetitive-programming*special
CF 1116D1 - Block diagonal matrix

We are asked to implement a unitary operation on an array of $N$ qubits, where $2 le N le 5$, such that the matrix representing the operation has a very specific block-diagonal structure.

codeforcescompetitive-programming*special
CF 1116C3 - ``Is the number of ones divisible by 3?'' oracle

We are given a small register of qubits that encode a bitstring and an additional single qubit that acts as an output accumulator.

codeforcescompetitive-programming*special
CF 1116C2 - ``Is the bit string periodic?'' oracle

We are asked to implement a quantum oracle that checks whether a given bit string is periodic. In practical terms, imagine we have an array of $N$ qubits, each representing a bit, and a separate output qubit.

codeforcescompetitive-programming*special
CF 1116B2 - Not A, not B or not C?

We are asked to work with a single qubit that is guaranteed to be in one of three specific quantum states: $ Our goal is not to identify which state the qubit is in, but to return a number corresponding to a state we are sure the qubit is not in.

codeforcescompetitive-programming*special
CF 1116C1 - Alternating bits oracle

We are asked to implement a "quantum oracle" that checks whether a binary vector alternates. That means for an input array of bits x[0..N-1], we need to determine if no two consecutive bits are the same.

codeforcescompetitive-programming*special
CF 1116B1 - Distinguish three-qubit states

We are given three qubits in one of two specific entangled states, each a superposition of three computational basis states with complex coefficients derived from the cube roots of unity. The two states differ only in the phase factors applied to the second and third qubits.

codeforcescompetitive-programming*special
CF 1117A - Best Subsegment

We are given an array of integers and may choose any contiguous subarray. For every chosen subarray, we can compute its arithmetic mean, which is the sum of its elements divided by its length. The task is to find the maximum possible mean among all subarrays.

codeforcescompetitive-programmingimplementationmath
CF 1117F - Crisp String

We are given a string consisting of the first p letters of the lowercase English alphabet, and a symmetric adjacency matrix A that specifies which letters can appear next to each other. A string is crisp if every consecutive pair of letters in it is allowed by this matrix.

codeforcescompetitive-programmingbitmasksdp