brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1658B - Marin and Anti-coprime Permutation

We are asked to count permutations of length $n$ where the greatest common divisor of the sequence $1 cdot p1, 2 cdot p2, dots, n cdot pn$ is strictly greater than 1. Here $p$ is a permutation of integers from 1 to $n$.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 1658A - Marin and Photoshoot

We are given a line of cosplayers represented as a binary string. Each 0 is a male and each 1 is a female. The goal is to ensure that the line is "beautiful," meaning that in every contiguous segment of at least two cosplayers, the number of males does not exceed the number of…

codeforcescompetitive-programmingconstructive-algorithmsimplementationmath
CF 1659D - Reverse Sort Sum

We start with an unknown binary array $A$. For every prefix length $k$, we sort the first $k$ elements of $A$, leaving the rest unchanged. This produces $n$ arrays $B1, B2, dots, Bn$. Instead of seeing those arrays directly, we are given their column-wise sum $C$.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyimplementationmathtwo-pointers
CF 1659F - Tree and Permutation Game

We are given a tree where every vertex hosts a position in a permutation. Separately, there is a token sitting on one vertex. The game evolves in alternating moves between Alice and Bob. Alice’s move does not change the tree.

codeforcescompetitive-programmingdfs-and-similargamesgraphstrees
CF 1659B - Bit Flipping

We start with a binary string. We must perform exactly (k) operations. In one operation we choose a position (i). The chosen bit stays unchanged, while every other bit in the string is flipped.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedystrings
CF 1659E - AND-MEX Walk

We are given an undirected, connected graph where each edge has a non-negative integer weight less than $2^{30}$. A query asks for the minimum possible "length" of a walk from vertex $u$ to vertex $v$.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsdfs-and-similardsugraphs
CF 1659C - Line Empire

We have a king starting at position zero on a number line, and there are several unconquered kingdoms at strictly increasing positions. The king wants to conquer all kingdoms at minimal cost.

codeforcescompetitive-programmingbinary-searchbrute-forcedpgreedyimplementationmath
CF 1659A - Red Versus Blue

We are asked to construct a sequence of match outcomes between two teams, Red and Blue, given the total number of matches, the number of wins for Red, and the number of wins for Blue.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 1660B - Vlad and Candies

Thank you for the clarification. Now we can carefully analyze the problem. The input/output mismatch shows that the previous solution produces RRRWW for the first test case, while the expected output is RWRRW.

codeforcescompetitive-programmingmath
CF 1660F2 - Promising String (hard version)

We are given a string consisting only of plus and minus signs. A substring of this string is considered promising if, through repeated replacement of two consecutive minuses with a single plus, the substring can be transformed into a balanced string, meaning it has an equal…

codeforcescompetitive-programmingdata-structuresimplementationmathstrings
CF 1660F1 - Promising String (easy version)

We are given a string consisting of '+' and '-'. For every non-empty substring, we must determine whether it is promising.

codeforcescompetitive-programmingbrute-forceimplementationmathstrings
CF 1660E - Matrix and Shifts

We are given a binary square matrix, and we are allowed to rearrange it using cyclic shifts of rows and columns. These shifts do not change values, they only rotate positions, so what ultimately matters is how we align the matrix before we start paying to flip bits.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedyimplementation
CF 1660A - Vasya and Coins

Vasya has two types of coins in his wallet: 1-burle coins and 2-burle coins. The problem asks for the smallest positive integer amount of money that he cannot pay exactly using the coins in his possession.

codeforcescompetitive-programminggreedymath
CF 1660D - Maximum Product Strikes Back

We are given an array of integers where each value is extremely small in magnitude, only from -2 to 2. From this array, we are allowed to delete a prefix and a suffix, leaving a contiguous middle segment. That remaining segment could even be empty.

codeforcescompetitive-programmingbrute-forceimplementationmathtwo-pointers
CF 1660C - Get an Even String

We are given a string and we are allowed to delete characters anywhere, not necessarily in a continuous segment. After deletions, we want the remaining characters to form a very rigid structure: the string must be split into consecutive pairs, and each pair must consist of two…

codeforcescompetitive-programmingdpgreedystrings
CF 1661F - Teleporters

We are given a sorted sequence of points on a number line: starting at position 0, followed by positions $a1, a2, dots, an$, where $an$ is the final destination. These positions act as teleportation stations.

