brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 2035H - Peak Productivity Forces

We are given two permutations of the same size and a very unusual operation that modifies the array in two independent segments split at a chosen index.

codeforcescompetitive-programmingconstructive-algorithms
CF 2035G2 - Go Learn! (Hard Version)

We are given an array of length $n$, but its values are not fixed. Instead, we must construct it. Alongside this, we are given $m$ constraints.

codeforcescompetitive-programmingdivide-and-conquerdp
Kvant Math Problem 2846

The word “ПЕТЯ” has five letters.

kvantmathematicsolympiad
CF 2035G1 - Go Learn! (Easy Version)

I can't provide a correct editorial and implementation for this problem from first principles without deriving and verifying the full dynamic programming recurrence.

codeforcescompetitive-programmingdptrees
CF 2035F - Tree Operations

We are given a rooted tree with n nodes, each carrying an initial nonnegative value. The task is to reduce all node values to zero using operations that are applied in a fixed cyclic order on the nodes: the first n operations are applied to nodes 1 through n sequentially, and…

codeforcescompetitive-programmingbinary-searchbrute-forcedfs-and-similardptrees
CF 2035E - Monster

We are fighting a monster with z health points using a weapon whose damage starts at zero. We can perform two operations: increase the weapon’s damage by one at a cost of x coins, or attack the monster for d damage at a cost of y coins.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsgreedyimplementationmathternary-search
CF 2035D - Yet Another Real Number Problem

We are given an array of integers and allowed to perform operations that move powers of two from one element to a later element in the array. Specifically, if an element is even, we can divide it by two and multiply a later element by two.

codeforcescompetitive-programmingbinary-searchdata-structuresdivide-and-conquergreedyimplementationmath
CF 2035C - Alya and Permutation

We are asked to construct a permutation of numbers from 1 to $n$ in a way that maximizes a value $k$ after a sequence of bitwise operations.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsmath
CF 2035A - Sliding

We are given a rectangular grid with $n$ rows and $m$ columns. Every cell contains one person, and these people are numbered from 1 to $nm$ in row-major order, meaning numbering proceeds left to right within a row and then continues to the next row.

codeforcescompetitive-programmingimplementationmath
CF 2035B - Everyone Loves Tres

We are asked to construct the smallest decimal number of length $n$ that consists only of digits $3$ and $6$, such that it is divisible by both $33$ and $66$.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathnumber-theory
CF 2141F - Array Reduction

Working

codeforcescompetitive-programming*specialgreedy
CF 2141E - Perfect Cut

The symptom here is actually very clear from the input/output pair: You are giving permutations, and the expected outputs are: But a correct inversion-counting or monotonic-feasibility solution would never produce those values.

codeforcescompetitive-programming*specialdpgreedy
CF 2141G - Good Robot Paths

We are given a set of black points on a Cartesian plane, each with integer coordinates. A robot can move up, down, left, or right by one unit per command.

codeforcescompetitive-programming*specialdata-structuresgeometrysortings
CF 2141B - Games

Two players each maintain a fixed sorted list of games they enjoy. They do not immediately know which common game to pick, so they go through a deterministic alternating process of suggesting games they personally like, one at a time, without repeating any suggestion.

codeforcescompetitive-programming*specialgreedy
CF 2141D - Avoid Minimums

Our systems have detected unusual activity coming from your system. Please try again later.

codeforcescompetitive-programming*specialgreedymath
Kvant Math Problem 2802

Let

kvantmathematicsolympiad
CF 2128F - Strict Triangle

We are given an undirected, connected graph with $n$ nodes and $m$ edges, where each edge has a weight that is not fixed but lies in a given interval $[li, ri]$.

codeforcescompetitive-programminggraphsgreedyshortest-paths
CF 2128E2 - Submedians (Hard Version)

We are asked to identify submedians in an array. More concretely, for each integer in the array range $1$ to $n$, we want to determine whether there exists a contiguous subarray of length at least $k$ such that the integer is a median of that subarray.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresmathtwo-pointers
CF 2128D - Sum of LDS

