brain

tamnd's digital brain — notes, problems, research

41777 notes

CF 315A - Sereja and Bottles

Each bottle has two properties. The value a[i] is the bottle's own brand. The value b[i] is the brand of bottles that this bottle can open. A bottle can be opened if there exists some other bottle whose opening capability matches its brand.

codeforcescompetitive-programmingbrute-force
CF 314C - Sereja and Subsequences

We are given an array of positive integers. Consider every distinct non-empty non-decreasing subsequence of the array. For each such subsequence $y = (y1,dots,yk)$, we count all positive integer sequences $x = (x1,dots,xk)$ satisfying $$xi le yi$$ for every position.

codeforcescompetitive-programmingdata-structuresdp
CF 314A - Sereja and Contest

The participants are listed in final rank order. Participant i has rating a[i]. For a table of size m, if a participant currently occupies position p, his rating change is $$d = sum{text{participants before him}} aj (posj-1) - ai (p-1)(m-p)$$ In the original statement this…

codeforcescompetitive-programmingimplementation
CF 314E - Sereja and Squares

The geometric description hides a much simpler combinatorial structure. Take a pair of points $(l,0)$ and $(r,0)$, with $l<r$. The left endpoint is marked by a lowercase letter and the right endpoint by the corresponding uppercase letter.

codeforcescompetitive-programmingdp
CF 314D - Sereja and Straight Lines

We are asked to place two perpendicular lines on a plane so that one of them makes a 45-degree angle with the x-axis, and the maximum Manhattan distance from a set of given points to either line is minimized. The input provides the coordinates of n points on the plane.

codeforcescompetitive-programmingbinary-searchdata-structuresgeometrysortingstwo-pointers
CF 314B - Sereja and Periods

We are given two strings, a and c, and two integers, b and d. The string a is repeated b times to form a long string w, and the string c is repeated p times to form another string q.

codeforcescompetitive-programmingbinary-searchdfs-and-similarstrings
CF 313A - Ilya and Bank Account

The problem centers on Ilya’s bank account balance, which is a signed integer. Positive values indicate savings, and negative values indicate debt.

codeforcescompetitive-programmingimplementationnumber-theory
CF 313C - Ilya and Matrix

We are asked to construct a $2 times n times 2 times n$ square matrix from a given list of $4n$ integers such that a recursively defined "beauty" measure is maximized.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationsortings
CF 313E - Ilya and Two Numbers

Codeforces 313E: Ilya and Two Numbers

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdsugreedy
CF 313D - Ilya and Roads

We have a row of holes on a road, numbered from 1 to $n$. Each hole can be repaired by hiring one of $m$ companies.

codeforcescompetitive-programmingdp
CF 313B - Ilya and Queries

We are given a string composed solely of the characters "." and "". The task is to answer multiple queries efficiently. Each query asks, within a substring from position l to r, how many times a character is immediately followed by an identical character.

codeforcescompetitive-programmingdpimplementation
CF 312B - Archer

Two archers shoot at a target alternately. SmallR shoots first and hits with probability $a/b$ on each shot. Zanoes hits with probability $c/d$ on each shot. As soon as someone lands the first hit of the match, the game ends and that player wins.

codeforcescompetitive-programmingmathprobabilities
CF 312A - Whose sentence is it?

We are given a small chat log with up to 10 sentences. Each sentence is a string of letters, underscores, commas, periods, and spaces. Two people, Freda and Rainbow, are involved. According to prior experience, Freda always ends her sentences with the substring "lala.

codeforcescompetitive-programmingimplementationstrings
CF 295A - Greg and Array

We are given an array of integers, and we need to perform multiple operations on ranges of this array. Each operation specifies a contiguous segment of the array and a value to add to every element in that segment.

codeforcescompetitive-programmingdata-structuresimplementation
CF 277D - Google Code Jam

Vasya is participating in a programming round with several problems, each split into a Small and a Large input. Completing the Small input of a problem gives him a guaranteed number of points in a certain amount of time.

codeforcescompetitive-programmingdpprobabilities
CF 277B - Set of Points

We are asked to construct a set of n points on the 2D plane such that the largest convex polygon that can be formed from these points has exactly m vertices. No three points may lie on a straight line.

codeforcescompetitive-programmingconstructive-algorithmsgeometry
CF 277E - Binary Tree on Plane

We are given a set of points in the plane, each with distinct coordinates, and we are asked to connect them into a directed rooted binary tree with the additional geometric constraint that every edge must go downward in the plane.