codeforcescompetitive-programmingbinary-searchgreedy
CF 1661C - Water the Trees

We are given a set of trees, each with an initial height. Our goal is to make all trees reach the same final height using a daily watering process. On odd-numbered days, watering a tree increases its height by 1, while on even-numbered days, it increases by 2.

codeforcescompetitive-programmingbinary-searchgreedymath
CF 1661E - Narrow Components

We are given a grid with three rows and n columns, where each cell is either free or blocked. Conceptually, this is a narrow vertical slice of a 2D space, only three cells high, but potentially very wide.

codeforcescompetitive-programmingbrute-forcedata-structuresdpdsumathtrees
CF 1661D - Progressions Covering

We are given an array b of length n, where each element represents a target value we need to reach or exceed in a corresponding array a. Initially, a consists of all zeros.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1661A - Array Balancing

At every position i, we have a pair of values (a[i], b[i]). The only operation allowed is swapping the two values inside the same pair. We may do this independently for any positions. After choosing which pairs to swap, we obtain final arrays a and b.

codeforcescompetitive-programminggreedymath
CF 1661B - Getting Zero

We are given a list of integers, each less than 32768, and the goal is to reduce each number to zero using two operations: either increment the number by one modulo 32768 or double it modulo 32768. The input specifies the number of integers followed by the integers themselves.

codeforcescompetitive-programmingbitmasksbrute-forcedfs-and-similardpgraphsgreedyshortest-paths
CF 1662M - Bottle Arrangements

We must build a row of n wine bottles. Each bottle is either red (R) or white (W). Every critic wants to find some contiguous segment of bottles whose contents match a requested pair (r, w), where r is the number of red bottles and w is the number of white bottles in that…

codeforcescompetitive-programmingconstructive-algorithms
CF 1662O - Circular Maze

The maze is drawn in polar coordinates with the center as the starting point. Movement is allowed continuously in any direction as long as we do not cross or touch a wall.

codeforcescompetitive-programmingbrute-forcedfs-and-similargraphsimplementation
CF 1662I - Ice Cream Shop

We are asked to place a new ice cream shop along a beach where huts are positioned at regular intervals of 100 meters. Each hut contains a certain number of people who will buy ice cream only from the shop that is strictly closest to their hut.

codeforcescompetitive-programmingbrute-forceimplementationsortings
CF 1662N - Drone Photo

We are asked to count the number of ways to select four contestants standing on the vertices of a rectangle in an $n times n$ grid, such that when forming a banner using the two youngest contestants as one pole and the two oldest as another, the poles do not cross.

codeforcescompetitive-programmingcombinatoricsmathsortings
CF 1662L - Il Derby della Madonnina

We are given a sequence of moments in a football match when kicks happen, each kick occurring at a fixed time and a fixed position along the touch-line. At time zero, we start at position zero, and then we are allowed to move continuously along the line with a bounded speed.

codeforcescompetitive-programmingdata-structuresdpmath
CF 1662K - Pandemic Restrictions

We are tasked with finding a residence point in a 2D plane from which you can meet any pair of three friends such that the sum of distances from each attendee to the meeting point does not exceed a certain threshold $r$.

codeforcescompetitive-programminggeometryternary-search
CF 1662J - Training Camp

We are given an $n times n$ grid of kids. Each cell has two attributes: an age from $1$ to $n$, and a binary label saying whether the kid is good at programming.

codeforcescompetitive-programmingflowsgraphs
CF 1662H - Boundary

Bethany wants to tile her rectangular bathroom with a specific pattern. The interior, excluding the boundary, must be covered with standard $1 times 1$ tiles. The boundary is a one-tile-thick frame around the interior.

codeforcescompetitive-programmingbrute-forcemath
CF 1662G - Gastronomic Event

We are given a tree with n rooms, connected by n-1 corridors, forming a connected acyclic graph. Each room must host a unique Italian dish rated from 1 to n. A pleasing tour is a path in the tree where the sequence of dishes encountered is strictly increasing.

codeforcescompetitive-programmingdpgreedytrees
CF 1662C - European Trip

We are asked to count special trips on a graph of cities. Each city is a node, and each road is an undirected edge connecting two cities. A trip of length k is a sequence of k+1 cities such that each consecutive pair is connected by a road.

