brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1852F - Panda Meetups

Codeforces 1852F: Panda Meetups

codeforcescompetitive-programmingdata-structuresdpflows
CF 1852B - Imbalanced Arrays

Working

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedymathsortingstwo-pointers
CF 1852C - Ina of the Mountain

We start with an infinite sorted sequence of positive integers. Each day, we repeatedly delete several positions from the current ordered set.

codeforcescompetitive-programmingdata-structuresdpgreedymath
CF 1852A - Ntarsis' Set

We are given an initially infinite-like set $S$ consisting of integers $1, 2, 3, dots$. Each day, Ntarsis removes specific elements from this set.

codeforcescompetitive-programmingbinary-searchmathnumber-theory
CF 1853F - Miriany and Matchstick

I’m sorry, but I can’t reliably write a complete editorial and verified solution for this problem from memory alone. For a Codeforces 2800-rated constructive/DP problem, producing a full editorial with proof and code without first reconstructing or veri

codeforcescompetitive-programmingconstructive-algorithmsdpgreedy
CF 1853E - Ina of the Mountain

We are given a row of n octopuses, each with a health value between 1 and k. The goal is to bring all octopuses to health k. We can throw boulders that reduce the health of a contiguous range of octopuses by 1.

codeforcescompetitive-programmingdata-structuresgreedymath
CF 1853B - Fibonaccharsis

We are given two integers, n and k. We want to count how many Fibonacci-like sequences of length k end with value n.

codeforcescompetitive-programmingbinary-searchbrute-forcemath
CF 1853A - Desorting

We are given an array of integers, and we are allowed to repeatedly apply an operation that shifts value from the right side of a chosen split point to the left side in a very structured way.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1854D - Michael and Hotel

We are given a directed graph on $n le 500$ vertices where each vertex has exactly one outgoing edge. From every room $i$, a teleporter sends us deterministically to room $ai$.

codeforcescompetitive-programmingbinary-searchinteractivetrees
CF 1854E - Game Bundles

We are asked to select a collection of games, each with a positive enjoyment value, such that the number of distinct subsets of these games that sum to exactly 60 equals a given integer $m$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdpgreedymath
CF 1854F - Mark and Spaceship

We are working in a four-dimensional integer grid. From the origin, a spaceship executes a sequence of moves, where each move chooses one of the four coordinate axes and steps by one unit in either direction.

codeforcescompetitive-programmingbrute-forcedp
Kvant Math Problem 2226

Let $A(k,n)$ denote the number of integer $k$-tuples $(x_1,\dots,x_k)$ satisfying the inequality

kvantmathematicsolympiad
CF 1854C - Expected Destruction

We are given a set of distinct integers S drawn from the range 1 to m. Every second, we perform a stochastic operation: we select an element x from S uniformly at random, remove it, and if x+1 is within bounds and absent from S, we add x+1 back into the set.

codeforcescompetitive-programmingcombinatoricsdpmathprobabilities
CF 1854A2 - Dual (Hard Version)

We are given an integer array. In one operation we choose two positions i and j and add the value at position j into position i. The goal is not to sort the array. We only need the final array to be non-decreasing, meaning every element is at least as large as the previous one.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1854A1 - Dual (Easy Version)

We are given an array of integers that may be positive, negative, or zero. We are allowed to perform operations where we pick any two indices $i$ and $j$ and add the value of $aj$ to $ai$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1854B - Earn or Unlock

We are given a scenario where a player wants to maximize their earnings while unlocking skills in a game. There are n skills, each requiring certain previously unlocked skills and providing a coin reward if unlocked.

codeforcescompetitive-programmingbitmasksbrute-forcedp
Kvant Math Problem 1595

Since $AB=BC$ and $\angle ABC=80^\circ$, the base angles of triangle $ABC$ are both $50^\circ$.

kvantmathematicsolympiad
CF 1855F - Michael and Hotel

We are given a hotel with n rooms, numbered 1 through n, each equipped with a teleporter that deterministically sends anyone in that room to a fixed target room.

codeforcescompetitive-programmingbinary-searchinteractive
CF 1855E - Expected Destruction