codeforcescompetitive-programmingflowstrees
CF 277C - Game

Every interior grid line of the paper is divided into unit segments by the lattice points. A cut along a grid line marks all unit segments touched by the knife as already cut. The crucial observation is that the geometry of the paper never changes.

codeforcescompetitive-programminggamesimplementation
CF 311E - Biologist

We are asked to maximize the net money SmallR can gain from an experiment on dogs, where she can change each dog’s sex at a given cost.

codeforcescompetitive-programmingflows
CF 311D - Interval Cubing

We are given an array of integers and a sequence of queries. Each query is either asking for the sum of a subarray or instructing us to cube every element in a subarray. The output consists of the answers to the sum queries, computed modulo 95542721.

codeforcescompetitive-programmingdata-structuresmath
CF 311A - The Closest Pair

We are given a set of points in a 2D plane. The original geometric task would normally be to compute the smallest Euclidean distance among all pairs of points.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 309A - Morning run

We are asked to compute the expected number of collisions between runners on a circular track. Each runner starts at a distinct position along a track of length l and chooses to run either clockwise or counter-clockwise with equal probability.

codeforcescompetitive-programmingbinary-searchmathtwo-pointers
CF 309C - Memory for Arrays

We are given a memory layout split into several contiguous free segments, which we can think of as independent blocks of space. Each block has a fixed length, and we also have a collection of arrays we may want to place into this memory.

codeforcescompetitive-programmingbinary-searchbitmasksgreedy
CF 309E - Sheep

We are given a collection of segments on a very large number line. Each sheep corresponds to one segment, and two sheep become “connected” if their segments overlap in at least one point. After this preprocessing, we must arrange all sheep in a single linear order.

codeforcescompetitive-programmingbinary-searchgreedy
CF 309D - Tennis Rackets

We are asked to count the number of obtuse triangles that can be drawn inside an equilateral triangular tennis racket frame. The racket’s three sides each have n equally spaced holes.

codeforcescompetitive-programmingbrute-forcegeometry
CF 309B - Context Advertising

We are given a sequence of words in fixed order, and we want to select a consecutive block of them, starting at some position and ending later, such that this block can be printed on a rectangular banner.

codeforcescompetitive-programmingdptwo-pointers
CF 300B - Coach

We are asked to divide n students into teams of exactly three. Some students explicitly request to be on the same team with certain other students. These requests are mutual, so if student 2 wants to team with student 5, then student 5 also wants student 2.

codeforcescompetitive-programmingbrute-forcedfs-and-similargraphs
CF 300C - Beautiful Numbers

We are given two fixed digits, and we are allowed to build length-n numbers using only those two digits. Any such number is considered “valid” in the first sense, because every position is constrained to a two-element alphabet instead of the full decimal set.

codeforcescompetitive-programmingbrute-forcecombinatorics
CF 300E - Empire Strikes Back

We are asked to determine the minimum positive integer $n$ such that the factorial $n!$ divided by a set of numbers $[a1, a2, dots, ak]$ produces an integer. In other words, the Empire has a strike strength $n!$, and each Republican strike is represented by $ai$.

codeforcescompetitive-programmingbinary-searchmathnumber-theory
CF 300D - Painting Square

We are given a square table of size n × n, initially all white, with a black border around the edges. Vasily the bear can perform exactly k painting moves.

codeforcescompetitive-programmingdpfft
CF 300A - Array

We are given an array of distinct integers and asked to split it into three non-empty sets. The first set must have a product less than zero, the second set a product greater than zero, and the third set a product equal to zero.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsimplementation
CF 297C - Splitting the Uniqueness

We are given an array of distinct non-negative integers s of length n. The goal is to split each element s[i] into a pair of non-negative integers a[i] and b[i] such that a[i] + b[i] = s[i]. We want both a and b to be almost unique.

codeforcescompetitive-programmingconstructive-algorithms
CF 297B - Fish Weight

The task is to determine whether it is possible for Alice's total fish weight to strictly exceed Bob's, given only the types of fish each caught. Fish types are numbered from 1 to k in non-decreasing weight order, but the exact weights are unknown.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 297E - Mystic Carvings

We are given a circle with $2n$ labeled points arranged in order around the boundary. Each point is used exactly once as an endpoint of a chord, so the chords form a perfect matching on these $2n$ positions. Each chord connects two boundary points.

codeforcescompetitive-programmingdata-structures
CF 297D - Color the Carpet

We are asked to color an h × w grid using at most k colors, while satisfying as many adjacency constraints as possible. Each square in the grid must be assigned an integer color between 1 and k.

