brain

tamnd's digital brain — notes, problems, research

43815 notes

IMO 1969 Problem 5

A convex quadrilateral is determined by four points in convex position, meaning all four lie on the boundary of their convex hull and no one lies in the convex hull of the other three.

imomathematicsolympiad
CF 105401M - White-Black-Tree

We are given a tree where every vertex is initially colored either white or black. The tree structure is fixed, but we are allowed to perform operations that swap the colors of two endpoints of any edge, and each such swap costs one unit.

codeforcescompetitive-programming
CF 105401L - Simple Tree Decomposition Problem

We are given a tree with $N$ vertices. We are allowed to remove any subset of edges. Once those edges are removed, the tree splits into connected components. The requirement is that every resulting connected component must have size either $A$ or $B$.

codeforcescompetitive-programming
CF 105401J - Running in the Plane

We are given a finite set of integer points in the plane, and we want to construct a small collection of allowed step vectors such that we can build a walk starting from the origin that visits every given point. The walk is a sequence of lattice points starting at $(0,0)$.

codeforcescompetitive-programming
CF 105401F - Jenga Game

We are given a vertical Jenga tower made of $N$ horizontal layers, each layer having three possible block positions. Each position is either present or missing.

codeforcescompetitive-programming
CF 105401H - Mosaic

We are given a grid of numbers that is supposed to come from an unknown black and white painting. Each cell of the grid is labeled with how many black cells appear in the 3 by 3 neighborhood centered at that position.

codeforcescompetitive-programming
CF 105401A - Automata Embedding

We are given a string of length $n$ over an alphabet of size $C$, but instead of working with the string directly, we look at its structure through the KMP prefix-function (failure function).

codeforcescompetitive-programming
CF 105401E - Hexagonal Tiling

We are given a regular hexagon of side length $N$, already decomposed into a fixed grid of unit equilateral triangles. The task is to cover the entire region using unit rhombuses, where each rhombus is formed by joining two adjacent unit triangles sharing an edge.

codeforcescompetitive-programming
CF 105401D - Graceful Triangles

We are given a fixed graph structure built from a chain of equilateral triangles. The vertices are laid out in a straight line, labeled from 1 to $n+2$.

codeforcescompetitive-programming
CF 105394K - Kitten of Chaos

We are given a long string composed only of four characters: b, d, p, and q. This string is printed on a rigid glass object.

codeforcescompetitive-programming
CF 105394M - Musical Mending

We are given a sequence of pitch offsets for piano keys relative to the first key. These values describe the current relative tuning, not the absolute frequencies, but they are consistent in the sense that shifting every key by the same constant would represent a valid…

codeforcescompetitive-programming
IMO 1969 Problem 4

Place $AB$ as a horizontal segment with $A,B$ fixed and the semicircle $\gamma$ above $AB$.

imomathematicsolympiad
CF 105394I - Interference

We are given a sequence of operations over a very large one-dimensional line, where positions can go up to 1e9. Two types of operations are performed online. The first type inserts a wave.

codeforcescompetitive-programming
CF 105394G - Geometric Gridlock

We are asked to fill an $h times w$ grid completely with connected pieces of size five cells. Each piece must be one of the classical pentomino shapes, meaning it is a connected set of five unit squares matching one of the twelve allowed geometric forms up to rotation and…

codeforcescompetitive-programming
CF 105394F - Fair Fruitcake Fragmenting

We are given the boundary of a simple polygon that represents a cake. The polygon is described by its vertices in counterclockwise order, and it has a strong structural property: it is invariant under a 180 degree rotation.

codeforcescompetitive-programming
CF 105394C - Copycat Catcher

We are given a reference program written as a sequence of tokens, and then multiple query programs. Each program is already tokenized, so we do not deal with raw characters but with a list of strings.

codeforcescompetitive-programming
CF 105390E - Innocent Students

We are given an array of integers representing answers from students sitting in a line. Each query either changes one student’s answer or asks about a contiguous segment of students together with a hypothetical correct answer value x.

codeforcescompetitive-programming
CF 105390A - Simple Update - I

We are given a binary string, meaning each position is either 0 or 1, and we are allowed to repeatedly apply a very specific local transformation.

codeforcescompetitive-programming
CF 105390F - Red Blue Tree

We are given a tree where each node carries two independent pieces of information: a color, either red or blue, and a positive weight.

codeforcescompetitive-programming
IMO 1969 Problem 3

A tetrahedron has six edges, so for each fixed $k \in {1,2,3,4,5}$ we are distributing edge lengths $a$ and $1$ across the complete graph $K_4$ in a way that can actually arise from a Euclidean embedd…