codeforcescompetitive-programmingdpgraphsmathmatrices
CF 1662F - Antennas

We are given a line of antennas indexed from left to right. Each antenna has a power value that determines how far it can directly communicate.

codeforcescompetitive-programmingdata-structuresdfs-and-similargraphsimplementationshortest-paths
CF 1662E - Round Table

We have n people sitting at a round table, numbered from 1 to n. The initial seating is the natural order [1, 2, 3, …, n] clockwise around the table. We are given a desired seating order in the form of a permutation p.

codeforcescompetitive-programmingmath
CF 1662D - Evolution of Weasels

We are given two DNA strings over the alphabet {A, B, C}. The goal is to decide whether we can transform the first string into the second using a sequence of operations.

codeforcescompetitive-programminggreedyimplementationstrings
CF 1662B - Toys

We are given three strings, each representing a name. Think of each string as a multiset of letters we need to be able to reconstruct. We are allowed to manufacture “sheets”, and each sheet has two letters written on its two sides.

codeforcescompetitive-programminggreedystrings
CF 1662A - Organizing SWERC

Gianni needs to assemble a problem set for SWERC from a pool of problems submitted by judges. Each problem has a beauty score and a difficulty rating from 1 to 10.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1663F - In Every Generation...

There are actually two separate problems. The immediate runtime error is not caused by the algorithm at all. The test harness calls: and inside run it calls: but the code snippet shown in the editorial did not include solve inside the test block.

codeforcescompetitive-programming*specialstrings
CF 1663H - Cross-Language Program

The task is purely about feasibility rather than computation. We are asked to construct a single source file that both C++ (GCC 10.3.1 with C++11 standard) and FreePascal (3.0.4) can compile successfully.

codeforcescompetitive-programming*specialconstructive-algorithms
CF 1663G - Six Characters

The task presents a string of exactly six letters. We are asked to produce another string of six letters that satisfies a hidden constructive property - in this problem, the exact constraints are designed so that a careful choice of repeated characters produces a valid answer.

codeforcescompetitive-programming*specialconstructive-algorithmsstrings
CF 1663D - Is it rated - 3

The problem gives us a string S of length three, consisting of the characters + and -, and a non-negative integer X. The string represents a sequence of operations on an integer: + means increment by 1, - means decrement by 1.

codeforcescompetitive-programming*specialcombinatoricsdpmath
CF 1663E - Are You Safe?

Before I start writing the editorial, I need to clarify something: the problem statement you gave is entirely narrative and does not include any actual rules for “Are You Safe?

codeforcescompetitive-programming*specialimplementation
CF 1663C - Pōja Verdon

I can't write a correct editorial for this problem from the information provided. The current statement for Codeforces 1663C - Pōja Verdon has been intentionally stripped down to: Given an array, output a single number. That version omits the actual task.

codeforcescompetitive-programming*specialimplementationmath
CF 1663A - Who Tested?

We are given a set of participants involved in a testing process, where each participant is associated with exactly one “tested by” relationship.

codeforcescompetitive-programming*specialexpression-parsingtrees
CF 1663B - Mike's Sequence

We are given a single integer $r$, which may be negative, zero, or positive up to 2999. The task is to compute another integer that depends on this value through a hidden construction that is not explicitly described in the statement, but is implicitly defined by the sample…

codeforcescompetitive-programming*specialdivide-and-conquerimplementationmath
CF 1665C - Tree Infection

We are asked to find the minimum time needed to infect all nodes of a rooted tree where infections spread in two ways each second. First, a spreading step allows any node with at least one infected child to infect at most one additional child.

codeforcescompetitive-programmingbinary-searchgreedysortingstrees
CF 1665D - GCD Guess

We are asked to find a hidden positive integer $x$ between 1 and $10^9$. Instead of observing $x$ directly, we can query the greatest common divisor of two numbers shifted by $x$. Specifically, for any two positive integers $a$ and $b$, the interactor returns $gcd(x + a, x + b)$.

codeforcescompetitive-programmingbitmaskschinese-remainder-theoremconstructive-algorithmsgamesinteractivemathnumber-theory
CF 1665E - MinimizOR

We are asked to process multiple subarray queries on an array of non-negative integers. For each subarray defined by indices $l$ and $r$, the task is to find the minimum value of the bitwise OR taken over all pairs of distinct elements in that subarray.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresdivide-and-conquergreedyimplementationtwo-pointers
CF 1665B - Array Cloning Technique

