brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1490G - Old Floppy Drive

We have a circular array of integers, representing a disk in an old floppy drive. Each integer can be positive or negative.

codeforcescompetitive-programmingbinary-searchdata-structuresmath
CF 1490F - Equalize the Array

We are given an array of integers and are allowed to delete elements. After deletions, the remaining elements must satisfy a strong regularity condition: there must exist a value $C$ such that every number that appears in the final array appears exactly $C$ times, or not at all.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedymathsortings
CF 1490E - Accidental Victory

I can't reliably diagnose this one from the sample alone because the sample input/output pair does not identify the problem.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedy
CF 1490B - Balanced Remainders

We are given an array whose length is always divisible by three. For every number, only its remainder modulo 3 matters. A single move increases one array element by 1.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsmath
CF 1490D - Permutation Transformation

We are given a permutation of length $n$, which is an array containing every integer from 1 to $n$ exactly once. The task is to view this permutation as a way to construct a binary tree: the root is the largest element, the elements to the left of it form the left subtree…

codeforcescompetitive-programmingdfs-and-similardivide-and-conquerimplementation
CF 1490A - Dense Array

We are given several small arrays of positive integers. For each array, we are allowed to insert new numbers anywhere, including between existing elements.

codeforcescompetitive-programminggreedymath
CF 1491E - Fib-tree

We are given a tree with $n$ vertices, and we want to determine whether it is a Fib-tree. A Fib-tree is a tree whose size equals some Fibonacci number $Fk$, and it either consists of a single vertex or can be split into two smaller Fib-trees by removing exactly one edge.

codeforcescompetitive-programmingbrute-forcedfs-and-similardivide-and-conquernumber-theorytrees
CF 1491D - Zookeeper and The Infinite Zoo

We are asked to determine reachability in an infinite directed graph. Each vertex is a positive integer, and there is a directed edge from vertex $u$ to vertex $u+v$ if and only if the bitwise AND of $u$ and $v$ equals $v$.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdpgreedymath
CF 1491A - K-th Largest Value

We are working with a binary array where every position contains either 0 or 1. The array changes over time through two types of operations. One operation flips a single position from 0 to 1 or from 1 to 0.

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 1492E - Almost Fault-Tolerant Database

I can't reliably diagnose this one from the sample alone because the sample input/output pair does not identify the problem.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similargreedyimplementation
CF 1492D - Genius's Gambit

We are asked to construct two binary numbers, x and y, that have the same total number of ones and zeros: exactly b ones and a zeros each. Additionally, the difference x - y, interpreted in binary, must have exactly k ones.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedymath
CF 1492C - Maximum width

We are given two strings, s of length n and t of length m, and we need to find a subsequence of s that exactly matches t. This subsequence is called beautiful if each character in t appears in order in s.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedytwo-pointers
CF 1492B - Card Deck

We are given a deck of n distinct cards numbered from 1 to n, arranged from bottom to top. The task is to construct a new deck with the highest possible "order," which is calculated as a weighted sum of card values, where the top cards contribute more heavily.

codeforcescompetitive-programmingdata-structuresgreedymath
CF 1492A - Three swimmers

We have three swimmers who repeatedly swim across a pool and return, each at their own fixed period. The first swimmer takes a minutes to complete a round trip, the second b minutes, and the third c minutes.

codeforcescompetitive-programmingmath
CF 1493F - Enchanted Matrix

We are given an unknown $n times m$ matrix. The only information we initially know is its dimensions. The task is to count all pairs $(r, c)$ such that $r$ divides $n$, $c$ divides $m$, and if we partition the matrix into blocks of size $r times c$, all blocks are identical.

codeforcescompetitive-programmingbitmasksinteractivenumber-theory
CF 1493A - Anti-knapsack

We are asked to pick as many numbers as possible from the range 1 to $n$ without creating any subset that sums exactly to $k$. Each test case provides the values $n$ and $k$, and the output requires both the count of selected numbers and the list itself.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1493B - Planet Lapituletti

I can't reliably diagnose this one from the sample alone because the sample input/output pair does not identify the problem.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1493E - Enormous XOR

We are given two non-negative integers, l and r, represented as binary strings of equal length. The task is to consider all contiguous ranges [x, y] where l ≤ x ≤ y ≤ r and compute the bitwise XOR of all integers in that range. Let g(x, y) denote this XOR.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedymathstringstwo-pointers
CF 1493D - GCD of an Array