codeforcescompetitive-programmingconstructive-algorithms
CF 297A - Parity Game

We are given two binary strings, and we can transform the first string using two operations that behave like a sliding window with a dynamically growing tail. The first operation appends a single bit determined by the parity of the current number of ones in the string.

codeforcescompetitive-programmingconstructive-algorithms
CF 296B - Yaroslav and Two Strings

We are given two digit strings of equal length, but some positions may contain unknown characters represented by ?. Each ? can independently be replaced by any digit from 0 to 9, and choices in different positions do not interact.

codeforcescompetitive-programmingcombinatoricsdp
CF 296A - Yaroslav and Permutations

Yaroslav has a sequence of integers, and he wants to rearrange them so that no two consecutive elements are equal. The only allowed operation is swapping two neighboring elements, and he wants to know if it is possible to reach a configuration satisfying this condition.

codeforcescompetitive-programminggreedymath
CF 295C - Greg and Friends

Every person weighs either 50 kg or 100 kg. A boat starts on the left bank and can carry any non-empty group whose total weight does not exceed the boat limit. Somebody inside the boat must steer it, so every crossing contains at least one passenger.

codeforcescompetitive-programmingcombinatoricsdpgraphsshortest-paths
CF 295E - Yaroslav and Points

We have a set of points on the number line. Each point has an identity, so when an update says "move point p by d", only that specific point changes position. There are two operations.

codeforcescompetitive-programmingdata-structures
CF 295D - Greg and Caves

We are asked to count the number of ways to paint a rectangle of size n by m with black and white cells so that it forms a "cave." In practical terms, each row can either be all white or have exactly two black cells.

codeforcescompetitive-programmingcombinatoricsdp
CF 295B - Greg and Graph

We are given a complete weighted directed graph with n vertices, represented as an adjacency matrix. Each entry a[i][j] is the weight of the edge from vertex i to vertex j. The graph is complete, so every pair of distinct vertices has an edge in both directions.

codeforcescompetitive-programmingdpgraphsshortest-paths
CF 294A - Shaass and Oskols

We are given a sequence of horizontal wires, each with some birds sitting on it. Wires are numbered from top to bottom, and on each wire, the birds are lined up from left to right. Shaass shoots birds one by one.

codeforcescompetitive-programmingimplementationmath
CF 294C - Shaass and Lights

We have a row of n lights. Some positions are already on, and all other positions are off. A move consists of choosing an off light that has at least one adjacent light already on, then switching it on. We continue until every light becomes on.

codeforcescompetitive-programmingcombinatoricsnumber-theory
CF 294E - Shaass the Great

We are given a tree with n cities connected by n-1 roads, where each road has a positive length. Every pair of cities has a unique path connecting them.

codeforcescompetitive-programmingdptrees
CF 294D - Shaass and Painter Robot

We have a kitchen floor of size n×m tiles, all initially white. A robot stands on a border tile at coordinates (xs, ys) and faces one of the four diagonal directions. Each time the robot moves to a tile, it paints it black. If it hits a wall, it reflects like a billiard ball.

codeforcescompetitive-programmingbrute-forceimplementationnumber-theory
CF 294B - Shaass and Bookshelf

We are given a collection of books, each with a thickness of either 1 or 2 units and a width representing how many pages it occupies horizontally. Shaass wants to arrange all books on a single bookshelf.

codeforcescompetitive-programmingdpgreedy
CF 293B - Distinct Paths

Codeforces 293B: Distinct Paths

codeforcescompetitive-programmingbrute-forcecombinatorics
CF 293A - Weird Game

We are asked to analyze a turn-based game between two players, Yaroslav and Andrey, who each have a binary string of length 2·n. They alternately pick positions from the combined index set {1, 2, …, 2·n}.

codeforcescompetitive-programminggamesgreedy
CF 293E - Close Vertices

We are given a tree with n vertices, where each edge carries a non-negative weight. For any two vertices, the distance between them can be measured in two ways: the number of edges along the path connecting them, and the sum of edge weights along that path.

codeforcescompetitive-programmingdata-structuresdivide-and-conquertrees
CF 293D - Ksusha and Square

We are given a convex polygon whose vertices have integer coordinates. Consider every lattice point, meaning every point with integer coordinates, that lies inside the polygon or on its boundary.

codeforcescompetitive-programminggeometrymathprobabilitiestwo-pointers
CF 293C - Cube Problem

