brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1927B - Following the String

We are given an array a that describes how a hidden string was built. For each position i, the value a[i] tells us how many times the character at position i has already appeared earlier in the string. If a[i] = 0, this character has never appeared before.

codeforcescompetitive-programmingconstructive-algorithmsgreedystrings
CF 1927C - Choose the Different Ones!

We are given two arrays, a and b, and an even integer k. We need to pick exactly k/2 elements from each array such that the multiset of chosen elements contains all integers from 1 to k.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1927A - Make it White

We are given a small horizontal strip of cells, each of which can be black or white. Our goal is to make every cell white by repainting a single contiguous segment. The repainting operation turns every black cell in that segment white, and leaves white cells unchanged.

codeforcescompetitive-programminggreedystrings
CF 1928F - Digital Patterns

We are given a grid-like scarf made by interweaving horizontal threads with vertical threads. Each horizontal thread has a transparency coefficient, as does each vertical thread. When interwoven, the cell at row i and column j has transparency equal to a[i] + b[j].

codeforcescompetitive-programmingcombinatoricsdata-structuresimplementationmath
Kvant Math Problem 1482

Let

kvantmathematicsolympiad
CF 1928A - Rectangle Cutting

We are given a rectangle with sides $a$ and $b$, and we are asked whether it is possible to cut this rectangle along a line parallel to one of its sides into two smaller rectangles with integer dimensions, and then use these two pieces to form a rectangle that is different in…

codeforcescompetitive-programminggeometrymath
CF 1928D - Lonely Mountain Dungeons

We are asked to assemble an army from multiple races, each with a certain number of creatures. Each creature pair from the same race, if they are placed in different squads, contributes a fixed amount b to the army’s strength.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedymathternary-search
CF 1928E - Modular Sequence

We are building a sequence starting from a fixed initial value, and each next value is determined by choosing between two operations. One operation increases the current value by a fixed step size y, and the other replaces the current value by its remainder when divided by y.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdpgraphsgreedymathnumber-theory
CF 1928B - Equalize

The problem gives us an array of integers and asks us to maximize the number of equal elements after adding a permutation of numbers from 1 to n to the array.

codeforcescompetitive-programmingbinary-searchgreedysortingstwo-pointers
CF 1928C - Physical Education Lesson

We are given a scenario in which students line up according to a repeating "first-$k$-th" pattern. The sequence starts with numbers $1$ to $k$, then reverses from $k-1$ down to $2$, and this whole block repeats every $2k-2$ positions.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
Kvant Math Problem 1474

Let the direction of the line used in the $i$-th projection be denoted by $\alpha_i$.

kvantmathematicsolympiad
CF 1929A - Sasha and the Beautiful Array

We are given an array of integers, and we may rearrange its elements in any order. The beauty of a particular arrangement is defined as the sum of differences between consecutive elements: $$(a2-a1)+(a3-a2)+cdots+(an-a{n-1})$$ Our task is to choose the ordering that produces…

codeforcescompetitive-programmingconstructive-algorithmsgreedymathsortings
CF 1930I - Counting Is Fun

We are given a binary template string $p$ of length $n$. We are asked to count how many binary strings $q$ of the same length are valid under a global consistency rule that is defined locally in a slightly indirect way.

codeforcescompetitive-programmingcombinatorics
CF 1930D2 - Sum over all Substrings (Hard Version)

For every binary pattern $p$, we define $f(p)$ as the minimum number of 1s in another binary string $q$ of the same length such that every position of $p$ can "justify" its value by looking at some interval of $q$ containing that position.

codeforcescompetitive-programmingbitmasksdivide-and-conquerdpdsugreedyimplementationstrings
CF 1930E - 2..3...4.... Wonderful! Wonderful!

We start with the array $$[1,2,3,dots,n].$$ A value $k$ is fixed for the whole process. In one operation we choose a subsequence of length $2k+1$. Among those chosen elements, we delete the first $k$ and the last $k$, keeping only the middle one.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1930A - Maximise The Score

We are given a list of 2n positive integers, and we need to perform exactly n moves. Each move consists of picking two numbers from the list, adding the smaller of the two to our score, and removing both numbers from the list.

codeforcescompetitive-programminggreedysortings
CF 1931G - One-Dimensional Puzzle