We are given an array of integers, and we can perform two types of operations: cloning an entire array copy, or swapping elements between any two copies. Our goal is to produce at least one array where all elements are identical, using the minimal number of operations.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 1665A - GCD vs LCM

The problem asks us to split a given positive integer $n$ into four positive integers $a, b, c, d$ such that the sum $a + b + c + d = n$ holds, and at the same time the greatest common divisor of $a$ and $b$ equals the least common multiple of $c$ and $d$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1666C - Connect the Points

We are given three distinct points on the 2D plane, and we are asked to connect them with segments that are either horizontal or vertical. The segments can only lie along the coordinate axes, meaning each segment has constant x or constant y.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgeometry
CF 1666L - Labyrinth

We are given a directed graph representing a labyrinth of halls and one-way passages. A traveler starts from a fixed starting hall $s$. We are allowed to choose any other hall $t$ as a meeting point.

codeforcescompetitive-programmingdfs-and-similargraphs
CF 1666K - Kingdom Partition

We are asked to partition a kingdom's towns into three districts, A, B, and C, corresponding to Adrian, Beatrice, and Cecilia. Adrian's castle must be in district A, Beatrice's castle in district B, and Cecilia has no castle.

codeforcescompetitive-programmingflows
CF 1666J - Job Lookup

We are asked to organize a team of n members into a binary search tree (BST) hierarchy that minimizes communication cost. Each team member has a unique number from 1 to n representing their position in a front-end to back-end spectrum.

codeforcescompetitive-programmingconstructive-algorithmsdpshortest-pathstrees
CF 1666I - Interactive Treasure Hunt

We are given a grid of size $n times m$ where two treasures are hidden in distinct cells. The goal is to locate both treasures using a combination of two operations: DIG r c and SCAN r c.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgeometryinteractivemath
CF 1666H - Heroes of Might

We are given a sequence of integer strengths representing heroes. Each hero can defeat monsters of strength equal to their own or weaker.

codeforcescompetitive-programmingmath
CF 1666G - Global Warming

In this problem, we are given a set of points on a two-dimensional plane, each representing a temperature measurement at a specific location.

codeforcescompetitive-programminggeometrymath
CF 1666F - Fancy Stack

The problem gives us a sequence of integers representing operations on a stack. Each integer can be seen as either pushing a new element onto the stack or performing a "fancy" operation that removes some elements from the top in a way governed by the problem's rules.

codeforcescompetitive-programmingcombinatoricsdpimplementation
CF 1666E - Even Split

We are given a one-dimensional segment representing the entire country, stretching from position 0 to position l. Inside this segment there are n citizens, each located at a distinct integer coordinate ai, sorted in increasing order.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedymath
CF 1666D - Deletive Editing

We are given two strings for each test case, an initial word and a target word. We repeatedly perform an operation where we are allowed to choose a character and delete its leftmost occurrence from the current word.

codeforcescompetitive-programminggreedy
CF 1666B - Budget Distribution

We are asked to distribute extra budget money over several topics, each consisting of a small number of items. For each topic, the optimal relative fractions of money for its items are given, and some money is already assigned to items and cannot be removed.

codeforcescompetitive-programming
CF 1666A - Admissible Map

We are given a string over four symbols, each symbol encoding a move in a grid: up, left, down, or right. Any substring of this string can be interpreted as a flattened matrix if we choose a height and width whose product equals the substring length, reading the substring row…

codeforcescompetitive-programming
CF 1667C - Half Queen Cover

The task is to place the minimum number of half-queens on an $n times n$ chessboard such that every square is either occupied or attacked. A half-queen attacks all cells in its row, its column, and the diagonal going from top-left to bottom-right that passes through its position.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1667F - Yin Yang

We are given a grid where some cells are already fixed as black or white, and the rest are empty. The goal is to assign a color to every empty cell so that, after filling, all black cells form a single connected region using 4-directional movement, and all white cells also…

codeforcescompetitive-programmingimplementation
CF 1667E - Centroid Probabilities

We are asked to count, for each vertex in a special class of labeled trees, how many trees have that vertex as a centroid. The trees have $n$ vertices labeled $1$ through $n$, with the restriction that each vertex $i ge 2$ is connected to exactly one vertex with a smaller index.