imomathematicsolympiad
CF 105388B - Square Locator

We are asked to reconstruct a geometric object from partial metric information. There is a square in the plane whose vertices lie on integer coordinates.

codeforcescompetitive-programming
IMO 1969 Problem 2

The expression is a finite linear combination of shifted cosine functions with positive weights decreasing geometrically.

imomathematicsolympiad
CF 105316D - Switching To Windows

We maintain a collection of labeled strings. Each string is introduced by a query, and from that moment it behaves like an object with an identifier equal to the time it was inserted. Alongside each string we store a numeric value.

codeforcescompetitive-programming
IMO 1969 Problem 1

The requirement is to construct infinitely many natural numbers $a$ such that for every natural number $n$, the integer $n^4 + a$ is composite.

imomathematicsolympiad
IMO 1968 Problem 6

The expression is

imomathematicsolympiad
IMO 1968 Problem 5

The functional equation applies a transformation

imomathematicsolympiad
IMO 1968 Problem 4

Assume a tetrahedron with vertices $A,B,C,D$ satisfies the opposite of the claim, meaning that at every vertex the three incident edges fail to form the sides of a triangle.

imomathematicsolympiad
CF 105388L - All-You-Can-Eat

We are interacting with a sequence of meals that arrive one by one, each carrying a non-negative calorie value. At any moment we may either ignore a meal or take it, but taking it adds it permanently to a current “plate set” whose total calorie sum must never exceed 1000.

codeforcescompetitive-programming
CF 105388H - Game Design

We are asked to count how many ways we can wire a system of one-to-one connections between entry portals and exit portals spread across levels 1 to n.

codeforcescompetitive-programming
CF 105388K - String and Nails

We are given a set of points in the plane, called nails. At any moment we imagine wrapping a tight rubber band around all remaining nails, so the band forms the convex hull of the current set.

codeforcescompetitive-programming
CF 105388D - Cycle Game

We are given a rectangular grid of size $n times m$, initially empty. Moves arrive one by one in a fixed order, and each move paints a previously unpainted cell black. After each move, we need to decide whether that move is allowed to be placed or whether it should be skipped.

codeforcescompetitive-programming
CF 105388F - Alternating Cycle

We are given a set of points in the plane, with the guarantee that no three are collinear. From this set, we are allowed to choose a non-empty subset and arrange it in a cyclic order.

codeforcescompetitive-programming
CF 105387N - Entomologist

We are given a partially corrupted description of a sequence that originally came from a simple formula. There is an unknown integer value $k$, and for each index $i$, the intended value is obtained by dividing $k$ by $i$ and rounding to the nearest integer using standard…

codeforcescompetitive-programming
CF 105387M - Cinema

We are given a row of $n$ seats and $n$ students. Each student has a preferred seat number, and each student also has a personal dissatisfaction cost parameter.

codeforcescompetitive-programming
CF 105387I - Line pinball

We are given a line of positions numbered from 0 to n. From each position i there is a fixed “launcher” that sends a ball forward. The distance it moves depends on the ball’s weight x through the expression i + floor(pi / x). A ball always starts at position 0.

codeforcescompetitive-programming
CF 105387G - Cubes

We are asked to count how many sequences of length n can be formed using three colors, red, green, and blue, where each position in the sequence is a cube.

codeforcescompetitive-programming
CF 105387J - There

We are simulating a constrained walk on a grid that represents a shop. The grid has $n$ rows and $m$ columns, where each cell is either empty or blocked. A person starts in the bottom-left corner of the grid and then follows a long sequence of movement commands.

codeforcescompetitive-programming
CF 105387E - Practical numbers

We are given a special class of integers called practical numbers. A number is practical when every integer from 1 up to that number can be formed as a sum of distinct divisors of the number.

codeforcescompetitive-programming
CF 105387C - Martian Meteorology

We are given a sequence of distorted 32-bit integer measurements coming from a Martian temperature sensor. The hardware fault is consistent across time: some fixed subset of bit positions has been flipped in every measurement, meaning that for those positions every recorded…

codeforcescompetitive-programming
CF 105387D - DNA

We are given a single long DNA strand composed of the four characters A, C, G, and T. From this strand, we can derive a second strand by applying a fixed pairing rule character by character: A pairs with T, and C pairs with G, and the pairing is symmetric.

codeforcescompetitive-programming
CF 105386K - Permutation

We are given a hidden permutation p of length n, meaning each number from 1 to n appears exactly once, but we do not know the order. We can ask queries. Each query is another length-n array q, where each entry is also between 1 and n.