We are asked to count the number of ways to assemble a one-dimensional puzzle using four distinct types of tiles. Each tile has connections on the left and right, which can be a protrusion or a recess.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 1931D - Divisible Pairs

We are given an array of integers and two numbers, $x$ and $y$. A pair of indices $(i, j)$ with $i < j$ is considered "beautiful" if the sum of the two elements $ai + aj$ is divisible by $x$ and the difference $ai - aj$ is divisible by $y$.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 1931F - Chat Screenshots

We are given a chat with n participants, each identified by a unique number from 1 to n. The chat displays participants in a list ordered by activity, but each participant always sees themselves at the top of their own list.

codeforcescompetitive-programmingcombinatoricsdfs-and-similargraphs
CF 1931E - Anna and the Valentine's Day Gift

The game begins with a list of integers. Anna moves first by reversing the digits of any number, which can increase or decrease its value depending on the digits. Sasha moves second by concatenating any two numbers, reducing the list size by one.

codeforcescompetitive-programminggamesgreedymathsortings
CF 1931C - Make Equal Again

We are given an array of integers and we want to make all elements equal. We are allowed to perform at most one operation, which consists of picking a contiguous subarray and setting all its elements to some value.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1931A - Recovering a Small String

We are given a single integer that represents the sum of three hidden lowercase letters. Each letter contributes its position in the alphabet, so a contributes 1, b contributes 2, and so on up to z contributing 26.

codeforcescompetitive-programmingbrute-forcestrings
CF 1931B - Make Equal

We are given several independent scenarios. In each scenario there is a line of containers, each holding some amount of water. We are allowed to move water, but only from a container on the left to a container on the right.

codeforcescompetitive-programminggreedy
CF 1932G - Moving Platforms

We are given a graph of platforms, where each platform has a level between 0 and H-1. Moving from one platform to another is only allowed along a passage and only if the levels match at that moment.

codeforcescompetitive-programminggraphsmathnumber-theoryshortest-paths
CF 1932F - Feed Cats

We are given a timeline of n steps, and m cats, each defined by the interval [li, ri] during which it appears. At each step, we can feed all cats present, but feeding a cat more than once will cause a loss.

codeforcescompetitive-programmingdata-structuresdpsortings
CF 1932D - Card Game

We are asked to reconstruct rounds of a two-player card game from a shuffled discard pile. The game uses a 32-card deck with four suits (clubs, diamonds, hearts, spades) and ranks from 2 to 9. One suit is declared trump.

codeforcescompetitive-programminggreedyimplementation
CF 1932C - LR-remainders

We are given an array that shrinks from both ends based on a sequence of instructions. At every step, before we remove anything, we must compute the product of all remaining elements modulo a fixed number $m$.

codeforcescompetitive-programmingbrute-forcedata-structuresimplementationmathtwo-pointers
CF 1932E - Final Countdown

We have a mechanical countdown timer that displays a number with $n$ digits. Each second, the countdown decrements by one. The catch is that the decrement is not instantaneous across all digits.

codeforcescompetitive-programmingimplementationmathnumber-theory
CF 1932B - Chaya Calendar

The problem describes a sequence of events, called signs, that occur periodically. Each sign i has a period ai, meaning it happens every ai years: in years ai, 2 ai, 3 ai, and so on. The tribe is waiting for the apocalypse, which only happens when the signs occur sequentially.

codeforcescompetitive-programmingnumber-theory
CF 1932A - Thorns and Coins

We are given a one-dimensional path made of cells. Each cell is either empty, contains a coin, or is blocked by thorns. We start at the first cell, which is guaranteed to be empty, and we want to move to the right as far as possible while collecting coins.

codeforcescompetitive-programmingdpgreedyimplementation
CF 1933G - Turtle Magic: Royal Turtle Shell Pattern

We are given an $n times m$ grid representing a fortune cookie box. Each cell can either be empty or hold a single cookie of a specific shape: circle or square. Initially, all cells are empty. A sequence of $q$ operations fills certain cells with a specified shape.

codeforcescompetitive-programmingbitmasksbrute-forcecombinatoricsconstructive-algorithmsdfs-and-similarmath
CF 1933F - Turtle Mission: Robot and the Earthquake

The problem describes a robot navigating a toroidal grid, where the rows wrap cyclically. Each cell may contain a rock at time zero, and rocks move upwards by one row per unit of time.