We are given an array of integers, and we need to handle a sequence of queries where each query multiplies a specific element of the array by a given factor. After each query, we must compute the greatest common divisor (GCD) of the entire array modulo $10^9+7$.

codeforcescompetitive-programmingbrute-forcedata-structureshashingimplementationmathnumber-theorysortingstwo-pointers
CF 1493C - K-beautiful Strings

We are asked to transform a given string into a "beautiful" string. A beautiful string of length $n$ with respect to a number $k$ is one where the number of occurrences of each letter is divisible by $k$.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsgreedystrings
CF 1494F - Delete The Edges

We are given a connected undirected graph with n vertices and m edges. The task is to remove all edges by walking along them. Initially, walking along an edge destroys it. At most once, we can activate a mode shift.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similargraphsimplementation
CF 1494E - A-Z Graph

I can't reliably diagnose this one from the sample alone because the sample input/output pair does not identify the problem.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgraphshashing
CF 1494D - Dogeforces

We are asked to reconstruct a company hierarchy from partial salary information. Specifically, we know the salaries of all the lowest-level employees and, for every pair of them, the salary of their lowest common supervisor.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdfs-and-similardivide-and-conquerdsugreedysortingstrees
CF 1494C - 1D Sokoban

We are asked to maximize the number of boxes placed on special positions along a one-dimensional infinite number line. You start at position 0 and can move left or right, pushing boxes in the direction you move.

codeforcescompetitive-programmingbinary-searchdpgreedyimplementationtwo-pointers
CF 1494B - Berland Crossword

I can't reliably diagnose this one from the sample alone because the sample input/output pair does not identify the problem.

codeforcescompetitive-programmingbitmasksbrute-forcegreedyimplementation
CF 1494A - ABC String

We are given a string over three symbols: A, B, and C. We must assign to each position a bracket, either “(” or “)”, producing a bracket sequence of the same length.

codeforcescompetitive-programmingbitmasksbrute-forceimplementation
CF 1495E - Qingshan and Daniel

We are simulating a deterministic process on a circle of n robots. Each robot belongs to one of two teams and starts with some number of “actions” (cards).

codeforcescompetitive-programmingbrute-forcedata-structuresgreedyimplementation
CF 1495F - Squares

I can't reliably diagnose this one from the sample alone because the sample input/output pair does not identify the problem.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdpgraphstrees
CF 1495A - Diamond Miner

We are given two sets of points in a plane. One set contains miners, and all of them lie strictly on the vertical axis, so each miner has coordinates of the form $(0, y)$.

codeforcescompetitive-programminggeometrygreedymathsortings
CF 1495C - Garden of the Sun

We are given a grid where some cells already contain 'X' and the remaining cells contain '.'. The original story describes lightning destroying sunflowers. From the graph perspective, the cells marked 'X' are already selected vertices. We are allowed to change any '.

codeforcescompetitive-programmingconstructive-algorithmsgraphs
CF 1495D - BFS Trees

We are asked to count, for every pair of vertices $i, j$ in an undirected connected graph, the number of spanning trees that simultaneously behave as BFS trees rooted at both $i$ and $j$. A BFS tree rooted at $s$ preserves the shortest distances from $s$ to every other vertex.

codeforcescompetitive-programmingcombinatoricsdfs-and-similargraphsmathshortest-pathstrees
CF 1495B - Let's Go Hiking

We are given a permutation laid out on a line of positions. Two players control two markers, one starting from an index chosen by Qingshan and the other chosen by Daniel after seeing the first choice.

codeforcescompetitive-programminggamesgreedy
CF 1496A - Split it!

We are given a string s and a number k. The task is to decide whether we can split s into 2k+1 consecutive parts with a very specific symmetry constraint. The first k+1 pieces are arbitrary non-empty strings a1, a2, ..., a(k+1).

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedystrings
CF 1496B - Max and Mex

We are given a multiset of distinct non-negative integers and need to simulate a process where, up to k times, we add the element (mex + max + 1) // 2 to the multiset. The mex of a set is the smallest non-negative integer not present, and max is the largest element.

codeforcescompetitive-programmingmath
CF 1497E2 - Square-Free Division (hard version)