codeforcescompetitive-programming
CF 105386L - Trails

We are working on an infinite grid of integer points. From every lattice point, you can move one step right or one step up for free, because there are standard unit edges in those directions.

codeforcescompetitive-programming
CF 105386H - Subarray

We are given an array of integers and we look at all possible contiguous subarrays. For any fixed subarray, we focus on its maximum value and we also count how many times that maximum value appears inside the subarray.

codeforcescompetitive-programming
CF 105386B - Gold Medal

There are several contests running in parallel. Each contest already has some number of participating teams, and you are allowed to distribute an additional pool of teams across these contests however you want.

codeforcescompetitive-programming
CF 105386D - Generated String

We start with a fixed base string $S$. Every operation builds new strings by cutting several substrings from $S$ and concatenating them in order.

codeforcescompetitive-programming
CF 105386E - Relearn through Review

We are given an integer array and a single operation that can be applied at most once. The operation picks a contiguous segment and adds a fixed value $k$ to every element in that segment.

codeforcescompetitive-programming
CF 105385K - Matrix

We are asked to construct an $n times n$ integer matrix using values from $1$ to $2n$, with two simultaneous requirements that interact in a very constrained way. First, every integer in the range $1 dots 2n$ must appear at least once somewhere in the grid.

codeforcescompetitive-programming
CF 105385H - Stop the Castle

We are given a large infinite chessboard, but only a small number of cells are occupied by two types of objects: castles and existing obstacles.

codeforcescompetitive-programming
CF 105385G - Cosmic Travel

We are given a fixed array of integers, and we imagine that every non-negative integer labels a “universe”. In universe j, each original value ai is transformed into ai XOR j, and then we sort these transformed values.

codeforcescompetitive-programming
CF 105385D - Hero of the Kingdom

We are given a trading simulation where a player can repeatedly convert money into flour and then convert flour back into money at a better price. The player starts with some amount of gold and has a limited amount of time.

codeforcescompetitive-programming
CF 105385C - Colorful Segments 2

We are given several independent test cases. Each test case consists of a set of closed segments on a number line, and we must assign each segment one of k colors. The restriction is that if two segments share the same color, they must not intersect at any point on the line.

codeforcescompetitive-programming
IMO 1968 Problem 3

Let $f(x)=ax^2+bx+c$.

imomathematicsolympiad
CF 105384L - Lalo's Lawyer Lost

We are given an undirected graph with a special structure: every edge belongs to at most one simple cycle. This means the graph is a cactus, so cycles do not overlap except possibly at shared vertices, and if you remove cycle edges appropriately the remaining structure becomes…

codeforcescompetitive-programming
CF 105384K - Knocker

We are given an initial array of small positive integers. One operation chooses a positive integer $x$, and then every element of the array is simultaneously replaced by its remainder when divided by $x$.

codeforcescompetitive-programming
CF 105384H - Highway Hoax

We are given a directed tree, meaning there are n nodes and n−1 edges, and if we ignore edge directions the graph is connected and acyclic. Each node is labeled either S or F.

codeforcescompetitive-programming
CF 105384G - Goodman

We are given a permutation $p$ over numbers from $1$ to $n$. We are allowed to choose another permutation $q$, which is simply an ordering of the same $n$ elements.

codeforcescompetitive-programming
CF 105384D - Daily Disinfection

We are given a line of positions representing a shelf. Each position is either empty or occupied by a book. The goal is to make every position “clean”, but there is a restriction: a position containing a book cannot be cleaned directly.

codeforcescompetitive-programming
CF 105384A - Aibohphobia

We are given a string for each test case and are allowed to permute its characters arbitrarily. After choosing a final arrangement, we examine every prefix of length at least two. The requirement is that none of these prefixes is a palindrome.

codeforcescompetitive-programming
CF 105383L - Lexicopolis

We are working on a directed graph where each edge has a weight that should be thought of as a “label” rather than a cost. A path is defined as a sequence of exactly $k$ directed edges starting at a fixed node $s$ and ending at a fixed node $t$.

codeforcescompetitive-programming
CF 105383K - Kingdom's Development Plan

We are given a set of projects, each labeled from 1 to n, together with a list of dependency rules of the form “project a must be finished before project b can start.

codeforcescompetitive-programming
CF 105383I - In Search of the Lost Array

We are given a hidden integer array of length $n$, where every element is between 1 and 100. We do not see the array directly. Instead, we are given the multiset of products formed by every pair of adjacent elements in that array.