The failure you’re seeing is not an algorithmic issue at all. It’s a complete breakdown of input handling consistency across the solution.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpgreedymath
CF 2128B - Deque Process

We are given a permutation of numbers, and we build a new sequence by repeatedly removing either the leftmost or rightmost remaining element. This produces a sequence of length n, but we are free to decide at each step whether to take from the left or the right.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortingstwo-pointers
CF 2128E1 - Submedians (Easy Version)

We are given an array and a length constraint $k$. From this array, we want to select a contiguous segment of length at least $k$.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedymath
CF 2127G2 - Inter Active (Hard Version)

We are dealing with a hidden structure, a permutation of size $n$, where every position points to exactly one value and no value repeats. There is an additional restriction that no element stays in its original position, so the permutation contains no fixed points.

codeforcescompetitive-programmingbinary-searchbitmasksconstructive-algorithmsgraphsimplementationinteractivemathprobabilities
CF 2127F - Hamed and AghaBalaSar

You’re not dealing with a “small bug anymore” - the issue is that the last solution implicitly solved a different problem (monotone feasibility) than the one your samples are testing. We can prove that directly from the third failing case.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpmathprobabilities
CF 2127G1 - Inter Active (Easy Version)

We are given a hidden permutation of size $n$, with the additional promise that no element stays in its own position. So every index points to a different value, and every value appears exactly once. We cannot see this permutation directly.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsinteractiveprobabilities
CF 2127E - Ancient Tree

We are given a rooted tree with weighted vertices, where each vertex either has a fixed color between 1 and k or a missing color represented by 0. The goal is to assign colors to all uncolored vertices to minimize the total weight of "cutie" vertices.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdfs-and-similardsugreedytrees
CF 2127D - Root was Built by Love, Broken by Destiny

We are given a connected undirected graph of n houses and m bridges. Each bridge must connect one house on the northern side of a river to one house on the southern side.

codeforcescompetitive-programmingcombinatoricsdfs-and-similargraphstrees
CF 2127A - Mix Mex Max

At this point the failures are not coming from “a small bug in transitions” or “a corner case in logic”. They come from a much simpler fact: The code you are running is not implementing the problem you are testing. We can prove this directly from your sample.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
Kvant Math Problem 1594

The functional equation is

kvantmathematicsolympiad
CF 2127C - Trip Shopping

We are given two arrays of integers, a and b, representing prices of items in two categories. The game consists of k rounds. In each round, Ali selects two indices, and Bahamin can rearrange the four numbers at those indices arbitrarily, even swapping elements between arrays.

codeforcescompetitive-programminggamesgreedysortings
CF 2127B - Hamiiid, Haaamid... Hamid?

We are given a one-dimensional grid of length n, with some cells containing walls and others empty. Hamid is standing on one empty cell, and every day two things happen: first Mani places a wall on an empty cell not currently occupied by Hamid, then Hamid chooses a direction…

codeforcescompetitive-programminggamesgreedy
CF 2117H - Incessant Rain

We are given an array of integers and a sequence of queries. Each query updates a single element of the array, and after the update, we are asked for the maximum integer $k$ such that some subarray contains a $k$-majority.

codeforcescompetitive-programmingdata-structuresdivide-and-conquersortings
CF 2117F - Wildflower

We are given a rooted tree where vertex 1 is the root, and every node must be assigned a value either 1 or 2. Once these values are fixed, every node computes a quantity defined as the sum of values in its rooted subtree, meaning the node itself plus all of its descendants.

codeforcescompetitive-programmingcombinatoricsdfs-and-similartrees
CF 2117E - Lost Soul

The repeated runtime errors you are seeing are all caused by misaligned assumptions about the input format. Let me go step by step. Looking at your input: The first line 5 is the number of test cases.

codeforcescompetitive-programmingbrute-forcegreedy
CF 2117G - Omg Graph

We are working with a weighted undirected connected graph where we need to travel from node 1 to node n. Every path is allowed to revisit vertices and edges, so cycles are permitted.

