brain

tamnd's digital brain — notes, problems, research

41650 notes

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
CF 1511G - Chips on a Board

We are given a rectangular board with n rows and m columns. Each row contains exactly one chip. The chips can be located in any column of their respective row.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresdpgamestwo-pointers
CF 1511E - Colorings and Dominoes

We are given a grid where some cells are blocked and the remaining cells are usable. Every usable cell must be colored either red or blue. After choosing a coloring, we want to place as many dominoes as possible.

codeforcescompetitive-programmingcombinatoricsdpgreedymath
CF 1511C - Yet Another Card Deck

We are given a deck of n cards, each with a color represented by an integer from 1 to 50. The deck is arranged from top to bottom, and we receive q queries.

codeforcescompetitive-programmingbrute-forcedata-structuresimplementationtrees
CF 1512G - Short Task

We are asked to find the smallest positive integer $n$ such that the sum of its divisors equals a given number $c$. Formally, the sum-of-divisors function $d(n)$ sums all numbers that divide $n$ evenly, including $1$ and $n$ itself. For example, $d(6) = 1 + 2 + 3 + 6 = 12$.

codeforcescompetitive-programmingbrute-forcedpmathnumber-theory
CF 1512F - Education

Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.

codeforcescompetitive-programmingbrute-forcedpgreedyimplementation
CF 1512E - Permutation by Sum

We are asked to construct a permutation of numbers from 1 to $n$ such that the sum of a contiguous segment from index $l$ to $r$ equals a given value $s$. A permutation here is just an arrangement of all integers from 1 to $n$ with no repetitions.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1512D - Corrupted Array

We are given an array that has been “tampered with” in a very specific way. Originally there was an unknown array of length n, call it a.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 1512A - Spy Detected!

Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1512C - A-B Palindrome

We are given a string composed of characters '0', '1', and '?', along with two integers a and b representing the total number of '0's and '1's that the final string must contain. The task is to replace every '?

codeforcescompetitive-programmingconstructive-algorithmsimplementationstrings
CF 1512B - Almost Rectangle

We are given a square grid where exactly two cells are already marked with stars. These two stars are the only information we start with, and they define a partial geometric shape on the grid.

codeforcescompetitive-programmingimplementation
CF 1513F - Swapping Problem

We are given two arrays of equal length. You should imagine that each position forms a pair of values, one coming from the first array and one coming from the second. The cost of a configuration is determined by summing the absolute differences of each paired position.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdata-structuressortings
CF 1513C - Add One

We are given an integer n and a number of operations m. In each operation, every digit d of n is incremented by 1, and if this results in a two-digit number (which only happens for 9), it is replaced by two digits 1 and 0.

codeforcescompetitive-programmingdpmatrices
CF 1513E - Cost Equilibrium

Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsmathsortings
CF 1513D - GCD and MST

We are asked to compute the minimum spanning tree (MST) of a weighted graph constructed from an array of positive integers.

codeforcescompetitive-programmingconstructive-algorithmsdsugraphsgreedynumber-theorysortings
CF 1513B - AND Sequences

Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.

codeforcescompetitive-programmingbitmaskscombinatoricsconstructive-algorithmsmath
CF 1513A - Array and Peaks

We are asked to build a permutation of the numbers from 1 to n such that it contains exactly k peaks. A peak is a position strictly inside the array where the value is larger than both immediate neighbors.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1514D - Cut and Stick

We are given an array of integers and multiple queries, each asking about a subarray. For each query, we need to divide the subarray into subsequences, possibly of different lengths, so that no number appears more than half the length of any subsequence, rounded up.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedyimplementationsortings
CF 1514E - Baby Ehab's Hyper Apartment

We are given a single apartment floor modeled as a number line, with n rooms located at integer coordinates from 1 to n. Each room has an initial height assigned to it, and we are allowed to modify the heights in a constrained way.

codeforcescompetitive-programmingbinary-searchgraphsinteractivesortingstwo-pointers
CF 1514A - Perfectly Imperfect Array

Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.

codeforcescompetitive-programmingmathnumber-theory
CF 1514B - AND 0, Sum Big

We are asked to count arrays of length n where each element lies between 0 and 2^k - 1, such that the bitwise AND of all elements is zero and the sum of elements is as large as possible. The result should be returned modulo 10^9 + 7.

codeforcescompetitive-programmingbitmaskscombinatoricsmath
CF 1514C - Product 1 Modulo N

We are given the numbers from $1$ to $n-1$, and we must select as many of them as possible while keeping a very specific multiplicative condition: if we multiply all selected numbers together, the result must leave remainder $1$ when divided by $n$.

codeforcescompetitive-programminggreedynumber-theory
CF 1515I - Phoenix and Diamonds

We are maintaining a multiset of diamond types where each type has a fixed weight and value per item, but its available count changes over time due to arrivals and sales. On top of this evolving collection, we must answer queries that simulate a greedy packing process.

codeforcescompetitive-programmingbinary-searchdata-structuressortings
CF 1515H - Phoenix and Bits

Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuressortings
CF 1515G - Phoenix and Odometers