codeforcescompetitive-programming
CF 105383H - Harmonious Passage of Magicians

We have two groups of agents starting at opposite ends of a one-dimensional corridor that contains exactly one extra empty cell.

codeforcescompetitive-programming
CF 105383D - Disbursement on Quarantine Policy

We are given a rectangular arrangement of passengers, modeled as an $n times m$ grid. Each cell represents one seat and contains either a definitely infected passenger, a definitely healthy passenger, or an uncertain passenger who is independently infected with probability $1/2$.

codeforcescompetitive-programming
CF 105383F - Fibonacci Lucky Numbers

We are given several test cases. Each test case provides an integer $n$, and from it we construct a very large index based on a power-of-seven expression: the target index is $7^n$.

codeforcescompetitive-programming
CF 105383B - Business Magic

We are given a line of stores, each store having a current profit value, which can be positive or negative. The goal is to maximize the total profit after applying at most one global operation called a blue spell and any number of local operations called green spells, with the…

codeforcescompetitive-programming
CF 105381M - The Tale of Professor Alya and the H-Index

We are given a list of citation counts for a researcher’s papers, already sorted in non-increasing order. Each number represents how many times a particular paper has been cited.

codeforcescompetitive-programming
CF 105381L - The Bag of Forgotten Coins

We are given a sequence of coins laid out in a line, where coin k has a fixed value v[k]. We are allowed to pick a subset of these coins, but there is a strict restriction: we cannot pick two coins whose indices differ by exactly one.

codeforcescompetitive-programming
CF 105381J - Randomized String Matching Algorithm

We are given two strings, a long text s and a pattern t. We scan every starting position in s where t could fit. For each such position, Tony’s algorithm tries to decide whether the substring is equal to t, but instead of checking all characters, it performs k random probes.

codeforcescompetitive-programming
CF 105381I - LIS Decrement

We are given a sequence of integers where each element carries a weight. From this sequence we are allowed to choose any subsequence, meaning we can delete elements while preserving order, and we care about two different quantities computed on that subsequence.

codeforcescompetitive-programming
CF 105381G - Graph Coloring Problem

We are given a connected undirected graph where each edge has a weight. For a fixed threshold value $x$, we conceptually “ignore” all edges whose weight is greater than $x$, and only keep edges with weight at most $x$.

codeforcescompetitive-programming
CF 105381H - Points Separation

We are given a fixed set of points in the plane, and then multiple query points. For each query point, we must choose a line such that the query point lies strictly on one side of the line and every given point lies strictly on the other side.

codeforcescompetitive-programming
CF 105381E - Elimination Game

We start with pebbles labeled from 1 to n, where pebble i has weight i. In each move, two currently available pebbles are selected and passed through one of two devices. One device always returns the lighter of the two inputs, the other always returns the heavier one.

codeforcescompetitive-programming
IMO 1968 Problem 2

The expression on the right side is quadratic in $x$, while the left side is a product of decimal digits, hence grows at most exponentially in the number of digits but remains extremely constrained di…

imomathematicsolympiad
CF 105381C - Trip Counting III

We are given a simple undirected graph with up to 300 vertices, where each input edge is guaranteed to exist and no duplicates appear. The graph represents travel routes between countries.

codeforcescompetitive-programming
CF 105381B - Trip Counting II

We are given a graph with $n$ nodes where every pair of nodes is potentially connected, but only $m$ of those edges are actually usable. Think of this as a simple undirected graph: each of the $m$ input pairs describes a working two-way road between two countries.

codeforcescompetitive-programming
CF 105381D - Rearrangement

We are given a rectangular grid with $n$ rows and $m$ columns. Each cell contains an integer, and the only operation allowed is to permute values independently inside each column.

codeforcescompetitive-programming
CF 105380C - Dhrumil The Pados Wali Aunty

We are given an array of size $2n$ representing fighting strengths of $2n$ friends. The task is to split them into two disjoint teams so that every person belongs to exactly one team, and both teams must contain an odd number of members.

codeforcescompetitive-programming
CF 105380F - Inversion Sum

We are asked to look at every permutation of numbers from 1 to n, compute how many inversions each permutation contains, and then sum those inversion counts over all permutations.

codeforcescompetitive-programming
CF 105380E - String Palindrome Game

We are given a string and multiple independent queries. Each query specifies a segment of the string, and we are only allowed to look inside that segment.

codeforcescompetitive-programming
CF 105380A - Who Hates Abhishek?

We are asked to construct a special kind of permutation of size n. A permutation here means we arrange the numbers from 1 to n exactly once each. The twist is that the permutation must behave like an involution without fixed points.