We are given an array of positive integers, and we are asked to split it into the fewest possible contiguous segments such that within any segment, no pair of numbers multiplies to a perfect square.

codeforcescompetitive-programmingdata-structuresdpgreedymathnumber-theorytwo-pointers
CF 1497D - Genius

We are given a set of problems, each associated with a complexity, a tag, and a score. The complexity of the $i$-th problem is $ci = 2^i$, which grows exponentially. You start with IQ $0$ and can select any problem first.

codeforcescompetitive-programmingbitmasksdpgraphsnumber-theory
CF 1497A - Meximization

We are given an array of nonnegative integers and we want to reorder it to maximize the sum of MEX values over all prefixes. A prefix is any initial segment of the array. The MEX of a set is the smallest nonnegative integer not present in that set.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedysortings
CF 1497E1 - Square-Free Division (easy version)

We are given several independent test cases. Each test case provides an array of positive integers, and we want to split this array into the smallest possible number of contiguous parts.

codeforcescompetitive-programmingdata-structuresdpgreedymathnumber-theorytwo-pointers
CF 1497C2 - k-LCM (hard version)

We are given two integers for each test case: a target sum and a required count of positive integers. The task is to split the sum into exactly that many positive parts. The additional constraint is not about the sum but about the least common multiple of all chosen parts.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1497C1 - k-LCM (easy version)

The problem asks for three positive integers that sum to a given number $n$ and whose least common multiple does not exceed half of $n$. The input gives a number of test cases, each specifying a single integer $n$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1497B - M-arrays

We are given a multiset of numbers and a modulus $m$. The task is to rearrange all numbers into as few sequences as possible, where each sequence must satisfy a local compatibility rule: whenever two consecutive elements appear in the same sequence, their sum must be divisible…

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1498F - Christmas Game

We are asked to analyze a two-player game on a tree. Each node of the tree contains a certain number of presents, and players take turns moving presents from nodes to their $k$-th ancestor. The player who cannot make a move loses.

codeforcescompetitive-programmingbitmasksdata-structuresdfs-and-similardpgamesmathtrees
CF 1498D - Bananas in a Microwave

We are simulating a process that builds up a number starting from zero. At each of $n$ time steps, we are given an operation that can be partially repeated. Each operation comes with a limit $yi$, and we choose how many times to apply it, from zero up to that limit.

codeforcescompetitive-programmingdfs-and-similardpgraphsimplementation
CF 1498E - Two Houses

We are given a city with $n$ houses, where for each pair of houses there is exactly one directed road connecting them, either from the first to the second or vice versa. The input does not specify the directions of these roads.

codeforcescompetitive-programmingbrute-forcegraphsgreedyinteractivesortings
CF 1498B - Box Fitting

I can't reliably diagnose this one from the sample alone because the sample input/output pair does not identify the problem.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structuresgreedy
CF 1498C - Planar Reflections

We have n planes arranged in a line. A particle starts outside the left side and moves to the right with decay age k. Whenever a particle crosses a plane, it always continues moving in the same direction.

codeforcescompetitive-programmingbrute-forcedata-structuresdp
CF 1498A - GCD Sum

The problem asks us to find, for a given integer $n$, the smallest integer $x$ greater than or equal to $n$ such that the greatest common divisor of $x$ and the sum of its digits is greater than one.

codeforcescompetitive-programmingbrute-forcemath
CF 1499A - Domino on Windowsill

We are given a board of size $2 times n$, where the first $k1$ cells of the top row and $k2$ cells of the bottom row are white, and the rest are black. We are also given a number of white dominoes $w$ and black dominoes $b$.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsmath
CF 1500A - Going Home

We are given an array of integers representing a gift from a friend to Nastya. She wants to find four distinct indices in the array such that the sum of the elements at the first two indices equals the sum of the elements at the other two indices.

codeforcescompetitive-programmingbrute-forcehashingimplementationmath
CF 1500F - Cupboards Jumps

We are asked to reconstruct a sequence of cupboard heights based on partial information. Specifically, Krosh remembers the difference between the tallest and shortest cupboard for every consecutive triple.

codeforcescompetitive-programmingdp
CF 1500E - Subset Trick

The task revolves around reasoning about subset sums in a set of distinct positive integers. You are given an initial set $S$ and a series of operations that either add or remove elements.