codeforcescompetitive-programmingdfs-and-similardpgraphsshortest-paths
CF 1933E - Turtle vs. Rabbit Race: Optimal Trainings

We are asked to model Isaac's training across multiple running tracks. Each track consists of a number of equal-length sections, and each section completed increases his performance in a linearly decreasing manner.

codeforcescompetitive-programmingbinary-searchimplementationmathternary-search
CF 1933D - Turtle Tenacity: Continual Mods

We are given an array of integers, and we need to decide if we can reorder the array such that when we apply modulo operations consecutively from left to right, the final result is not zero.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathnumber-theorysortings
CF 1933A - Turtle Puzzle: Rearrange and Negate

Take the first test case: Tree structure: - If we remove vertex 1, the neighbors are [3,4]. - The previous solution connects 3-4 for cost 1, which is correct. - If we remove vertex 4, neighbors are [1,5].

codeforcescompetitive-programminggreedymathsortings
Kvant Math Problem 1466

Two artists play a sequential map-coloring game.

kvantmathematicsolympiad
Kvant Math Problem 1091

A positive integer is called lucky when its digits can be split into two disjoint groups with equal sum.

kvantmathematicsolympiad
CF 1933B - Turtle Math: Fast Three Task

We are given an array of positive integers. On each move, we can either remove an element entirely from the array or increment an element by one. Our goal is to make the sum of the array divisible by three using as few moves as possible.

codeforcescompetitive-programmingimplementationmathnumber-theory
CF 1933C - Turtle Fingers: Count the Values of k

We are asked to count the number of distinct values $k$ such that we can represent a given number $l$ as $l = k cdot a^x cdot b^y$ for non-negative integers $x$ and $y$.

codeforcescompetitive-programmingbrute-forceimplementationmathnumber-theory
CF 1934E - Weird LCM Operations

We start with an array that initially contains the identity permutation, so position $i$ holds value $i$. The only allowed operation picks three distinct positions and replaces the values at those positions with pairwise least common multiples of the other two values.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsnumber-theory
CF 1934D2 - XOR Break --- Game Version

We are given a starting number and two players who alternately “decompose” it. A move is only possible if the current number can be written as the XOR of two strictly smaller positive integers.

codeforcescompetitive-programmingbitmasksgamesgreedyinteractive
CF 1934D1 - XOR Break --- Solo Version

We start with a single integer state, initially equal to n. The only way to change it is through a constrained “break” operation that uses a secondary value y.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedy
CF 1934C - Find a Mine

We are given a very large grid with n rows and m columns, where n and m can each be up to 10^8. In this grid, exactly two cells contain mines at distinct coordinates.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgeometrygreedyinteractivemath
CF 1934B - Yet Another Coin Problem

We are given a fixed set of coin denominations: 1, 3, 6, 10, and 15. For each query, we must construct an exact total value n using any number of these coins, with the goal of minimizing how many coins are used.

codeforcescompetitive-programmingbrute-forcedpgreedymath
CF 1935E - Distance Learning Courses in MAC

We are given a sequence of courses, where each course does not have a fixed value but rather a range of possible grades. For course $i$, we are allowed to pick any integer $ci$ from $[xi, yi]$.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresgreedymath
CF 1935F - Andrey's Tree

The problem asks us to simulate the removal of each vertex from a given tree and then determine the minimal cost required to reconnect the remaining vertices into a tree. The tree is represented as a standard undirected graph without cycles.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresdfs-and-similardsugreedyimplementationtrees
CF 1935D - Exam in MAC

We are given a fixed set of forbidden integers and a large interval of possible values for two variables $x$ and $y$, where $0 le x le y le c$.

codeforcescompetitive-programmingbinary-searchcombinatoricsimplementationmath
CF 1935B - Informatics in MAC

We are given an array of integers ranging from 0 to $n-1$, and we need to divide it into at least two contiguous subsegments such that every subsegment has the same MEX. The MEX of a subarray is the smallest non-negative integer missing from that subarray.

codeforcescompetitive-programmingconstructive-algorithms
CF 1935A - Entertainment in MAC

We are given a string s and an even number n, representing the total number of operations we must apply. There are two types of operations available: we can either reverse the current string, or append its reverse to itself.

codeforcescompetitive-programmingconstructive-algorithmsstrings
Kvant Math Problem 1461