codeforcescompetitive-programmingcombinatoricsdpfftmath
CF 1667D - Edge Elimination

We are given a tree, which is a connected graph with no cycles, and we are asked to remove all its edges following a very particular rule: an edge can be removed only if it is adjacent to an even number of remaining edges. Two edges are adjacent if they share exactly one vertex.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardptrees
CF 1667A - Make it Increasing

We are asked to construct an array $b$ from an array $a$ such that each element of $b$ is obtained from zero by either adding or subtracting a multiple of the corresponding element in $a$.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1667B - Optimal Partition

We are asked to partition an array of integers into contiguous subarrays in order to maximize a custom score. Each subarray contributes to the total sum based on its sum: if the sum is positive, its contribution is the length of the subarray; if zero, it contributes nothing…

codeforcescompetitive-programmingdata-structuresdp
CF 1668B - Social Distance

We are given a circular arrangement of $m$ seats and a list of $n$ people. Each person has a personal “exclusion radius” $ai$: if they sit on some seat, then the closest $ai$ seats on both sides around the circle must remain empty.

codeforcescompetitive-programminggreedymathsortings
CF 1668A - Direction Change

We are walking on a very large rectangular grid starting from the top-left cell and trying to reach the bottom-right cell.

codeforcescompetitive-programmingimplementationmath
CF 1669B - Triple

The problem asks us to find any number in an array that occurs at least three times. We are given multiple test cases, and for each test case, an array of integers is provided. The integers are guaranteed to be between 1 and the size of the array.

codeforcescompetitive-programmingimplementationsortings
CF 1669H - Maximal AND

We are given an array of integers, and we are allowed to “turn on” bits in individual elements. Each operation picks one element and sets one previously-zero bit to one. We may do this at most k times across the entire array.

codeforcescompetitive-programmingbitmasksgreedymath
CF 1669G - Fall Down

We are given a rectangular grid of size $n times m$ consisting of empty cells, stones, and obstacles. Stones are represented by '', empty cells by '.', and obstacles by 'o'.

codeforcescompetitive-programmingdfs-and-similarimplementation
CF 1669F - Eating Candies

We are given a sequence of candy weights laid out in a straight line. Two people, Alice and Bob, consume candies under a strict constraint: Alice can only take a prefix from the left end, while Bob can only take a suffix from the right end.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedytwo-pointers
CF 1669E - 2-Letter Strings

We are given a collection of short strings, each consisting of exactly two lowercase letters from a small alphabet.

codeforcescompetitive-programmingdata-structuresmathstrings
CF 1669D - Colorful Stamp

We are given a line of cells that starts completely empty, and we are allowed to apply a special operation that always acts on exactly two adjacent positions. Each application recolors those two cells into different colors, one red and one blue, in either order.

codeforcescompetitive-programmingimplementation
CF 1669C - Odd/Even Increments

We are given an array of integers where we are allowed to repeatedly apply two global operations. One operation increments every element at odd positions, and the other increments every element at even positions.

codeforcescompetitive-programminggreedyimplementationmath
CF 1669A - Division?

Each test case gives a single integer representing a Codeforces user rating, and the task is to classify that rating into one of four fixed intervals, each corresponding to a division number. The mapping is purely threshold-based.

codeforcescompetitive-programmingimplementation
CF 1670C - Where is the Pizza?

We are given two permutations of size $n$, which are arrays containing each integer from $1$ to $n$ exactly once. From these two permutations, a third array is constructed by choosing for each position either the value from the first permutation or from the second permutation.

codeforcescompetitive-programmingdata-structuresdfs-and-similardsugraphsimplementationmath
CF 1670E - Hemose on the Tree

We are given a tree with $n = 2^p$ vertices. We must assign distinct integers from $1$ to $2n-1$ to all vertices and edges, so in total we label exactly $2n-1$ objects. After fixing these labels, we also choose a root.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdfs-and-similartrees
CF 1670F - Jee, You See?

Working

codeforcescompetitive-programmingbitmaskscombinatoricsdp
CF 1670D - Very Suspicious

We are working with an infinite hexagonal grid, where each hexagon shares edges with six neighbors. The task is to add straight lines along the directions of the hexagon edges to form equilateral triangles.

codeforcescompetitive-programmingbinary-searchbrute-forcegeometrygreedyimplementationmath
CF 1670A - Prof. Slim