We are given a set of distinct integers between 1 and some maximum value m. At each second, we remove a random element x from the set. After removing it, if x+1 is within bounds and not already in the set, we add x+1.

codeforcescompetitive-programmingdpmathprobabilities
CF 1855D - Earn or Unlock

We are given a sequence of cards arranged in a line. Each card has a numeric value and starts either locked or unlocked depending on its position: initially only the first card can be used, while all others become usable only after being unlocked through earlier actions.

codeforcescompetitive-programmingbitmasksbrute-forcedp
CF 1855C2 - Dual (Hard Version)

We are given an array of integers, which can be positive, negative, or zero, and the task is to transform this array into a non-decreasing sequence. The only allowed operation is to pick two indices $i$ and $j$ and add the value at $aj$ to $ai$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1855C1 - Dual (Easy Version)

We are allowed to repeatedly pick two positions in an array and add the value of one position into another. The source element is not consumed or changed when it is used, so the operation behaves like a reusable “transfer of value” between indices.

codeforcescompetitive-programmingconstructive-algorithms
CF 1855A - Dalton the Teacher

The problem asks us to make every student in a classroom "happy" by ensuring that no student sits on a chair with the same number as their own. We are given an initial permutation of students to chairs.

codeforcescompetitive-programminggreedymath
CF 1855B - Longest Divisors Interval

We are asked to work with a positive integer $n$ and find the longest contiguous range of positive integers $[l, r]$ such that each number in this interval divides $n$. In other words, for every integer $i$ between $l$ and $r$, $n bmod i = 0$.

codeforcescompetitive-programmingbrute-forcecombinatoricsgreedymathnumber-theory
CF 1856E2 - PermuTree (hard version)

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.

codeforcescompetitive-programmingbitmasksdfs-and-similardpfftgreedyimplementationmathtrees
CF 1856D - More Wrong

We are asked to find the position of the maximum element in a hidden permutation of length $n$ by using queries that tell us the number of inversions in a subarray.

codeforcescompetitive-programmingdivide-and-conquerinteractive
CF 1856E1 - PermuTree (easy version)

We are given a rooted tree with n vertices, labeled 1 through n, where vertex 1 is the root. Each non-root vertex i has a parent pi, defining the edges of the tree.

codeforcescompetitive-programmingdfs-and-similardptrees
Kvant Math Problem 1593

Let $f_n(m)$ denote the number of ways to represent an integer $m$ as a sum of signed powers of two up to $2^n$, where each coefficient $a_k$ can take values in ${-1,0,1}$.

kvantmathematicsolympiad
CF 1856B - Good Arrays

We are given an array of positive integers. We want to know whether it is possible to construct another array of the same length such that every position changes its value, but the total sum stays exactly the same. The second array is not arbitrary.

codeforcescompetitive-programmingimplementationmath
CF 1856A - Tales of a Sort

We are given an array of positive integers. Alphen can perform a single operation repeatedly, where every element of the array is reduced by one, but no element can go below zero.

codeforcescompetitive-programmingimplementation
CF 1856C - To Become Max

We are given an array of integers and a number of allowed operations. Each operation lets us pick an index $i$ such that the element at $i$ is less than or equal to its right neighbor, and increase $ai$ by one.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdp
CF 2220E - Coloring a Red Black Tree

We are given a tree with n nodes, where each node is either red or black. The goal is to make all nodes red using a stochastic operation: you select a node and recolor it with the color of one of its neighbors chosen uniformly at random.

codeforcescompetitive-programmingdpgreedyprobabilitiessortingstrees
CF 2220D2 - Unique Values (Hard version)

We are given an array of length $2n+1$. Every number from $1$ to $n$ appears exactly twice, except for one special value that appears three times. This creates a very rigid structure: all values are paired except one value that has an “extra copy”.

codeforcescompetitive-programmingbinary-searchinteractive
CF 2220F - MEX Replacement on Tree

We have a rooted tree. Every vertex carries a unique value from the permutation $0,1,dots,n-1$. For a vertex $v$, look at all vertices on the root-to-$v$ path. Their values form a set $Sv$.

codeforcescompetitive-programming
CF 2220D1 - Unique Values (Easy version)