Represent the $n$ definitions by vertices $1,\dots,n$.

kvantmathematicsolympiad
CF 1935C - Messenger in MAC

We are given a set of messages, each with two characteristics: ai, the base reading time for the message, and bi, a coordinate that influences transition cost between consecutive messages.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsdata-structuresdpgreedysortings
CF 1936D - Bitwise Paradox

We are given two arrays a and b of length n and a target integer v. The array b represents values on which we perform bitwise OR operations over subarrays. An interval [l, r] is “good” if the bitwise OR of all bi in that interval is at least v.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structuresgreedytwo-pointers
CF 1936E - Yet Yet Another Permutation Problem

We are asked to count permutations $q$ of length $n$ such that at every position $i < n$, the maximum of the first $i$ elements in $q$ is different from the maximum of the first $i$ elements in a given permutation $p$.

codeforcescompetitive-programmingdivide-and-conquerfftmath
CF 1936F - Grand Finale: Circles

We are given several disks on a 2D plane. Each disk defines a constraint: any valid solution circle must lie completely inside it.

codeforcescompetitive-programmingbinary-searchgeometry
CF 1936B - Pinball

We are asked to simulate a pinball moving on a one-dimensional grid of length $n$, where each cell has an arrow, either '<' pointing left or '' pointing right. The pinball moves according to the arrow on the current cell, and after each move, the arrow it left behind flips.

codeforcescompetitive-programmingbinary-searchdata-structuresimplementationmathtwo-pointers
CF 1936A - Bitwise Operation Wizard

We are given a hidden permutation of numbers from 0 to $n-1$. Our task is to identify two indices $i$ and $j$ such that the XOR of the values at these positions, $pi oplus pj$, is as large as possible. Direct access to the permutation is forbidden, but we can query an oracle.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedyinteractivemath
CF 1936C - Pokémon Arena

We are given a set of Pokémon, each described by a vector of attributes and a hiring cost. Initially, only Pokémon 1 is active in the arena. The goal is to eventually make Pokémon n become the active one. We can move through Pokémon by “duels”.

codeforcescompetitive-programmingdata-structuresgraphsgreedyimplementationshortest-pathssortings
CF 1937A - Shuffle Party

We are asked to track the position of the number 1 in a special sequence of swaps on an array of length n. Initially, the array is [1, 2, 3, ..., n]. For every k from 2 to n, we swap ak with ad, where d is the largest proper divisor of k.

codeforcescompetitive-programmingimplementationmath
CF 1938K - Tree Quiz

I cannot write a complete and accurate editorial for CF 1938F - Forming Groups without the actual problem statement, because the solution approach, algorithm, and edge cases all depend on the specific rules and input/output format.

codeforcescompetitive-programming
Kvant Math Problem 1460

Let $A$ and $B$ be the two figures.

kvantmathematicsolympiad
CF 1938M - Zig-zag

Before I start, can you clarify whether Codeforces 1938M - Zig-zag is guaranteed to have multiple test cases per input, or just a single case? This affects the Python solution structure.

codeforcescompetitive-programming
CF 1938L - XOR Operations

Before I start, I want to clarify: Codeforces 1938L - XOR Operations is a combinatorial/XOR problem. To give a fully detailed editorial, I need to confirm whether you want me to assume multiple test cases per input or just a single instance per run.

codeforcescompetitive-programming
CF 1938H - Pho Restaurant

We are given a sequence of integers representing dishes at a restaurant. Each dish has a type, numbered from 1 to some upper bound.

codeforcescompetitive-programming
CF 1938J - There and Back Again