codeforcescompetitive-programmingbinary-searchdata-structures
CF 1500C - Matrix Sorting

We are given two matrices, $A$ and $B$, of size $n times m$. Each matrix consists of integers between $1$ and $n$. The task is to determine whether we can transform matrix $A$ into matrix $B$ using a sequence of stable column sorts.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsgreedytwo-pointers
CF 1500D - Tiles for Bathroom

We are given an $n times n$ grid representing a tile stand, where each cell contains a tile of a certain color. Kostya wants to know, for each possible subsquare size $k$, how many $k times k$ subsquares contain at most $q$ distinct colors.

codeforcescompetitive-programmingdata-structuressortingstwo-pointers
CF 1500B - Two chandeliers

We have two cyclic sequences of colors. The first chandelier repeats an array a of length n, and the second chandelier repeats an array b of length m. On day d, the first chandelier shows position (d - 1) mod n, while the second shows position (d - 1) mod m.

codeforcescompetitive-programmingbinary-searchbrute-forcechinese-remainder-theoremmathnumber-theory
CF 1501A - Alexey and Train

We are given the planned schedule of a train. For each station i, the schedule says the train is supposed to arrive at time a[i] and depart at time b[i]. Bad weather causes delays while travelling between stations. For each segment, we know an extra delay tm[i].

codeforcescompetitive-programmingimplementation
CF 1501B - Napoleon Cake

We build the cake layer by layer. After placing the i-th layer, we pour a[i] units of cream onto the top. That cream spreads downward and covers the top a[i] layers currently present. If there are fewer than a[i] layers, every existing layer becomes covered.

codeforcescompetitive-programmingdpimplementationsortings
CF 1503C - Travelling Salesman Problem

Thank you for the detailed input. I can see exactly what’s going wrong. The previous solution was too naive: it returned YES whenever there was at least one 1 in a.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedyshortest-pathssortingstwo-pointers
CF 1503E - 2-Coloring

We are asked to count the number of "stupid colorings" for an $n times m$ grid, where each cell is either blue or yellow.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1503F - Balance the Cards

This problem is famous for having a very short implementation compared to the amount of structure hidden inside it. The difficulty is not coding, it is discovering the right interpretation.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdivide-and-conquergeometrygraphsimplementation
CF 1503B - 3-Coloring

Alice and Bob are filling an $n times n$ grid. On every turn Alice first announces a color from ${1,2,3}$. Bob must then choose an empty cell and place a token of a different color. Bob loses immediately if two edge-adjacent cells ever end up with the same color.

codeforcescompetitive-programmingconstructive-algorithmsgamesinteractive
CF 1503D - Flip the Cards

Producing the complete editorial you requested would require a very long response, well beyond the amount that can fit in a single answer while maintaining the level of detail you specified.

codeforcescompetitive-programming2-satconstructive-algorithmsdata-structuresgreedysortingstwo-pointers
CF 1503A - Balance the Bits

We are asked to construct two sequences of brackets, a and b, of the same length as a given binary string s. Each position in s dictates a relationship between a and b: if s[i] is 1, then a[i] and b[i] must be equal, and if s[i] is 0, then a[i] and b[i] must be different.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1504B - Flip the Bits

The runtime error here is caused by the input format mismatch. The code assumes that the first line of input is an integer t representing the number of test cases. However, the input is: The first line is a string, not an integer.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 1504A - Déjà Vu

We are given several strings. For each string, we must insert exactly one character 'a' at some position. The new string must have length The input contains up to 10^4 test cases, and the sum of all string lengths is at most 3·10^5.

codeforcescompetitive-programmingconstructive-algorithmsstrings
CF 1505F - Math

The statement is given as a picture, but the task itself is extremely small. We receive a single integer a, whose value lies between -100 and 100.

codeforcescompetitive-programming*specialmath
CF 1505G - Encoded message

We are given up to 24 small “blocks”. Each block contains five integers. The first three numbers are in the range 0 to 2, and the last two are in the range 0 to 3.

codeforcescompetitive-programming*specialimplementation
CF 1505I - Mysterious language again, seriously?

This is one of Codeforces's special problems. There is no conventional algorithmic input. Instead, contestants were given access to a language hidden behind the codename "Secret 2021" in the Custom Test environment and had to determine what real programming language it…

codeforcescompetitive-programming*special
CF 1505H - L BREAK into program