In the original interactive problem, there is a hidden array of length $2n+1$. Every value from $1$ to $n$ appears exactly twice, except for one special value that appears three times. The task is to identify the three positions containing that special value.

codeforcescompetitive-programmingbinary-searchinteractive
CF 2220A - Blocked

We are given two nonnegative integers (x) and (y). We must construct two new nonnegative integers (p) and (q) such that no bit is set in both numbers simultaneously, that is, [ p ,&, q = 0.

codeforcescompetitive-programminggreedysortings
CF 2220C - Grid L

We are given two types of building blocks: unit-length segments and L-shaped pieces made of two segments joined at a right angle. We need to construct a rectangular grid with dimensions $n times m$ so that every piece is used exactly once.

codeforcescompetitive-programmingbrute-forcemath
CF 2216E - Oriented Journey

The value $V = 7frac{1}{16}$ corresponds to the chi-square statistic computed from $k = 11$ categories, as in Eq. (5). The number of degrees of freedom is therefore $nu = k - 1 = 10$.

codeforcescompetitive-programmingcommunicationconstructive-algorithmsinteractive
CF 2216F - Star Map

After sorting the stars by increasing $x$-coordinate, every star appears at a unique horizontal position and also has a unique $y$-coordinate. The geometry is completely determined by the permutation of the $y$-values in this order.

codeforcescompetitive-programmingconstructive-algorithmsgeometry
CF 2216A - Course Wishes

We are given a small system of courses, each currently assigned a priority level from 1 up to k+1. The last level behaves differently: it has no capacity restriction and is the final target state for every course.

codeforcescompetitive-programminggreedy
CF 2216C - Interval Mod

We are given an array of integers and can repeatedly pick subarrays of length at least k and reduce every element in that subarray modulo one of two given values p or q. The goal is to minimize the sum of the array after any number of such operations.

codeforcescompetitive-programminggreedy
CF 2216D - RReeppeettiittiioonn

The value $V = 7frac{1}{16}$ corresponds to the chi-square statistic computed from $k = 11$ categories, as in Eq. (5). The number of degrees of freedom is therefore $nu = k - 1 = 10$.

codeforcescompetitive-programmingbrute-forceimplementationnumber-theory
CF 2216B - THU Packing Puzzle

The value $V = 7frac{1}{16}$ corresponds to the chi-square statistic computed from $k = 11$ categories, as in Eq. (5). The number of degrees of freedom is therefore $nu = k - 1 = 10$.

codeforcescompetitive-programminggreedy
CF 2202G2 - Monotone Monochrome Matrices (Hard Version)

We are maintaining a very large square grid that starts completely empty, meaning every cell is white. Over time, we flip some cells to black, one by one, and after each flip we must decide whether the resulting black-white pattern is still “valid” under a global…

codeforcescompetitive-programmingdata-structures
Kvant Math Problem 1591

Let $BL$ be the internal angle bisector at $B$ meeting $AC$ at $L$, and $AK$ be the internal angle bisector at $A$ meeting $BC$ at $K$.

kvantmathematicsolympiad
CF 2202G1 - Monotone Monochrome Matrices (Easy Version)

The value $V = 7frac{1}{16}$ corresponds to the chi-square statistic computed from $k = 11$ categories, as in Eq. (5). The number of degrees of freedom is therefore $nu = k - 1 = 10$.

codeforcescompetitive-programmingdata-structures
CF 2202F - Binary Not Search and Queries

We are asked to maintain a sequence of integers and repeatedly compute two properties after point updates. Specifically, for a given array a of length n, we want to find, after each update, the largest length k such that there exist two subarrays of length k with identical…

codeforcescompetitive-programmingdata-structuresgreedy
CF 2202E - Rigged Bracket Sequence

We are given a balanced bracket sequence, meaning every prefix has at least as many opening brackets as closing brackets, and the total numbers match at the end. From this sequence, we choose a non-empty subset of positions.

codeforcescompetitive-programmingdp
Kvant Math Problem 1568

This is a Type B problem.

kvantmathematicsolympiad
CF 2202B - ABAB Construction

The value $V = 7frac{1}{16}$ corresponds to the chi-square statistic computed from $k = 11$ categories, as in Eq. (5). The number of degrees of freedom is therefore $nu = k - 1 = 10$.

codeforcescompetitive-programmingdpgreedyimplementation
CF 2202D - Recollect Numbers

Working

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 2202C1 - Lost Civilization (Easy Version)

We are asked to reverse-engineer a process that generates a sequence by repeatedly inserting an incremented copy of an existing element immediately after that element.

codeforcescompetitive-programmingdata-structuresdsugreedy
CF 2202C2 - Lost Civilization (Hard Version)

We are given a sequence of integers, and the task revolves around understanding a generative procedure used by an ancient civilization.

codeforcescompetitive-programmingdata-structuresdpdsugreedy
CF 2197F - Double Bracket Sequence

The value $V = 7frac{1}{16}$ corresponds to the chi-square statistic computed from $k = 11$ categories, as in Eq. (5). The number of degrees of freedom is therefore $nu = k - 1 = 10$.

codeforcescompetitive-programmingdata-structuresdpflowsgreedy
Kvant Math Problem 1569

Working

kvantmathematicsolympiad
Kvant Math Problem 1570

Consider three pairs of diametrically opposite points on a sphere, denoted $A, A'$, $B, B'$, $C, C'$, where $O$ is the center of the sphere.

kvantmathematicsolympiad
CF 2197E2 - Interactive Graph (Hard Version)

We are tasked with reconstructing a hidden directed acyclic graph with n vertices by asking queries about its paths. Each query gives the k-th path in lexicographical order.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardpgraphsinteractive
CF 2197E1 - Interactive Graph (Simple Version)

We are tasked with reconstructing an unknown directed acyclic graph using an interactive interface. The graph has n vertices and an unknown number of edges m, and no loops or multiple edges.

codeforcescompetitive-programmingbinary-searchcombinatoricsdfs-and-similardpgraphsinteractive
CF 2197C - Game with a Fraction

The value $V = 7frac{1}{16}$ corresponds to the chi-square statistic computed from $k = 11$ categories, as in Eq. (5). The number of degrees of freedom is therefore $nu = k - 1 = 10$.

codeforcescompetitive-programminggamesgreedymath
CF 2197D - Another Problem about Beautiful Pairs

We are given an array of integers, and we need to count pairs of indices (i, j) where i < j and the product of the corresponding values equals the distance between the indices: a[i] a[j] = j - i.

codeforcescompetitive-programmingbrute-forcedata-structuresdivide-and-conquermathnumber-theory
CF 2197B - Array and Permutation

We are given a permutation p of length n and an array a of the same length. A permutation is an array of distinct integers from 1 to n, in some order.

codeforcescompetitive-programmingimplementationschedulessortingstwo-pointers
CF 2191G - Median Permutation

We are given a partially filled permutation of size $n$, represented as an array $a$ where zeros indicate unknown positions.

codeforcescompetitive-programmingcombinatorics
CF 2191F - Prufer Vertex

We start with a graph that is already a forest, meaning it is a collection of trees on the vertex set $1 ldots n$. Some edges are present, but the graph is acyclic and possibly disconnected.

codeforcescompetitive-programmingcombinatoricsnumber-theory
CF 2191E - Comparable Permutations

Something went wrong. If this issue persists please contact us through our help center at help.openai.com.

codeforcescompetitive-programminginteractivetwo-pointers
CF 2191C - Sorting Game

We are given a weighted undirected graph. We must choose exactly $n-1$ edges. If those $n-1$ edges form a spanning tree, the choice is forbidden. We want the minimum possible total weight among all choices of $n-1$ edges that do not form a tree.

codeforcescompetitive-programminggames
CF 2191D2 - Sub-RBS (Hard Version)

We are given a string s of parentheses of length n. The task is to consider all non-empty subsequences of s and compute a "score" for each. The score is defined as follows: if the subsequence is not a regular bracket sequence, its score is 0.

codeforcescompetitive-programmingdpgames
CF 2191D1 - Sub-RBS (Easy Version)

We are given a string of parentheses s that is already a valid regular bracket sequence. The task is to find the longest non-empty subsequence t of s that is also a valid regular bracket sequence and is “better” than s.

codeforcescompetitive-programmingconstructive-algorithms
CF 2191B - MEX Reordering

We are given an array of integers, and we are allowed to reorder it arbitrarily. After fixing an order, we look at every possible split position between prefix and suffix.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 2188G - Doors and Keys

We are given a line of rooms connected by doors, where each door has a time at which it opens automatically and each room may contain a key. You start in room 1 at time 0, and the goal is to find the minimum time to reach each subsequent room.

codeforcescompetitive-programmingdp
CF 2188F - Cool Problem

We are given a string made of characters 0, 1, and ?. Each complete version of this string defines a numerical process that generates a sequence of values. We start from c0 = 0. Then we scan the string from left to right.

codeforcescompetitive-programmingbitmasksdpmath
CF 2188E - Jerry and Tom

Every vertex has an edge to the next vertex, and possibly one additional long jump to a larger vertex. The extra edges never cross. If we draw every edge above the number line, no two extra edges form the pattern $ui < uj < vi < vj$. Jerry must move every turn.

codeforcescompetitive-programmingdata-structuresdfs-and-similargamesgraphsgreedytrees
CF 2188C - Restricted Sorting

We are given an array of integers and asked to find the largest integer $k$ such that the array can be sorted into non-decreasing order by repeatedly swapping any two elements whose difference is at least $k$. If no such $k$ exists, we return $-1$.

codeforcescompetitive-programminggreedysortings
CF 2188A - Divisible Permutation

We are asked to construct a rearrangement of the numbers from 1 to n such that adjacent elements satisfy a divisibility condition tied to their position. More concretely, we build an array p of length n containing each integer from 1 to n exactly once.

codeforcescompetitive-programmingconstructive-algorithms
CF 2188D - Shortest Statement Ever

Working

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdpgreedymath
CF 2175F - Secret Message

We are given a weighted undirected graph. We must choose exactly $n-1$ edges. If those $n-1$ edges form a spanning tree, the choice is forbidden. We want the minimum possible total weight among all choices of $n-1$ edges that do not form a tree.

codeforcescompetitive-programmingdata-structuresimplementationtrees
Kvant Math Problem 1565

A query chooses 50 of the 100 elements and reveals their induced linear order, which determines all pairwise comparisons inside the chosen set.

kvantmathematicsolympiad
CF 2175E2 - Beautiful Patterns (Hard Version)

We are asked to compute the expected beauty of a one-dimensional mosaic of length $n$, where each position is independently colored using one of $m$ colors. The beauty is defined as the square of the number of palindromic subsegments of the mosaic.

codeforcescompetitive-programmingcombinatoricsmathprobabilities
CF 2175E1 - Beautiful Patterns (Easy Version)

We are looking at a random string of length $n$, where each position independently receives one of $m$ colors with equal probability.

codeforcescompetitive-programmingcombinatoricsmathprobabilities
CF 2175D - Wishing Cards

We are tasked with distributing a limited number of wishing cards among $n$ friends so that the cumulative happiness of Little A is maximized. Each friend $i$ can carry at most $ai$ cards, and the sum of all cards cannot exceed $k$.

codeforcescompetitive-programmingdpgreedy
CF 2175B - XOR Array

We are asked to construct an array of positive integers of length n such that the XOR of a single contiguous subarray from index l to r is zero, while the XOR of every other non-empty subarray is non-zero.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 2175C - Needle in a Haystack

We are given two strings, s and t. The goal is to rearrange the letters of t such that s appears as a subsequence in the resulting string, while making the final string lexicographically as small as possible.

codeforcescompetitive-programminggreedystrings
CF 2166B - Tab Closing

<Title valuea). If there are currently (="Solution Editorial"m) tabs open, every tab has length [ size="2xl"/<Title value="Problem Understanding" size="text{len} = minleft(b,frac{a}{m}right).

codeforcescompetitive-programmingmath
CF 2166F - Path Split

We are given a sequence of integers, and we want to split its elements into several subsequences. Each element must belong to exactly one subsequence, and within each subsequence, consecutive chosen elements must differ by exactly one in value.

codeforcescompetitive-programmingdata-structuresgraph-matchingsgreedy
CF 2166E - Binary Wine

We are given an array of integers, and we are allowed to increase individual elements by paying a cost equal to the total number of increments we perform.

codeforcescompetitive-programmingbitmasksdpgreedymath
CF 2166D - Marble Council

We are given a multiset of integers, which is just a collection where elements can repeat. The task is to count how many different multisets can be generated by repeatedly partitioning the original multiset into any number of non-empty groups and then taking one mode from each…

codeforcescompetitive-programmingdpmath
CF 2166A - Same Difference

We are given a string of lowercase letters. In one move, we pick a position and overwrite its character with the character immediately to its right. The operation only allows copying from right to left, so information flows strictly in one direction.

codeforcescompetitive-programmingbrute-forcegreedystrings
CF 2166C - Cyclic Merging

We are given a set of values placed around a circle, and we repeatedly compress this circle until only one value remains.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdsugreedy
CF 2160G2 - Inverse Minimum Partition (Hard Version)

We are given an array of positive integers. For every subarray, we first define a function $f$ that depends on how we optimally split that subarray into consecutive pieces.

codeforcescompetitive-programmingdata-structuresdpgreedy
Kvant Math Problem 1562

We are asked whether a $5\times7$ rectangle can be covered by L-trominoes in several layers so that each cell of the rectangle is covered by the same number of cells from the trominoes.

kvantmathematicsolympiad
CF 2160F - Twin Polynomials

We are given a polynomial $f(x) = a0 + a1 x + dots + an x^n$, where each coefficient is a non-negative integer and the leading coefficient $an$ is positive. Some coefficients are fixed, others are unknown.

codeforcescompetitive-programmingcombinatoricsdpgraphsmath
CF 2160E - Rectangles

We are given a binary grid of size $n times m$, where each cell contains either 0 or 1. A rectangle in this context is defined not by the usual continuous blocks of 1s, but by the four corner cells: a rectangle $(u,d,l,r)$ exists if and only if the top-left, top-right…

codeforcescompetitive-programmingbrute-forcedpgreedyimplementationtwo-pointers
Kvant Math Problem 1564

Let

kvantmathematicsolympiad
CF 2160B - Distinct Elements

The solution correctly identifies the modified middle-square sequence as a special case of a quadratic congruential sequence modulo $2^e$.

codeforcescompetitive-programminggreedymath
CF 2160D - MAD Interactive Problem

We are given a hidden array of length $2n$. Every number from $1$ to $n$ appears exactly twice, but their order is unknown. We cannot see the array directly.

codeforcescompetitive-programmingconstructive-algorithmsgreedyinteractivemath
CF 2160C - Reverse XOR

We are given a target integer $n$, and we want to know whether it is possible to construct some positive integer $x$ such that a specific transformation applied to $x$ and combined with XOR produces exactly $n$.

codeforcescompetitive-programmingbitmasks
Kvant Math Problem 1560

Consider the population as a finite set of $N$ individuals arranged along a circle.

kvantmathematicsolympiad
CF 2151G1 - Hidden Single (Version 1)

We are given a hidden array of length 2n-1 where each number from 1 to n appears exactly twice except for one number, which appears exactly once. Our goal is to determine which number appears only once. We do not need to find its position, only the value.

codeforcescompetitive-programmingbinary-searchdivide-and-conquerinteractivemath
CF 2151G2 - Hidden Single (Version 2)

We are given a hidden sequence of length $2n-1$ that contains every number from $1$ to $n$ exactly twice, except for one special value that appears only once. So the multiset looks like a perfect pairing structure with a single unpaired element. We cannot see the array directly.

codeforcescompetitive-programmingbinary-searchdivide-and-conquerinteractivemathprobabilities
CF 2151F - Attraction Theory

We are given a one-dimensional line with $n$ people initially at positions $1$ through $n$, and each position $i$ has a value $ai$.

codeforcescompetitive-programmingcombinatoricsdp
CF 2151D - Grid Counting

We are given an $n times n$ grid and we must choose a set of black cells. The choice is constrained by three independent-looking counting rules. The first rule fixes how many black cells appear in each row. Row $k$ must contain exactly $ak$ chosen cells.

codeforcescompetitive-programmingcombinatorics