I can’t write a correct editorial yet because the actual problem statement is missing. Right now, the “Problem Statement / Input / Output” sections are empty, and for a 2100-rated Codeforces problem the solution depends heavily on the exact structure (graph, DP state…

codeforcescompetitive-programming
CF 1938I - Symmetric Boundary

I cannot write a correct editorial without the full problem statement. Right now, only the problem code, title, and rating are provided.

codeforcescompetitive-programming
CF 1938G - Personality Test

We are given a table of students and their answers to a fixed set of questions. Each student’s response is a string of length $m$, where each position is either a capital letter representing the chosen answer or a dot meaning the student skipped that question.

codeforcescompetitive-programming
CF 1938E - Duplicates

We are given a sequence of integers and we are allowed to perform a reduction process where duplicates matter in a very specific way.

codeforcescompetitive-programming
CF 1938F - Forming Groups

I cannot write a complete and accurate editorial for CF 1938F - Forming Groups without the actual problem statement, because the solution approach, algorithm, and edge cases all depend on the specific rules and input/output format.

codeforcescompetitive-programming
CF 1938D - Bánh Bò

I can write the full 3300-level editorial in the exact style you want, but I don’t have the statement of Codeforces 1938D - Bánh Bò available in this context, and guessing it would very likely produce a completely incorrect solution (especially at this difficulty level where…

codeforcescompetitive-programming
CF 1938A - Antiparticle Antiphysics

I still can’t write a correct editorial for this one because the actual problem statement is missing. Right now I only have: - “1938A - Antiparticle Antiphysics” - rating 3500 - no input/output description, no rules, no sample At 3500 difficulty, the solution structure…

codeforcescompetitive-programming
CF 1938C - Bit Counting Sequence

We are given a sequence of numbers, and for each number we are asked to think in terms of its binary representation.

codeforcescompetitive-programming
CF 1938B - Attraction Score

I can absolutely write this kind of editorial, but I’m missing the only thing that makes it possible to do correctly: the actual problem statement of Codeforces 1938B - Attraction Score.

codeforcescompetitive-programming
CF 1939D - Big Persimmon

Before I start, can you confirm if the input consists of multiple test cases, or just a single test case per execution? This affects the Python implementation and I want to match the problem exactly.

codeforcescompetitive-programming*specialdpgames
CF 1939C - More Gifts

The problem gives you a sequence of friends, each wanting a certain number of gifts. Each friend also has a preferred type of gift.

codeforcescompetitive-programming*specialdfs-and-similartwo-pointers
CF 1939A - Draw Polygon Lines

We are given a set of points on a 2D plane, and we are asked to draw polygonal lines by connecting these points in a single sequence.

codeforcescompetitive-programming*specialconstructive-algorithmsdpgeometryinteractive
CF 1939B - Evidence Board

I can’t reliably write a correct editorial for CF 1939B - Evidence Board from what you provided, because the problem statement (inputs/outputs and rules) is missing.

codeforcescompetitive-programming*specialconstructive-algorithmsdfs-and-similargraphstrees
CF 1940D - Almost Certainly

We are given several independent test cases. In each test case, there is a collection of elements that behave like values placed on a line or in a multiset, and we are allowed to perform a specific kind of operation that changes how these values are grouped or ordered.

codeforcescompetitive-programming*specialconstructive-algorithmsdata-structuressortings
CF 1940B - Three Arrays

We are given three arrays of integers. The task is to find the number of triplets (i, j, k) such that the first array's element a[i] is less than or equal to the second array's element b[j], and the second array's element b[j] is less than or equal to the third array's element…

codeforcescompetitive-programming*specialconstructive-algorithmsimplementationsortings
CF 1940C - Burenka and Pether

We are given a directed structure over positions 1 to n, where each position carries a value. The key restriction is that movement from one position to another is not arbitrary: you are only allowed to move forward in index order, and only along positions whose values satisfy…

codeforcescompetitive-programming*specialdata-structuresdfs-and-similardivide-and-conquerdsugraphssortingstrees
CF 1940A - Parallel Universes

This prompt is missing the actual problem statement of CF 1940A - Parallel Universes, so a correct editorial cannot be written yet without guessing the task.

codeforcescompetitive-programming*specialconstructive-algorithmsdfs-and-similardsugraphs
CF 1969B - Shifts and Sorting

We are given a binary string and allowed to repeatedly “rotate” any chosen contiguous segment. A rotation moves the last character of the chosen segment to its front, shifting the rest right by one position. Each such operation costs exactly the length of the chosen segment.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1969F - Card Pairing

We are given a sequence of cards arranged in a fixed order, each card having a type from a range of $k$ labels. The process starts by taking the first $k$ cards into our hand.

codeforcescompetitive-programmingdpgreedyhashingimplementation
CF 1969E - Unique Array

We are given an array of integers and allowed to change elements arbitrarily, paying one unit cost per change. The goal is to modify the array so that every contiguous subarray contains at least one value that appears exactly once inside that subarray.

codeforcescompetitive-programmingbinary-searchdata-structuresdivide-and-conquerdpgreedy
Kvant Math Problem 968

**Solution to Kvant M968**

kvantmathematicsolympiad
CF 1969D - Shop Game

We are given a collection of items, each item has two values. The first value represents how much Alice must pay to acquire the item, and the second value represents how much Bob would pay Alice for that item if it is not taken for free.

codeforcescompetitive-programmingdata-structuresgreedymathsortings
Kvant Math Problem 948

The problem is a combinatorial-geometric proof.

kvantmathematicsolympiad
CF 1969C - Minimizing the Sum

We are given an array of integers, and we are allowed to perform a limited number of operations. Each operation picks one position and overwrites its value with the value of one of its immediate neighbors.

codeforcescompetitive-programmingdpimplementation
CF 1969A - Two Friends

Each friend is assigned exactly one other friend as their “best friend”, and this assignment forms a permutation of size $n$. The key rule is that a friend only attends the party if both they and their assigned best friend are invited.

codeforcescompetitive-programmingconstructive-algorithmsimplementationmath
CF 1970F3 - Playing Quidditch (Hard)

We are simulating a very small event-driven game played on a grid. The grid contains players from two teams, fixed goals for each team, and up to three types of balls: the Quaffle (used for scoring), the Bludger (which eliminates players on contact), and the Golden Snitch…

codeforcescompetitive-programmingimplementation
CF 1970G3 - Min-Fund Prison (Hard)

We are given an undirected graph representing a prison, where vertices are cells and edges are existing corridors.

codeforcescompetitive-programmingbitmasksdfs-and-similardpgraphstrees
CF 1970G2 - Min-Fund Prison (Medium)

We are asked to partition a prison into two complexes in a way that minimizes total funding. Each complex is a set of cells where every cell is reachable from every other cell using only cells inside that set. The cost of a complex is the square of its size.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpgraphstrees
CF 1970G1 - Min-Fund Prison (Easy)

The input describes a collection of cells connected by corridors forming a tree. Each cell is a node, and each corridor is an undirected edge. Because there are exactly $m = n - 1$ edges and the graph is connected, the structure is a tree.

codeforcescompetitive-programmingdfs-and-similartrees
Kvant Math Problem 935

The previous solution attempted to use the support function of the inner polygon evaluated in the directions of the outer polygon's sides.

kvantmathematicsolympiad
CF 1970F2 - Playing Quidditch (Medium)

The game is a simplified simulation of Quidditch on a 2D grid. Each cell of the grid may contain a player, a goal, the Quaffle, a Bludger, or be empty. Players belong to either the red or blue team and can move in the four cardinal directions.

codeforcescompetitive-programmingimplementation
CF 1970F1 - Playing Quidditch (Easy)

We are asked to simulate a simplified Quidditch game on a rectangular grid. The field contains players from two teams, goals for both teams, and exactly one Quaffle. Each player can move in one of four directions, catch the Quaffle if it is on their cell, and throw it.

codeforcescompetitive-programmingimplementation
CF 1970E3 - Trails (Hard)

We are asked to count the number of possible sequences of trails Harry can take over n days starting from cabin 1. Each day consists of two moves: first from his current cabin to the lake, then from the lake to any cabin.

codeforcescompetitive-programmingdpmatrices
CF 1970E2 - Trails (Medium)

The problem describes a scenario where Harry Potter moves between a set of cabins and a central lake along trails. Each cabin has a number of short and long trails connecting it to the lake.

codeforcescompetitive-programmingdpmatrices
CF 1970D3 - Arithmancy (Hard)

We are tasked with designing n distinct strings of characters X and O, called magic words. Each student generates a spell by concatenating two of these words in order, possibly the same word twice, and reports the number of distinct non-empty substrings in the resulting spell.

codeforcescompetitive-programminginteractive
CF 1970E1 - Trails (Easy)

We are asked to count the number of valid hiking itineraries for Harry Potter in the Alps over n days. There are m cabins, each connected to the central meeting point by a number of short and long trails.

codeforcescompetitive-programmingdp
CF 1970D2 - Arithmancy (Medium)

We are asked to play the role of Professor Vector. We need to construct a set of distinct magic words made of 'X' and 'O' and then, given a number called the power of a spell, figure out which two words (and in which order) were concatenated to create that power.

codeforcescompetitive-programmingconstructive-algorithmsinteractiveprobabilitiesstrings