codeforcescompetitive-programmingbrute-forcedsugraphsgreedyshortest-pathssortings
CF 2117C - Cool Partition

We are given an array of integers and need to divide it into contiguous segments. Each element must appear in exactly one segment. A partition is considered cool if every element in a segment also appears in the next segment, if there is one.

codeforcescompetitive-programmingdata-structuresgreedy
CF 2117B - Shrink

The task is to construct a permutation of length $n$ that allows the maximum number of "shrink" operations. A shrink operation removes an element that is larger than its immediate neighbors.

codeforcescompetitive-programmingconstructive-algorithms
Kvant Math Problem 1559

Let the given plane be $\Pi$.

kvantmathematicsolympiad
CF 2115F2 - Gellyfish and Lycoris Radiata (Hard Version)

We are asked to maintain an array of sets, starting empty, under three types of modification operations: inserting the current operation index into a prefix of sets, reversing a prefix of sets, and deleting a given element from all sets.

codeforcescompetitive-programmingdata-structures
CF 2115D - Gellyfish and Forget-Me-Not

For two odd-index cells $A(x1,y1)$, $B(x2,y2)$, we need to count the number of cells $C$ such that: - $C$ is adjacent to $A$ - $C$ is adjacent to $B$ - and $A ne B ne C$ On a grid, this intersection has a known structure: - If $A$ and $B$ differ by 2 in one coordinate and 0 in…

codeforcescompetitive-programmingbitmasksdpgamesgreedymath
CF 2115B - Gellyfish and Camellia Japonica

We are given a final array b that results from a sequence of q operations on an initial array a. Each operation selects two positions x and y, takes the minimum of their current values, and assigns it to a third position z.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similardpgraphsgreedytrees
CF 2115C - Gellyfish and Eternal Violet

We are given a group of monsters, each starting with some integer health value. Over a fixed number of rounds, we interact with a probabilistic weapon that sometimes performs a global action and sometimes allows a targeted action.

codeforcescompetitive-programmingcombinatoricsdpgreedymathprobabilities
CF 2098A - Vadim's Collection

We are given a string of exactly ten digits representing a phone number that satisfies a "beauty" condition: the first digit is at least 9, the second at least 8, and so on down to the last digit, which is at least 0.

codeforcescompetitive-programmingbrute-forcegreedy
CF 2097E - Clearing the Snowdrift

We are given a runway divided into n sections, each covered with some snow. The snow in the i-th section has height ai. A snowplow can operate on any contiguous segment of at most length d.

codeforcescompetitive-programmingdata-structuresdfs-and-similardpgreedy
CF 2097D - Homework

We are given two binary strings of the same length, and we are allowed to repeatedly apply a very specific transformation that acts on halves of substrings and mixes corresponding bits using XOR-like behavior.

codeforcescompetitive-programmingbitmasksmathmatrices
CF 2097B - Baggage Claim

The task is to reconstruct a simple path on a rectangular grid where only the cells with odd indices are known. Specifically, the path alternates between "known" and "unknown" cells, starting and ending with known cells.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardpdsugraphsimplementationmathtrees
CF 2097C - Bermuda Triangle

The plane moves inside a right triangle with corners at $(0,0)$, $(n,0)$, and $(0,n)$. The aircraft starts strictly inside this triangle at $(x,y)$ and moves with a constant velocity vector $(vx, vy)$.

codeforcescompetitive-programmingchinese-remainder-theoremgeometryimplementationmathnumber-theory
CF 2097A - Sports Betting

We are given several independent scenarios. In each scenario, there are multiple students, and for each student we are told a day $ai$.

codeforcescompetitive-programming2-satbrute-forcemathsortings
Kvant Math Problem 1524

Let the incenters of the triangles $ABP$, $BCP$, $CDP$, $DAP$ be $X,Y,Z,W$ respectively.

kvantmathematicsolympiad
CF 2066F - Curse

We are given two arrays of integers, a and b, and we are asked whether we can transform a into b using a very particular operation.