We are given an array of non-zero integers, and we are allowed to repeatedly swap the signs of any two elements that have opposite signs. The goal is to determine whether we can make the array non-decreasing with this operation.

codeforcescompetitive-programminggreedyimplementationsortings
CF 1670B - Dorms War

We are given a string that represents a password and a set of special characters. A transformation program can be applied repeatedly to the string.

codeforcescompetitive-programmingbrute-forceimplementationstrings
CF 1671F - Permutation Counting

We are counting permutations of size $n$ with two simultaneous structural constraints. The first constraint fixes the total number of inversions, meaning how many pairs $(i, j)$ with $i < j$ appear in reversed order in the permutation.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpfftmath
CF 1671D - Insert a Progression

We are given an array of integers a and a set of extra integers {1, 2, …, x}. The task is to insert all these extra integers into a in any order and at any positions, including at the beginning or end.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedy
CF 1671A - String Building

The input to the system is well-formed but the observed failure pattern is not a mathematical or logical inconsistency of the task; it is a structural defect: the program produces no output at all for multiple independent test cases, indicating that the core loop does not…

codeforcescompetitive-programmingimplementation
CF 1671E - Preorder

We are given a complete binary tree of size $2^n - 1$, where every internal node has exactly two children and all leaves lie on the same level. Each node carries a label, either A or B.

codeforcescompetitive-programmingcombinatoricsdivide-and-conquerdpdsuhashingsortingstrees
CF 1671B - Consecutive Points Segment

We are given a set of points on a number line, already sorted in increasing order. Each point is allowed to “wiggle” by at most one unit, meaning its final position can be its original coordinate, one step left, or one step right.

codeforcescompetitive-programmingbrute-forcemathsortings
CF 1671C - Dolce Vita

We have a scenario where you want to buy sugar packs from several shops over consecutive days, with each shop selling one pack per day. Each shop has an initial price for its pack, and every day the price increases by one.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedymath
CF 1672I - PermutationForces

Codeforces 1672I: PermutationForces

codeforcescompetitive-programmingdata-structuresgreedy
CF 1672H - Zigu Zagu

We are given a binary string and many queries on substrings. For each query interval, we repeatedly delete contiguous pieces of the current substring.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 1672G - Cross Xor

We are asked to construct a binary grid of size $r times c$ by applying a specific row-column flip operation multiple times starting from an all-zero grid. The operation allows us to pick any cell and flip all values in its row and column using XOR with 1.

codeforcescompetitive-programmingconstructive-algorithmsgraphsmathmatrices
CF 1672B - I love AAAB

We are asked to represent each integer in the range from $-10$ to $10$ using the numeral system with radix $-2$. In this system, every integer $N$ is written in the form $$N = sum{i=0}^{k} di (-2)^i,$$ where each digit $di in {0,1}$ and the representation is chosen so that the…

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1672F2 - Checker for Array Shuffling

We are given two arrays of the same length. The first array represents the “original” configuration, and the second array is a shuffled version of it, meaning it contains exactly the same multiset of values but possibly in a different order.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphs
CF 1672F1 - Array Shuffling

We are given an array that contains values in the range from 1 to n, possibly with repetitions. Think of this array as a multiset of labeled tokens.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedy
CF 1672E - notepad.exe

We are dealing with a hidden array of word lengths, and the only way to learn anything about it is by querying a hypothetical text editor.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedyinteractive
CF 1672D - Cyclic Rotation

We are given two arrays, a and b, of the same length n. The goal is to determine whether we can transform a into b using a specific operation.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationtwo-pointers
CF 1672A - Log Chopping

We are asked to determine the winner in a simple two-player game with logs of integer lengths. There are $n$ logs, and two players take turns splitting a single log into two positive integer pieces. The first player unable to make a move loses.

codeforcescompetitive-programminggamesimplementationmath
CF 1672C - Unequal Array

We are given an array of integers and asked to minimize consecutive repetitions. Formally, we define the equality of an array as the number of positions where two consecutive elements are equal.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1673C - Palindrome Basis

The runtime error ValueError: min() arg is empty comes from trying to compute min(arr) when arr is empty. The root cause is that the input parsing logic does not match the problem's actual input format.

codeforcescompetitive-programmingbrute-forcedpmathnumber-theory