brain
tamnd's digital brain — notes, problems, research
41777 notes
The task is to read a single line containing two non-negative integers separated by whitespace and output their arithmetic sum.
We are given a single integer $a$, and we are asked to compute a certain count associated with binary strings of length $a$. Each position in such a string can be thought of as a switch that is either off or on, but the strings we are allowed to consider are not arbitrary.
The problem presents a number x that represents a dome's height in some scaled system. Our task is to find two positive integers, a and b, both between 1 and 10 inclusive, that encode this height according to the formula $x = a cdot sqrt{b}$.
This is one of Codeforces' April Fools problems. There is no real algorithmic input. The judge provides a special language called "Secret" through the custom invocation system. The task is to identify what that language actually is and submit a program written in that language.
At first glance, the problem seems almost absurdly simple: you are given an integer between 1 and 16, and you need to output a single integer corresponding to that input.
We are given two short strings representing sequences of moves in a fictional duel between two teams. Each string is built from a small alphabet that visually looks like emoticon fragments, and each valid move is actually encoded using two characters.
The problem gives us a list of integers representing quantities of some alchemical ingredients. The goal is to determine the greatest common divisor (GCD) of these quantities. In other words, we want to find the largest integer $d$ such that each given number is divisible by $d$.
We are given an integer sequence of length $n$ and two additional parameters: $k$, the maximum number of elements we are allowed to insert, and $d$, the intended difference of an arithmetic progression.
We are given an integer matrix of size n by m. Each cell contains a positive integer. The task is to find the largest rectangular submatrix where all the elements are distinct. The “largest” is measured by area, meaning the number of cells inside the rectangle.
We are given an array and a sequence of range operations. Each operation picks a segment $[l, r]$ and a parameter $k$, and for every position $j$ inside that segment we add a value that depends on how far $j$ is from the left endpoint $l$.
We are given two positive integers, a and b, which are the lengths of the legs of a right triangle. The task is not to check whether such a triangle exists, it obviously does.
We are given a linear maze with n+1 rooms, numbered from 1 to n+1. Each room 1 through n has two portals. The first portal always moves forward to the next room, i+1. The second portal moves backward to some previous room, p₁ through pₙ, where pᵢ ≤ i.
We are given a large universe of numbered blocks from 1 to 1,000,000. Some subset of these blocks, called $X$, has been removed from Chris’s set. From the remaining blocks, we need to choose a non-empty subset $Y$ so that a very specific weighted balance condition holds.
We are given a connected undirected graph, and we are asked to completely decompose its edges into length-2 paths.
We are given an n×n binary matrix, meaning every element is either 0 or 1. The "unusual square" of the matrix is defined as the sum over all rows of the dot product of row i with column i, computed modulo 2.
We are given a row of dominoes, some of which are initially pushed to fall either left or right, while others are standing upright. Each second, a falling domino pushes its immediate neighbor in the same direction.
We are given a row of vertical stacks of cubes. Each position in the row holds a column, and the input array describes how many cubes are stacked at each position. Then a “gravity switch” happens.
We have a robot standing on an infinite 1D strip of cells indexed by integers, starting at cell 0. The robot is given a sequence of moves, each either left (L) or right (R). Before the robot starts, we can place obstacles on some cells, except cell 0.
We have a one-dimensional Minesweeper field represented as a string of length n. Each character can be a bomb '', an unknown '?', or a number 0, 1, or 2. The numbers indicate how many bombs are immediately adjacent to that cell.
We are asked to reconstruct an undirected connected graph from a list of shortest distances from one vertex, under the constraint that each vertex can have at most k edges.
We are given an odd-sized square grid of letters. Each cell contains a lowercase English letter. The task is to check whether the letters form a perfect "X" pattern.
Valera runs around the perimeter of a square stadium. The square has side length a, and the route follows the boundary in counterclockwise order. The starting point is the bottom-left corner (0, 0).
We are given a square matrix $a$ of size $n times n$ whose elements are all non-negative integers. The matrix can be thought of as a weighted adjacency matrix of a graph with $n$ nodes, where $a{ij} 0$ indicates a direct edge from node $i$ to node $j$.
We are asked to construct a special type of undirected graph. The graph has n vertices and a parameter p, and it must satisfy two global conditions. First, the total number of edges is exactly 2n + p. Second, no subgraph of k vertices may have more than 2k + p edges.
We are asked to distribute a given number of nuts into boxes, but the boxes are not simple containers. Each box can be split into sections using “divisors,” and every section can hold at most a certain number of nuts.
We have a row of trees, each with a given height. The Queen wants the trees arranged in perfect arithmetic progression: the difference between consecutive tree heights must be exactly $k$.
We are asked to arrange a set of cards, some marked with zero and some with one, in a line so that no two zeros are adjacent and no three ones are consecutive. We know the counts of each type of card upfront: n zeros and m ones.
Vanya has found a subset of his playing cards, each card labeled with an integer between $-x$ and $x$. He wants the total sum of all his cards to be zero. We need to determine the minimum number of additional cards he should find to achieve that zero sum.
We have a row of domino tiles. Each tile has a number on its upper half and a number on its lower half. For every tile, we may either leave it as it is or rotate it by 180 degrees. Rotating a tile simply swaps its upper and lower values. Each rotation costs one second.
We are given an array of non-negative integers a with length n and a number m in binary form. We want to select a subset of indices from 0 to n-1 and sum the corresponding a[i] values, but with a twist: the subset corresponds to the binary representation of some integer x…
Codeforces 353E: Antichain
We are given a line of schoolchildren represented as a string of letters M and F, where M indicates a boy and F a girl. Each second, any boy standing immediately in front of a girl swaps positions with her. This process repeats until no boy is in front of a girl.
Each cube contains a two digit number. We must split the 2n cubes into two heaps of exactly n cubes each. After the split, Valera may choose any cube from the first heap and any cube from the second heap.
We are asked to construct a bracket sequence of length n·m, where n is a small number up to 20 and m is much larger, up to 10^7, and is even. Each position in the sequence can be either an opening bracket ( or a closing bracket ).
Jeff has a list of 2n real numbers and he wants to round them in pairs so that the total sum changes as little as possible. Each operation consists of taking two unused numbers: one is rounded down (floor) and the other rounded up (ceiling).
We are given a sequence of integers, and we are allowed to flip the sign of any element. The goal is to minimize the number of inversions in the sequence. An inversion occurs whenever a larger number appears before a smaller number in the sequence.
For each query we look at a subarray of the given array and ask for its beauty. A single operation chooses several equal values whose positions form an arithmetic progression, removes them, and then allows us to reorder everything that remains. That last sentence is the key.
We are asked to model a two-player game played on a permutation of integers from 1 to n. Jeff moves first and can swap any adjacent elements.
Label the people around the circle as a cyclic sequence of 60 vertices, each colored either $B$ (boy) or $G$ (girl), with exactly 30 of each color.
Let
Let integers $a \le b$ be such that the required sum is
The relation
We are given a set of points on an infinite grid, each point containing a single bomb. A robot starts at the origin and must eventually destroy every bomb, but it cannot simply “teleport” to them.
We are given an undirected, simple, connected graph with $n$ vertices and $m$ edges. In addition, a subset of vertices $a1, a2, dots, ak$ is designated as “special”.
We are asked to count "owls" in a geometric picture composed of segments and circles. An owl is defined as a combination of two circles and a segment where the circles are reflections of each other across the segment, have identical radii, do not overlap, and the segment…
We are asked to help Valera set a time limit for a programming problem. He has a set of correct solutions, each with a known runtime, and a set of wrong solutions, also with runtimes.
Place the circumcenter $O$ as a reference point and represent the triangle on its circumcircle.
Igor wants to paint the largest possible number on a fence using a limited amount of paint. Each digit from 1 to 9 has a specific paint cost, and zero cannot be used.
We are given a queue of people waiting to buy cinema tickets. Each person holds a bill worth 25, 50, or 100 rubles, and each ticket costs 25 rubles. The clerk starts with no money and must sell tickets in the exact order of the line, giving correct change if necessary.
We are given an array of integers and a collection of subsets, each referencing indices in the array. Two types of operations are performed repeatedly: querying the sum of the elements of a subset, and adding a value to all elements of a subset.
Let $n_k$ be the repunit of length $k$, so
We are given a rooted tree where only the leaves initially contain apples, while internal nodes are empty. Each leaf contributes a fixed number of apples, and the “weight” of any subtree is defined as the total number of apples in all leaves inside that subtree.
We are given a weighted tree with n towns. Some of these towns contain monasteries, and each monastery hosts exactly one pilgrim.
We are given a rectangular grid of size n by m, where each cell is either free or blocked. Two turtles start at the top-left corner, cell (1,1), and both want to reach the bottom-right corner, cell (n,m).
We are given a group of friends who will repeatedly play a game. Each round of the game has exactly one person acting as a supervisor, while the remaining $n-1$ people participate as players.
Let $P(x)\in\mathbb{Z}[x]$ and suppose there exist distinct integers $x_1,\dots,x_n$ with $n\ge 3$ such that
We are given a list of n integers and need to arrange them in a row such that the sum of differences between consecutive numbers is maximized. Concretely, if the arrangement is $x1, x2, dots, xn$, the value is calculated as $(x1 - x2) + (x2 - x3) + dots + (x{n-1} - xn)$.
The process can be encoded in terms of the coefficients $a$ and $b$ of the quadratic $x^2+ax+b$, starting from $(a,b)=(10,20)$ and ending at $(20,10)$.
We are given a permutation of numbers from 0 to n − 1, stored in an array where each index represents a position and the value at that index represents where that position “points”. A position i is called a fixed point if the value stored at that position is exactly i.
We start with a number a and want to reduce it down to b using two types of moves. One move simply decreases the current value by 1. The other move is more interesting: we pick one of the given numbers xi and subtract the remainder of the current value when divided by xi.
We start with a finite set of distinct positive integers. Two players alternate turns, and on each turn a player is allowed to take any two existing numbers, compute their absolute difference, and insert that value into the set if it is not already present.
Let $x,y \in \mathbb{Q}\setminus{0}$ satisfy
We are given a sequence of platform heights generated by a modular arithmetic rule. The x-th platform sits at height (a · x) mod p, where a and p are coprime and we only consider the first n such positions.
We are given a directed graph representing a map a robot can traverse. The robot starts at a vertex s and must reach a target vertex t.
We are asked to build a sequence that appears as a subsequence of two given strings while avoiding a third string as a contiguous pattern.
We are given a list of strings, and the task is to find the largest possible subset of these strings such that all strings in the subset are suffixes of some single string. In other words, there should exist a string t that ends with every string in our chosen subset.
The rule replaces one chip by two chips placed one step north and one step east, provided those target cells are empty.
We are given a number $n le 10^5$. For every integer base $b ge 2$, we write $n$ in base $b$, but instead of usual digit symbols we represent each digit as a decimal number and concatenate them without separators.
We model the configuration as follows.
For the Fibonacci sequence $f_1=1$, $f_2=2$, $f_{k+1}=f_k+f_{k-1}$, the first terms are
Let $A=4^{5^6}+6^{5^4}$.
We are moving along a straight line from (0, 0) to (a, 0) at a constant speed v. Around us, there are n black cats, each starting at a point (xi, yi). Each cat can move in any direction at speed at most u.
Let $G$ be the graph whose vertices are parliamentarians and edges represent mutual enmity.
We are given a network of people, where every pair of people either knows each other in both directions or does not know each other at all.
We are given a string representing Fridays the 13th across some period of time. Each character in the string can be "0" for a normal day, "1" for a particularly bad day, or "?" for a day the user cannot recall.
Let the squares have side lengths $a_1, a_2, \dots, a_n$, so that
We are asked to construct a resistor network using only unit resistors to achieve a specific rational resistance $frac{a}{b}$.
Let
We are asked to simulate multiple read heads moving along a linear hard drive to read a set of target tracks as quickly as possible. Each head starts at a given track, can move left, right, or stay in place, and multiple heads can occupy the same track.
Consider small values of $n$.
We are asked to maximize the total amount of water Mike can pump across a network of stations in a sequence of days. Each station is a node in an undirected graph, and pipes between stations are edges with capacities.
The recurrence is
We are given a rooted tree where every node behaves like a reservoir that can either contain water or be empty. The root is fixed at node 1, and all edges are directed conceptually away from it.
The triangle is equilateral, so placing it in a coordinate system with one side horizontal allows algebraic control over all distances and angles.
We are given a sequence that describes how two wires, one called “plus” and the other “minus”, overlap as they run from the left side to the right side of a device. At each position along the path, exactly one of the wires is physically above the other.
Let the quadrilateral have diagonals intersecting at a point $O$.
The task is to determine how many spherical balloons of radius 1 can fit inside a cupboard shaped like a semicircle on top of a rectangle. The cupboard has a semicircular top with radius r and vertical walls of height h, forming a depth also equal to r.
The allowed operations on a fraction $\frac{a}{b}$ replace the integer pair $(a,b)$ by one of $(a-b,b)$, $(a+b,b)$, or $(b,a)$.
A note starts at one spy positioned at index s in a line of n spies. The note must eventually reach another spy at position f.
From the condition with $n=m=1$ we obtain
For three consecutive natural numbers $n, n+1, n+2$, the key structural feature is that any two of them are coprime.
We are working with a tree where every node represents a point in a connected acyclic graph. Initially only node 1 is colored red, while every other node starts blue. Over time, we perform two kinds of operations.
Let the two given lines be denoted $l_1$ and $l_2$.
We are given a 3×n grid representing a puzzle board. Each cell can be forbidden, free, or marked with a special circle. Dominoes, which are 1×2 or 2×1 tiles, must be placed to cover exactly two non-forbidden cells.
We are given a sequence of positive integers, all between 1 and 7, and the length of the sequence is divisible by three.
Work in the unit circle centered at $O$.
We are given an $n times n$ matrix initially filled with zeros. The problem asks us to handle two types of operations efficiently: one that computes the xor of all elements inside a submatrix, and another that xors a given value into every element of a submatrix.
We are given a set of boxes, each containing some number of candies. The objective is to redistribute candies such that exactly two boxes contain all the candies, and every other box is empty.
We are given a set of $n$ points in the 2D Cartesian plane, and we are asked to select four of these points to form a quadrilateral with the maximal area. The quadrilateral does not need to be convex, but it must have four vertices from the given points and cannot self-intersect.
We have several destinations located on a straight line at positions $a1,a2,dots,an$, all strictly positive and distinct. A route is simply a permutation of these destinations.