The three original cubes had side lengths $a$, $b$, and $c$. Their total number of unit cubes was $$a^3+b^3+c^3.$$ Vitaly wanted to build one larger cube whose side length was $a+b+c$, which would require $$(a+b+c)^3$$ unit cubes.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 292B - Network Topology

We are given a connected undirected graph representing a computer network. The task is not to analyze arbitrary graph structure, but to determine whether the graph exactly matches one of three specific topologies. A bus topology is simply a path.

codeforcescompetitive-programminggraphsimplementation
CF 292A - SMSC

We are given a sequence of tasks that arrive at a corporation's SMS center. Each task consists of a time ti when it arrives and a number ci of text messages to send. The SMS center can send at most one message per second, and messages are queued in the order they arrive.

codeforcescompetitive-programmingimplementation
CF 292E - Copying Data

We are asked to maintain two arrays of integers, a and b, each of length n. The first array a is static: its values never change.

codeforcescompetitive-programmingdata-structures
CF 292D - Connected Components

We have an undirected graph representing a computer network. The vertices are computers and the edges are cables. The cables are numbered from 1 to m in the order they appear in the input.

codeforcescompetitive-programmingdata-structuresdfs-and-similardpdsu
CF 292C - Beautiful IP Addresses

We are given a set of decimal digits. We must find every IP address consisting of four integers between 0 and 255 such that, after writing the four numbers next to each other without dots, the resulting string is a palindrome. The digit restriction is strict.

codeforcescompetitive-programmingbrute-force
CF 291A - Spyke Talks

We are given a list of secretaries and, for each, either a Spyke session number or 0 if the secretary is idle. Each positive session number represents an ongoing call between exactly two people.

codeforcescompetitive-programming*specialimplementationsortings
CF 291C - Network Mask

Each IP address is really a 32-bit integer written in dotted decimal form. A subnet mask is also a 32-bit value, but it must have a very specific shape: some number of leading 1 bits followed by some number of trailing 0 bits.

codeforcescompetitive-programming*specialbitmasksbrute-forceimplementation
CF 291E - Tree-String Problem

We are given a rooted tree with $n$ vertices, where each edge is labeled with a non-empty string. The root of the tree is vertex 1. Each non-root vertex $v$ has a parent $pv$ and a string $sv$ on the edge from $pv$ to $v$.

codeforcescompetitive-programming*specialdfs-and-similarhashingstrings
CF 291D - Parallel Programming

We are asked to simulate a parallel memory-writing process. There are n processors and n memory cells. Each processor can only write to its corresponding cell, but all processors can read any cell. Initially, all cells except the last one contain 1, and the last cell contains 0.

codeforcescompetitive-programming*specialgreedy
CF 291B - Command Line Arguments

We are given a single command-line string written in the fictional Pindows operating system. A command line consists of lexemes, which are the tokens passed to a program. There are two ways a lexeme can appear. A normal lexeme is a maximal sequence of non-space characters.

codeforcescompetitive-programming*specialimplementationstrings
CF 290A - Mysterious strings

The entire task is a joke problem from the April Fools contest. The input is a single integer a between 1 and 40. Instead of computing anything, we must output a specific string associated with that position.

codeforcescompetitive-programming*specialimplementation
CF 290C - WTF?

The input is not a conventional mathematical specification. Instead, it is a small program written in LOLCODE. The task is to determine what that program computes and print the resulting real number. The first input value is read into a variable that controls a loop.

codeforcescompetitive-programming*specialgraph-matchingsimplementationtrees
Kvant Math Problem 1446

Let $P$ be a convex polyhedron in $\mathbb{R}^3$ with vertices $V(P)={A,V_1,\dots,V_8}$.

kvantmathematicsolympiad
Kvant Math Problem 1447

No mathematical exploration is possible because the statement of Kvant problem M1447 is not provided.

kvantmathematicsolympiad
Kvant Math Problem 1445

Let a natural number $N$ satisfy the condition that after deleting one digit that is not the first digit, the resulting number $M$ divides $N$ with an integer quotient.

kvantmathematicsolympiad
Kvant Math Problem 1444

Consider polynomials with a negative coefficient, such as $P(x) = -x + 2$ or $P(x) = x^2 - x + 1$.

kvantmathematicsolympiad
Kvant Math Problem 1443

The problem statement for Kvant M1443 is not included, and the graphical version is not available here.

kvantmathematicsolympiad
Kvant Math Problem 1442

Solution to Kvant math problem 1442.

kvantmathematicsolympiad
Kvant Math Problem 1441