We are given a directed graph representing intersections in a city and one-way roads between them, each with a positive integer length. A set of cars starts at specific intersections, each with an odometer that begins at a number s and wraps around to zero after reaching t.

codeforcescompetitive-programmingdfs-and-similargraphsmathnumber-theory
CF 1515F - Phoenix and Earthquake

The problem describes a scenario where a country’s road network has been destroyed by an earthquake, leaving n cities and m roads in a disconnected state.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardsugraphsgreedytrees
CF 1515D - Phoenix and Socks

Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.

codeforcescompetitive-programminggreedysortingstwo-pointers
CF 1515E - Phoenix and Computers

We have a row of n computers, all initially off, and Phoenix wants to turn all of them on. He can manually switch on any computer that is currently off, but with a twist: if a computer has both its neighbors already on, it will turn on automatically without manual intervention.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1515C - Phoenix and Towers

We are given a set of n blocks, each with a height hi. Phoenix wants to construct exactly m towers using all the blocks. Each tower's height is the sum of its blocks, and a "beautiful" arrangement requires that no two towers differ in height by more than x.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 1515B - Phoenix and Puzzle

We are given a set of identical right isosceles triangular puzzle pieces. Each triangle has two equal sides and a right angle. Phoenix wants to use exactly $n$ of these triangles to form a perfect square, without overlaps or holes.

codeforcescompetitive-programmingbrute-forcegeometrymathnumber-theory
CF 1515A - Phoenix and Gold

Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1516E - Baby Ehab Plays with Permutations

We start with the identity permutation of numbers from 1 to n arranged in a row. In one operation, we are allowed to pick any two positions and swap their values. After performing exactly j such swaps, the array becomes some permutation of 1 to n.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1516D - Cut

We are given an array of up to $10^5$ integers. For each query $[l,r]$, we must split that subarray into the minimum possible number of contiguous pieces such that, inside every piece, the product of all elements equals the least common multiple of those elements.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgraphsnumber-theorytwo-pointers
CF 1516C - Baby Ehab Partitions Again

Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdpmath
CF 1516B - AGAGA XOOORRR

We are given an array and allowed to repeatedly compress it by taking two adjacent elements, removing them, and replacing them with their XOR.

codeforcescompetitive-programmingbitmasksbrute-forcedpgreedy
CF 1516A - Tit for Tat

We are given an array of non-negative integers, and we can perform a number of “transfer” operations. In one operation, we choose two different elements, subtract one from the first, and add one to the second, provided that the first element does not go below zero.

codeforcescompetitive-programminggreedy
CF 1517H - Fly Around the World

We are given a sequence of real values $b1, b2, ldots, bn$, which can be interpreted as the altitude of an aircraft at $n$ checkpoints. Each checkpoint restricts the allowed altitude range, so every $bi$ must lie inside a fixed interval.

codeforcescompetitive-programmingdpgeometry
CF 1517F - Reunion

Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.

codeforcescompetitive-programmingcombinatoricsdptrees
CF 1517G - Starry Night Camping

Each tent is placed at an integer coordinate and has a positive weight. We may remove any subset of tents. The goal is to maximize the total weight of the tents that remain. The restriction only applies to important tents, meaning tents whose coordinates are both even.

codeforcescompetitive-programmingconstructive-algorithmsflowsgraphs
CF 1517E - Group Photo

We are given a line of n people, each holding a card labeled either 'C' or 'P'. Each arrangement of cards forms a candidate photo.

codeforcescompetitive-programmingbinary-searchdata-structuresimplementationtwo-pointers
CF 1517D - Explorer Space

We are given a two-dimensional grid representing the explorer space at a conference. Each cell in the grid is a vertex, and each adjacent pair of vertices (up, down, left, right) is connected by an edge with a weight representing the number of exhibits along that edge.

codeforcescompetitive-programmingdpgraphsshortest-paths
CF 1517B - Morning Jogging

Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 1517C - Fillomino 2

We are given an $n times n$ lower-triangular part of a chessboard, where only the diagonal and the cells below it matter. On the main diagonal, each cell contains a distinct integer from 1 to $n$, forming a permutation.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargreedyimplementation
CF 1517A - Sum of 2050

We are asked to take a number $n$ and express it as a sum of numbers that are multiples of 2050 scaled by powers of ten. Concretely, the numbers we can use are 2050, 20500, 205000, 2050000, and so on. Each number in this sequence is exactly 2050 multiplied by a power of ten.

codeforcescompetitive-programminggreedymath
CF 1519F - Chests and Keys

Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.

codeforcescompetitive-programmingbitmasksbrute-forcedfs-and-similardpflows
CF 1519E - Off by One

We are given $n$ points in the first quadrant of a plane. Each point is defined by a pair of rational coordinates $(xi, yi)$, where $xi = ai / bi$ and $yi = ci / di$.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargeometrygraphssortingstrees
CF 1519D - Maximum Sum of Products