codeforcescompetitive-programmingconstructive-algorithmsdpmath
CF 2066D2 - Club of Young Aircraft Builders (hard version)

We are asked to restore missing information in a sequence of airplane launches by residents in a building. Each floor has exactly one resident, and the residents launch paper airplanes sequentially.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 2066E - Tropical Season

We are given a changing multiset of barrel volumes. Each barrel has a numeric value, and exactly one barrel is “special” in the sense that it carries an invisible poison.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedyimplementation
CF 2066D1 - Club of Young Aircraft Builders (easy version)

We are asked to count the number of valid sequences of airplane launches from a building with n floors. Each floor has exactly one resident, and all residents want to collectively launch at least c airplanes. The building has m total launches.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 2066A - Object Identification

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programminggraphsgreedyimplementationinteractive
CF 2066C - Bitwise Slides

We are building a process that evolves three integers, initially all zero. We read an array from left to right, and for each element we must assign it to exactly one of the three variables. Assigning means XORing that value into the chosen variable.

codeforcescompetitive-programmingbitmaskscombinatoricsdpmath
CF 2066B - White Magic

We are given an array of non-negative integers, and we are allowed to pick a subsequence from it. From that subsequence, we want to keep as many elements as possible while ensuring a very specific prefix-suffix condition holds at every split point.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdpgreedyimplementation
CF 2060G - Bugged Sort

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programmingdpgreedysortings
CF 2060F - Multiplicative Arrays

We are asked to count arrays of integers where the product of all elements equals a specific target number. More concretely, for given integers $k$ and $n$, we need to determine, for every number $x$ from $1$ to $k$, how many arrays $a$ exist such that each element is between…

codeforcescompetitive-programmingcombinatoricsdpnumber-theory
CF 2060E - Graph Composition

We are given two undirected graphs on the same set of vertices. One graph, call it the working graph, is the structure we are allowed to modify. The second graph is a fixed reference structure that we must eventually “match” in terms of connectivity.

codeforcescompetitive-programmingdfs-and-similardsugraphsgreedy
CF 2060D - Subtract Min Sort

We are given an array of positive integers. We are allowed to repeatedly choose two adjacent elements and perform a “balancing subtraction” operation: we look at a pair, subtract the smaller value from both entries, and continue.

codeforcescompetitive-programminggreedy
CF 2060B - Farmer John's Card Game

We are given several independent test cases. In each one, a set of cows holds disjoint collections of cards, and every card has a unique integer value across all cows.

codeforcescompetitive-programminggreedysortings
CF 2060A - Fibonacciness

We are given four known values that represent an array of five integers with the middle element missing. The missing position is the third one, and we are free to choose any integer value for it, including negatives or zero.

codeforcescompetitive-programmingbrute-force
CF 2038G - Guess One Character

We are given an interactive problem where the judge has a hidden binary string s of length n. Our goal is to identify at least one character in s by asking up to three queries per test case. Each query asks how many times a binary substring t occurs contiguously in s.

codeforcescompetitive-programmingconstructive-algorithmsimplementationinteractive
CF 2038N - Fixing the Expression

We are given a very small expression of fixed length three. The first and last characters are digits, and the middle character is a comparison operator: less than, equal, or greater than.

codeforcescompetitive-programmingimplementation
CF 2038M - Royal Flush

We are repeatedly simulating a constrained card game where the only thing that ultimately matters is whether we ever manage to hold a very specific 5-card pattern: the Royal Flush of some suit.

codeforcescompetitive-programmingdpimplementation
Kvant Math Problem 1501

For small $x$, the functions admit linear approximations $\sin(kx)\sim kx$ and $\sin x\sim x$.

kvantmathematicsolympiad
CF 2038E - Barrels

We are asked to maximize the water volume in the first of a sequence of connected barrels by adding clay into any barrel. Each barrel has a water column, and adjacent barrels are connected by horizontal pipes at given heights.

codeforcescompetitive-programmingdata-structuresgreedymath
CF 2038F - Alternative Platforms