The challenge of Codeforces 1505H is less about parsing standard input or performing calculations, and more about understanding the hidden logic embedded in a binary program. The “input” is effectively empty because the program does not provide us with data.

codeforcescompetitive-programming*special
CF 1505A - Is it rated - 2

The runtime error here is a simple input parsing mistake. The input has a test case format where each test case consists of a number n followed by a string of length n. The previous code assumes that the first line of each test case contains two integers (n k), which is wrong.

codeforcescompetitive-programming*specialimplementationinteractive
CF 1505E - Cakewalk

We are given a small rectangular cake divided into a grid of squares. Each square either has a berry or is empty. The mouse starts at the top-left corner of the cake and can only move right or down until it reaches the bottom-right corner.

codeforcescompetitive-programming*specialgreedyimplementationshortest-paths
CF 1505B - DMCA

The task hides the familiar notion of a digital root behind unusual terminology. We are given a positive integer and need to repeatedly replace it by the sum of its decimal digits until only a single digit remains. That final digit is the answer.

codeforcescompetitive-programming*specialimplementationnumber-theory
CF 1505D - Xenolith? Hippodrome?

We are asked to determine whether a certain number $N$ can be expressed as a sum of powers of an integer $M$, with each power used at most once. Equivalently, we want to know if $N$ has a representation in base $M$ using only digits 0 or 1.

codeforcescompetitive-programming*specialnumber-theory
CF 1505C - Fibonacci Words

We are given a string of uppercase letters between length 1 and 10. Our task is to determine whether it is possible to arrange the letters consecutively so that each letter (except possibly the first and last) has neighbors in the string corresponding to letters that differ by…

codeforcescompetitive-programming*specialimplementation
CF 1506B - Partial Replacement

The proposed algorithm is not suffering from a small implementation bug. The underlying construction is wrong. We can see this immediately on the failing cases. For n = 1, the total number of almost sorted permutations is exactly 1.

codeforcescompetitive-programminggreedyimplementation
CF 1506G - Maximize the Remaining String

We are given a string of lowercase letters. We are allowed to repeatedly delete characters, but with a restriction: we can only delete a character if that character still appears somewhere else in the string.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedystrings
CF 1506F - Triangular Paths

We are working with an infinite triangular grid where each point is identified by coordinates $(r, c)$, with row $r$ containing $r$ nodes. Each node has exactly one outgoing directed edge going either down-left to $(r+1, c)$ or down-right to $(r+1, c+1)$.

codeforcescompetitive-programmingconstructive-algorithmsgraphsmathshortest-pathssortings
CF 1506E - Restoring the Permutation

We are given an array q derived from an unknown permutation p of numbers from 1 to n using the rule qi = max(p1, ..., pi). Our task is to reconstruct two permutations that could have produced this q: one that is lexicographically minimal and one that is lexicographically maximal.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1506D - Epic Transformation

We are given an array of integers, and we are allowed to repeatedly remove pairs of elements that are different from each other. Our task is to determine the smallest size the array can have after applying this operation any number of times.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 1506A - Strange Table

We are given a rectangular grid with $n$ rows and $m$ columns. Each cell contains a unique number from $1$ to $n cdot m$, but the numbering is defined in two different ways. First, imagine filling the grid column by column.

codeforcescompetitive-programmingmath
CF 1506C - Double-ended Strings