We are given two arrays of integers, a and b, both of the same length n. The task is to maximize the sum of element-wise products, $sum ai cdot bi$, by reversing at most one contiguous subarray of a.

codeforcescompetitive-programmingbrute-forcedpimplementationmathtwo-pointers
CF 1519C - Berland Regional

Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedynumber-theorysortings
CF 1519B - The Cake Is a Lie

We are given a rectangular grid with n rows and m columns. You start at the top-left corner (1, 1) and want to reach the bottom-right corner (n, m) by only moving right or down. Moving right from cell (x, y) costs x burles, moving down costs y burles.

codeforcescompetitive-programmingdpmath
CF 1519A - Red and Blue Beans

We have two colors of beans, red and blue. Every packet we create must contain at least one bean of each color, and inside any packet the difference between the number of red and blue beans cannot exceed d. The question is whether all

codeforcescompetitive-programmingmath
CF 1520G - To Go Or Not To Go?

We are asked to find the minimum time for Dima to travel from the top-left corner of a rectangular city grid to the bottom-right corner. The city is represented as an n × m grid where each cell has a value: -1 for blocked, 0 for free, and x 0 for a portal with cost x.

codeforcescompetitive-programmingbrute-forcedfs-and-similargraphsgreedyimplementationshortest-paths
CF 1520E - Arranging The Sheep

We have a one-dimensional board represented by a string. Each '' is a sheep and each '.' is an empty cell. In one move, a sheep can move exactly one position left or right into an adjacent empty cell.

codeforcescompetitive-programminggreedymath
CF 1520D - Same Differences

We are given an array and must count how many index pairs $(i, j)$ with $i < j$ satisfy a very specific relationship between their values and positions.

codeforcescompetitive-programmingdata-structureshashingmath
CF 1520A - Do Not Be Distracted!

Each test case gives a sequence of days, where every day is labeled with the task Polycarp worked on that day. The rule is simple: once he stops working on a task and switches to another one, he is never allowed to return to the old task.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1520C - Not Adjacent Matrix

We are asked to fill an $n times n$ square grid with the numbers from $1$ to $n^2$ such that no two horizontally or vertically neighboring cells contain consecutive integers. In other words, the difference between numbers in adjacent cells cannot be exactly one.

codeforcescompetitive-programmingconstructive-algorithms
CF 1521D - Nastia Plays with a Tree

We start with a tree, meaning a connected graph with $n$ vertices and exactly $n-1$ edges. Each move allows us to remove one existing edge and insert a new edge between any two vertices.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdfs-and-similardpdsugreedyimplementationtrees
CF 1521E - Nastia and a Beautiful Matrix

We are given counts of values 1..k. Value i must appear exactly ai times. Empty cells are allowed and are represented by 0. We must place all copies into an n × n matrix and minimize n. Every 2 × 2 submatrix must satisfy two conditions.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdpgreedy
CF 1521B - Nastia and a Good Array

We are given an array of positive integers, and we need to transform it into what Nastia calls a good array. A good array is defined as one where every pair of consecutive elements is coprime.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 1521C - Nastia and a Hidden Permutation

We are asked to reconstruct a hidden permutation of length n containing all integers from 1 to n using an interactive querying mechanism. For each query, we choose two distinct indices i and j, a type t (either 1 or 2), and a threshold x.

codeforcescompetitive-programmingconstructive-algorithmsinteractive
CF 1521A - Nastia and Nearly Good Numbers

A radix conversion routine transforms a nonnegative integer written in one base into its representation in another base. The program under discussion is Method 1a from Section 4.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 1523A - Game of Life

The empty output indicates a runtime crash before any printing happens, not a logical error in the math. Tracing the execution on the input: The program first reads t = 3, then processes three test cases.

codeforcescompetitive-programmingimplementation
CF 1523H - Hopping Around the Array

We are asked to help a grasshopper hop across a sequence of tiles represented by an array a. Each tile i contains a number a[i] that defines the maximum distance the grasshopper can jump forward from that tile.

codeforcescompetitive-programmingdata-structuresdp
CF 1523G - Try Booking

We are given a flat available for n days and m booking requests. Each request is a segment (li, ri) representing consecutive days someone wants to rent. Requests arrive in chronological order.

codeforcescompetitive-programmingdata-structuresdivide-and-conquer
CF 1523F - Favorite Game

We are asked to maximize the number of quests William can complete in a 2D grid game with two interacting mechanics: movement and fast travel towers.

codeforcescompetitive-programmingbitmasksdp
CF 1523B - Lord of the Values

We are given an array of even length, representing internal variables of a system. Each variable has an initial positive integer value.

codeforcescompetitive-programmingconstructive-algorithms
CF 1523E - Crypto Lights

We are asked to compute the expected number of lights that turn on in a line of $n$ lights, given a stopping condition based on consecutive segments of length $k$. Each light starts off, and in each step, one random light that is still off is turned on.

codeforcescompetitive-programmingcombinatoricsdpmathprobabilities