codeforcescompetitive-programming
CF 105364B - Papalindromes!

We are given a starting integer and a deterministic process that repeatedly transforms it. At each step, we take the current number, reverse its decimal representation, average the two values, and round the result down to an integer.

codeforcescompetitive-programming
IMO 1968 Problem 1

Let the triangle have consecutive integer side lengths.

imomathematicsolympiad
CF 105364F - Gold Cubes

Each test case describes a very small “production system” that assembles gold cubes from three types of nuggets. Every nugget type has a fixed weight in milligrams, and we are also given a maximum available count for each type.

codeforcescompetitive-programming
CF 105364E - Painting Crosswalks

We are given several independent road segments, each containing a set of existing painted crosswalk stripes. Every stripe is described by its starting position and its width, so each one occupies a continuous interval on a number line. These stripes may overlap or leave gaps.

codeforcescompetitive-programming
CF 105364D - Colored Towers

We are given several test cases. In each case, María owns disks of different colors, and for each color we know how many identical disks she has. She wants to partition all disks into several vertical towers.

codeforcescompetitive-programming
CF 105364A - Pairs

We are given several independent test cases. In each one, we receive an even-length list of integers, and we must decide whether it is possible to partition the numbers into pairs such that every pair has the same sum.

codeforcescompetitive-programming
CF 105363B - Closed by Subtraction

We are given several independent test cases. Each test case provides a finite set of distinct integers, and we need to decide whether this set satisfies a very specific structural property involving differences between elements.

codeforcescompetitive-programming
IMO 1967 Problem 6

Let $m$ be the total number of medals and let $n$ be the number of days.

imomathematicsolympiad
CF 105363F - Coloring the Grid

We are given a geometric construction that can be reinterpreted as a graph problem. There are two families of segments.

codeforcescompetitive-programming
CF 105363E - Beautiful Board

We are given a rectangular grid of $n times m$ cells, and we must assign each cell one of two colors. The coloring must satisfy two global conditions at the same time. First, exactly half of the cells must be black and the other half white.

codeforcescompetitive-programming
CF 105363C - Squares in the Notebook

The page is drawn with a fixed set of horizontal guide lines, equally spaced one centimeter apart, and a set of vertical guide lines placed at arbitrary x-coordinates.

codeforcescompetitive-programming
CF 105363D - Connecting Villages

We are given a network of villages connected by roads, where each road is initially unusable and becomes usable only after a certain number of hours. All roads “unlock” in parallel according to their own schedules. Once a road is unlocked, it can be used permanently.

codeforcescompetitive-programming
CF 105358L - 502 Bad Gateway

We are simulating a system that holds a single countdown timer whose initial value is random. At time zero, the timer is set to a uniformly chosen integer between 1 and T. Time then advances in discrete seconds. Every second, the timer decreases by one.

codeforcescompetitive-programming
IMO 1967 Problem 5

Testing small configurations clarifies what structure is forced by infinitely many vanishing power sums.

imomathematicsolympiad
CF 105358K - Match

We are given a complete bipartite setup with two groups of size $n$, which we can think of as left vertices indexed by $i$ and right vertices indexed by $j$. An edge between $i$ and $j$ exists only when the XOR of their values, $ai oplus bj$, is at least $k$.

codeforcescompetitive-programming
CF 105358I - Strange Binary

We are given a non-negative integer and asked to express it as a sum of powers of two, but instead of standard binary digits, each bit position can take the value −1, 0, or 1. The contribution of position i is ai · 2^i, and the total sum must equal the given number.

codeforcescompetitive-programming
CF 105358J - Stacking of Goods

We are given a sequence of goods, each with three attributes: a weight, an initial volume, and a compression factor. We must arrange all goods in a single stack. Once stacked, each item’s final volume is reduced depending on how much total weight is placed above it.

codeforcescompetitive-programming
CF 105358G - Game

Two players start with piles of chips. In each round they either have no change in position (a draw) or exactly one of them wins the round. A win is not just a point, it can immediately end the game if the winner already has at least as many chips as the opponent.

codeforcescompetitive-programming
CF 105358F - Tourist

We are tracking a single evolving value, the rating of a user. The rating starts at a fixed initial value, 1500, and then changes after each of n upcoming contests.

codeforcescompetitive-programming
CF 105358E - Escape

We are given an undirected, connected graph of rooms and passages. Sneaker starts at room 1 and wants to reach room n using as few passages as possible. The graph is simple in the sense that there are no self-loops and no multiple edges between the same pair of rooms.

codeforcescompetitive-programming