The textual statement of Kvant problem M1441 is not included, and the graphical version is referenced but not provided here.

kvantmathematicsolympiad
Kvant Math Problem 1440

I can write the solution as requested, but I need the full text of Kvant problem M1440 in order to proceed.

kvantmathematicsolympiad
Kvant Math Problem 1439

Before I can begin the full solution in your requested six-section format, I need the precise text of Kvant problem M1439.

kvantmathematicsolympiad
Kvant Math Problem 1438

The textual statement of Kvant M1438 is not included, and the graphical version is not accessible here.

kvantmathematicsolympiad
Kvant Math Problem 1437

The problem statement is not provided in textual or graphical form.

kvantmathematicsolympiad
Kvant Math Problem 1436

The statement of Kvant problem M1436 is not included, and the note indicates only a graphical version exists in the issue.

kvantmathematicsolympiad
Kvant Math Problem 1435

Before writing the full solution, I need the exact textual statement of Kvant Problem M1435.

kvantmathematicsolympiad
Kvant Math Problem 1434

Consider a simple convex polyhedron, such as a cube or a tetrahedron, and imagine casting a shadow onto a plane with a point light source.

kvantmathematicsolympiad
Kvant Math Problem 1433

I can do this, but I need the **textual statement of Kvant problem M1433** to proceed.

kvantmathematicsolympiad
Kvant Math Problem 1432

Consider a sequence of positive numbers $a_1, a_2, \dots$.

kvantmathematicsolympiad
Kvant Math Problem 1431

Let the operation be $f(10k+d)=k+4d$ with $0\le d\le 9$.

kvantmathematicsolympiad
Kvant Math Problem 1430

The sequence ${a_n}$ is monotonic and integer-valued.

kvantmathematicsolympiad
Kvant Math Problem 1429

I see that you want a full Kvant-style solution in six sections, but the actual textual statement of problem M1429 is missing.

kvantmathematicsolympiad
Kvant Math Problem 1428

Before I start, I need the full text of Kvant problem M1428.

kvantmathematicsolympiad
Kvant Math Problem 1427

I notice that the textual statement of Kvant problem M1427 has not been provided.

kvantmathematicsolympiad
Kvant Math Problem 1426

Consider the function $f(n) = n + S(n)$, where $S(n)$ is the sum of the digits of $n$.

kvantmathematicsolympiad
Kvant Math Problem 1425

Consider a quadrilateral with three interior angles of $45^\circ$.

kvantmathematicsolympiad
Kvant Math Problem 1424

For a sequence $a_1,\dots,a_n$, the transformation replaces each entry by the number of strictly larger elements to its right.

kvantmathematicsolympiad
Kvant Math Problem 1423

Consider three players $A$, $B$, and $C$, each playing the same number of games against one another.

kvantmathematicsolympiad
Kvant Math Problem 1422

Before proceeding, I need the full textual statement of Kvant M1422.

kvantmathematicsolympiad
Kvant Math Problem 1421

I cannot write a solution to Kvant M1421 because the problem statement itself is not present in your message.

kvantmathematicsolympiad
Kvant Math Problem 1420

Before I begin writing the solution, I need the text of Kvant problem M1420.

kvantmathematicsolympiad
Kvant Math Problem 1419

I cannot write a solution to Kvant problem M1419 because the actual problem statement is not present in your message.

kvantmathematicsolympiad
Kvant Math Problem 1418

I cannot write a solution to Kvant problem M1418 because the problem statement itself is not present in the conversation.

kvantmathematicsolympiad
Kvant Math Problem 1417

I see that the problem statement for Kvant M1417 is not yet fully provided in text form.

kvantmathematicsolympiad
Kvant Math Problem 1416

Consider a small finite set of gangsters.

kvantmathematicsolympiad
Kvant Math Problem 1415

Consider two regular decagons, each with 10 vertices, and numbers $a_1,\dots,a_{10}$ on the first decagon and $b_1,\dots,b_{10}$ on the second, all natural numbers, summing to 99 on each decagon.

kvantmathematicsolympiad
Kvant Math Problem 1414

I do not yet have the full text of Kvant problem M1414.

kvantmathematicsolympiad
Kvant Math Problem 1413

Let $N$ be the number of inhabitants, $T$ the number of truth-tellers, and $L=N-T$ the number of liars.

kvantmathematicsolympiad
Kvant Math Problem 1412

I cannot write a rigorous solution to Kvant problem M1412 because the actual problem statement is missing.

kvantmathematicsolympiad