We are given a collection of bloggers, where each blogger has two independent activity counts: how many videos they uploaded to platform A and how many to platform B. A user does not necessarily watch all bloggers equally.

codeforcescompetitive-programmingcombinatoricsdata-structuresfftmathsortings
CF 2038D - Divide OR Conquer

We are given an array of integers and asked to count the number of ways to partition it into contiguous subarrays such that the bitwise OR of each subarray is non-decreasing from left to right. Each element must belong to exactly one subarray.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structuresdpimplementation
CF 2038C - DIY

We are given a list of integers, and each integer can represent either an x-coordinate or a y-coordinate. The task is to choose eight integers from this list and form four points in the 2D plane so that these four points become the corners of a rectangle whose sides are…

codeforcescompetitive-programmingdata-structuresgeometrygreedysortings
CF 2038A - Bonus Project

We have a team of engineers, each with a promised bonus and a personal cost for doing one unit of work. The team needs to complete a project that requires exactly $k$ units of work, and every engineer will decide individually how much to contribute.

codeforcescompetitive-programminggamesgreedy
CF 2038B - Make It Equal

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programmingbinary-searchbrute-forcegreedymath
Kvant Math Problem 1469

Each integer $n$ with exactly three ones in binary has the form

kvantmathematicsolympiad
CF 2036G - Library of Magic

We are dealing with a very large universe of book types, from 1 up to n where n can be as large as 10^18. Every type normally appears exactly twice in a hidden collection.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdivide-and-conquerinteractivemathnumber-theory
CF 2036D - I Love 1543

The input describes several rectangular grids of digits. Each grid is split conceptually into concentric “rings” or layers, starting from the outer border and moving inward. Every layer forms a closed cycle if you walk along its border clockwise.

codeforcescompetitive-programmingbrute-forceimplementationmatrices
CF 2036F - XORificator 3000

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programmingbitmasksdpnumber-theorytwo-pointers
CF 2036E - Reverse the Rivers

We are given a world with n countries, each divided into k regions, where each region has an initial water value a[i][j]. The sages have built channels so that water in a region flows downstream through countries in the same region index.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedy
CF 2036B - Startup

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programminggreedysortings
CF 2036C - Anya and 1100

We are given a binary string that changes over time. Each query updates a single position, flipping that character to either 0 or 1. After every update, we must answer a very specific question: does the current string contain the pattern “1100” as a contiguous block anywhere?

codeforcescompetitive-programmingbrute-forceimplementation
CF 2036A - Quintomania

A melody here is just a short sequence of integer pitches. Each pitch is an integer between 0 and 127, and what matters is not the absolute values but the differences between neighboring notes.

codeforcescompetitive-programmingimplementation
Kvant Math Problem 953

Each special point is an intersection of three lines determined by pairs of the six given points.

kvantmathematicsolympiad
CF 2037G - Natlan Exploring

We are asked to count the number of distinct paths from the first city to the last city in a region of Natlan, where each city has an attractiveness value. The paths follow a simple rule: from city $i$ you can travel to city $j$ if $i < j$ and $gcd(ai, aj) neq 1$.

codeforcescompetitive-programmingbitmaskscombinatoricsdata-structuresdpmathnumber-theory
CF 2037E - Kachina's Favorite Binary String

We are tasked with reconstructing a hidden binary string of length $n$ by querying a function $f(l, r)$, which counts the number of subsequences "01" in the substring from index $l$ to $r$. A subsequence is any selection of characters maintaining the original order.

codeforcescompetitive-programmingdpgreedyinteractivetwo-pointers
CF 2037D - Sharky Surfing

We are asked to model a surfboard journey along a one-dimensional path from position 1 to position $L$. Mualani starts with jump power 1, which allows her to move from her current position $x$ to any position in $[x, x+k]$, where $k$ is her current jump power.

codeforcescompetitive-programmingdata-structuresgreedytwo-pointers
CF 2037F - Ardent Flames

We are given a line of enemies, each with a fixed health and a fixed position. Xilonen can attack from a single chosen position p, and each attack reduces an enemy’s health by m - The first key observation is that the damage from each attack decreases linearly with distance.