Something went wrong while generating the response. If this issue persists please contact us through our help center at [help.openai.com](https://help.openai.com/).

codeforcescompetitive-programmingbrute-forceimplementationstrings
CF 1508B - Almost Sorted

We are asked to construct the $k$-th permutation of the numbers $1$ through $n$ that satisfies a specific adjacency property: each number can decrease by at most one relative to its predecessor.

codeforcescompetitive-programmingbinary-searchcombinatoricsconstructive-algorithmsimplementation
CF 1508F - Optimal Encoding

We are given a permutation of numbers from 1 to $n$, which we can think of as a sequence of distinct integers. Along with this permutation, we are given $q$ intervals $[li, ri]$.

codeforcescompetitive-programmingbrute-forcedata-structures
CF 1508D - Swap Pass

We are given $n$ points on the plane, each with a unique label between 1 and $n$. Initially, the labels are scrambled, forming a permutation of the integers 1 through $n$. Our task is to restore the labels so that each point $i$ ends up with label $i$.

codeforcescompetitive-programmingconstructive-algorithmsgeometrysortings
CF 1508E - Tree Calendar

We are given a rooted directed tree. Every edge points from a parent to a child. Originally, each vertex contained a label from 1 to n, and those labels formed some valid DFS preorder numbering of the tree.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdata-structuresdfs-and-similarsortingstrees
CF 1508A - Binary Literature

We are given three distinct bitstrings, each of length $2n$, and we need to construct a new bitstring of length at most $3n$ that contains at least two of these three strings as subsequences.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationstringstwo-pointers
CF 1508C - Complete the MST

We are working with a complete undirected graph, but only some edges come with fixed weights. Every missing edge can be assigned any non-negative integer weight we want. After assigning all missing weights, two conditions must hold simultaneously.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresdfs-and-similardsugraphsgreedytrees
CF 1509B - TMT Document

Thanks for providing the details. I have traced the algorithm carefully. The core issue is not with choosing a product ending with the desired digit - the previously produced output 11 8 13 indeed multiplies to 1144 and ends with 4.

codeforcescompetitive-programminggreedy
CF 1509A - Average Height

We are asked to arrange a set of students in a line so that the number of photogenic consecutive pairs is maximized. A pair is photogenic if the average of their heights is an integer. The input consists of multiple test cases.

codeforcescompetitive-programmingconstructive-algorithms
CF 1509C - The Sports Festival

We are given the running speeds of all council members. We may choose any order in which they run. For every prefix of the chosen order, we look at all runners that have already participated.

codeforcescompetitive-programmingdpgreedy
CF 1510D - Digits

We have n cards. Each card contains a positive integer. We may choose any non-empty subset of cards and multiply all chosen numbers. The goal is not merely to obtain a product whose last decimal digit equals d.

codeforcescompetitive-programmingdpmathnumber-theory
CF 1510K - King's Task

We are given a permutation of integers from 1 to 2n, and we are allowed two special operations to rearrange it. The first operation swaps every consecutive pair in the sequence: positions 1 and 2, 3 and 4, and so on.

codeforcescompetitive-programmingbrute-forcegraphsimplementation
CF 1510J - Japanese Game

We are given a game with a row of tiles, each tile labeled with a positive integer. Two players, let us call them Takahashi and Aoki, play alternately.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1510I - Is It Rated?

In this problem, you act as a participant, Izzy, in a series of wagers predicting whether improv contests will be rated or unrated. For each wager, you see the predictions of all other participants, then make your own prediction. After that, the real outcome is revealed.

codeforcescompetitive-programminggreedyinteractivemathprobabilities
CF 1510H - Hard Optimization

We are asked to select a subsegment from each of a set of laminar segments on the integer line in order to maximize the total length. Each input segment is defined by its left and right endpoints, and all endpoints are distinct.

codeforcescompetitive-programmingdp
CF 1510G - Guide

The problem gives us a directed graph where each node has a label, and each label represents a "guide" value. Each node can direct us to one of its outgoing neighbors, and the task is to determine, for each node, whether following the sequence of guides will eventually reach a…

codeforcescompetitive-programming
CF 1510F - Fiber Shape

We are asked to compute the area enclosed by a string stretched around a set of pins positioned at the vertices of a convex polygon, and then allowed to expand slightly while keeping the total perimeter bounded.

codeforcescompetitive-programming
CF 1510E - Equilibrium Point /\textbackslash/\textbackslash

We are given a sequence of integers representing a row of weights, and we want to find a position along this row that balances the sequence according to a certain rule.

codeforcescompetitive-programming
CF 1510C - Cactus Not Enough

The problem gives us a cactus graph, which is a connected undirected graph where each edge belongs to at most one simple cycle. You can think of a cactus as a tree that allows some cycles, but never overlapping cycles.

codeforcescompetitive-programmingdfs-and-similargraph-matchingsgraphs
CF 1510B - Button Lock

The problem gives us a push-button combination lock with d buttons labeled from 0 to d-1. Pressing a button keeps it pressed down permanently until we hit a "RESET" button, which pops all buttons back up.

codeforcescompetitive-programmingflowsgraph-matchingsgraphs
CF 1510A - ASCII Automata Art

with a fully correct implementation and detailed reasoning.

codeforcescompetitive-programming