codeforcescompetitive-programmingbinary-searchdata-structuresmathsortingstwo-pointers
CF 2037C - Superultra's Favorite Permutation

We are asked to construct a permutation of numbers from 1 to n such that the sum of every pair of consecutive numbers is composite. In other words, for a permutation p of length n, every p[i] + p[i+1] must not be a prime. If no such permutation exists, we return -1.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathnumber-theory
CF 2037A - Twice

We are given a small array of integers. Kinich can score points by repeatedly selecting two distinct indices containing equal values, with the restriction that each index can be used at most once. The task is to determine the maximum number of such pairings for each test case.

codeforcescompetitive-programmingimplementation
CF 2037B - Intercepted Inputs

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programmingbrute-forceimplementation
CF 2038L - Bridge Renovation

We are asked to compute the minimum number of standard-length planks, each 60 units long, needed to cover three bridges that have different widths. Each bridge requires n planks to span its width: the first bridge needs planks of length 18, the second 21, and the third 25.

codeforcescompetitive-programmingbrute-forcedpgreedymathtwo-pointers
Kvant Math Problem 851

Place the square in a coordinate system so that computations can be expressed in terms of two parameters.

kvantmathematicsolympiad
CF 2038H - Galactic Council

Each turn in this game is a small strategic decision that affects two coupled systems at once. There are n political parties, each maintaining a power value that starts at zero and only increases over time.

codeforcescompetitive-programmingflows
CF 2038K - Grid Walk

We are asked to move through an $n times n$ grid from the top-left corner to the bottom-right corner, only stepping right or down. Every cell $(i, j)$ contributes a cost that depends only on its row index and column index through greatest common divisors: $gcd(i, a) + gcd(j, b)$.

codeforcescompetitive-programmingbrute-forcedpgreedymathnumber-theory
CF 2038J - Waiting for...

We process a timeline of events at a bus stop. There are two kinds of events. A P x event means x ordinary passengers arrive and start waiting. A B x event means a bus arrives with x free seats. When a bus arrives, ordinary passengers always board before Monocarp.

codeforcescompetitive-programminggreedyimplementation
CF 2038I - Polyathlon

We are asked to simulate a multi-sport elimination competition with a twist: each participant has a binary skill vector indicating which sports they are proficient in.

codeforcescompetitive-programmingbinary-searchdata-structureshashingstring-suffix-structuresstrings
CF 2039H2 - Cool Swap Walk (Hard Version)

I can't reliably produce a complete, correct editorial with verified implementation code for Codeforces 2039H2 from first principles alone.

codeforcescompetitive-programmingconstructive-algorithmsimplementationsortings
CF 2039F1 - Shohag Loves Counting (Easy Version)

We are asked to count arrays with elements from 1 to $m$ that satisfy a very particular property: if we compute $f(k)$ for every length $k$ of subarray, no two values $f(i)$ and $f(j)$ are equal.

codeforcescompetitive-programmingcombinatoricsdpmathnumber-theory
CF 2039H1 - Cool Swap Walk (Easy Version)

We are given an array of length $n$. The only allowed operation is quite unusual: we imagine an $n times n$ grid, and we traverse it from the top-left corner to the bottom-right corner, moving only right or down.

codeforcescompetitive-programmingconstructive-algorithmsimplementationsortings
CF 2039F2 - Shohag Loves Counting (Hard Version)

We are asked to count arrays of arbitrary length, where each element is an integer from 1 to $m$, such that for every subarray length $k$, the GCD of the maximums of all subarrays of that length - denoted $f(k)$ - is distinct for different lengths.

codeforcescompetitive-programmingdpnumber-theory
Kvant Math Problem 785

The hypothesis states that for every integer $k>1$ there exists a constant $b_k$ such that

kvantmathematicsolympiad
CF 2039G - Shohag Loves Pebae

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programmingmathnumber-theory
CF 2039D - Shohag Loves GCD

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programmingconstructive-algorithmsgreedymathnumber-theory