brain

tamnd's digital brain — notes, problems, research

41230 notes

CF 104010F - Lazy to Win

We are given a sequence of problem scores laid out in a fixed order. Each position has a positive value, and solving a problem yields that many points.

codeforcescompetitive-programming
CF 104010E - Just Like Pickle

We are standing at position zero on an infinite number line and want to reach some target coordinate $x$, which can be positive, negative, or zero. In one move, we choose a non-negative integer $k$, and then jump either left or right by exactly $2^k$.

codeforcescompetitive-programming
CF 104010A - Rain Diary

We are given a strictly convex polygon, and we imagine choosing a point inside it. For any fixed direction, we draw the maximal chord of the polygon that passes through this point and is parallel to that direction.

codeforcescompetitive-programming
CF 104010B - Magnetic Games

We are given an $n times m$ grid. One unknown cell contains a magnet. Every other cell contains a compass that points toward the magnet using one of 8 discrete directions: four axis-aligned directions and four diagonals.

codeforcescompetitive-programming
CF 104010D - The Tree

We are working with an infinite complete binary tree where every node has a left child and a right child. Initially, every node is uncolored. We receive two kinds of operations.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 76

Let $U={0,1,\dots,n-1}$ and let each subset $S\subseteq U$ be identified with its characteristic integer $s=\sum_{e\in S}2^e$.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104010C - Campfire Riddle

We are given a group of $n$ people. Each person $i$ has an associated number $di$, which represents how many friends that person has. The friendship rule is unusually rigid: two distinct people $i$ and $j$ are friends if and only if they have the same value $di = dj$.

codeforcescompetitive-programming
CF 104011G - Grand Center

We are given a strictly convex polygon, and we imagine choosing a point inside it. For any fixed direction, we draw the maximal chord of the polygon that passes through this point and is parallel to that direction.

codeforcescompetitive-programming
CF 104011M - Multithreaded Program

We are given several threads, and each thread contains a fixed sequence of assignment operations. Each operation writes a value to a named variable, and these writes happen in a strict order inside each thread.

codeforcescompetitive-programming
CF 104011N - New White-Black Tree

We are given a collection of independent trees. For each tree, every vertex comes with two numbers that describe how many incident edges of two different colors it should have in a valid reconstruction.

codeforcescompetitive-programming
CF 104011L - Letters Q and F

We are given a final picture of an $n times m$ grid consisting of white and black cells. This picture was produced by repeatedly stamping two fixed, non-rotated, non-mirrored patterns, called the letters Q and F.

codeforcescompetitive-programming
CF 104011K - Kaleidoscopic Route

We are given an undirected graph with weighted edges, where the weight is called colorfulness. The task is to travel from city 1 to city n, but not just by any path.

codeforcescompetitive-programming
CF 104011J - Journey in Fog

We are working on a one-dimensional street of fixed length $L$. One endpoint is Julia’s home at position $0$, and the other endpoint is Jane’s home at position $L$.

codeforcescompetitive-programming
CF 104011I - Imprecise Permutation Sort

We are given a hidden permutation of size $n$, where the values are a rearrangement of the integers from 1 to $n$. We cannot see the array directly. Instead, we can interact with it using two operations.

codeforcescompetitive-programming
CF 104011F - First to Solve

Each contestant has a personal list of problems they are capable of solving. For contestant $i$, problem $j$ has a nonzero time $a{i,j}$ if it is solvable, otherwise it is unusable.

codeforcescompetitive-programming
CF 104011H - Halfway There

We are given a number $n$, and we consider all integers from $1$ up to $n-1$. From this range, we keep only those numbers that share no common divisor with $n$ except 1. In other words, we filter the range by a coprimality condition relative to $n$.

codeforcescompetitive-programming
CF 104011E - Extreme Problem

We are working on a small fixed integer grid of size 21 by 21, where both coordinates range from minus 10 to 10. The task is not to compute anything dynamically but to construct a function over this grid and output it in reverse Polish notation using a restricted set of…

codeforcescompetitive-programming
CF 104011B - Boris and Berta

Exercise 225 constructs a ZDD whose paths encode all simple paths between two fixed vertices $s$ and $t$. The construction proceeds by a controlled search over partial edge sets: each ZDD node represents a state of the partial path, and each decision corresponds to including…

codeforcescompetitive-programming
CF 104011D - Day Streak

We are given a sequence of timestamps when problems were solved, already sorted in increasing order. Each timestamp represents a moment in continuous time, but the platform converts these moments into discrete “days” using a floor division after shifting time by a chosen…

codeforcescompetitive-programming
CF 104011C - Clean Up!

We are given a collection of file names, all consisting of lowercase letters. Charlie wants to delete all of them using a restricted version of the rm command.

codeforcescompetitive-programming
CF 104011A - Anno Domini 2022

We are given two points on a simplified timeline where every year is labeled either in the AD system or in the BC system. Each input line describes a year like “AD 2022” or “5508 BC”.

codeforcescompetitive-programming
CF 104012K - K-Shaped Figures

Exercise 225 constructs a ZDD whose paths encode all simple paths between two fixed vertices $s$ and $t$. The construction proceeds by a controlled search over partial edge sets: each ZDD node represents a state of the partial path, and each decision corresponds to including…

codeforcescompetitive-programming
CF 104012N - New Time

We are given two moments in a day written on a 24-hour digital clock. The first is the current displayed time, and the second is the target correct time.

codeforcescompetitive-programming
CF 104012M - Mex and Cards

We are given a multiset of cards where each card has a value between 0 and n − 1. At any moment, we know how many copies exist of each value. We are allowed to partition all cards into any number of non-empty groups.

codeforcescompetitive-programming
CF 104012L - Limited Swaps

We are given a permutation of numbers from 1 to n, initially arranged on a line of cubes. We are also given a target permutation of the same numbers.

codeforcescompetitive-programming
CF 104012J - Joking?

We are asked to construct a set of dice for up to five players. Each player gets one die, and all dice have the same number of sides, denoted by k, with k at most 120.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 75

Let $x_1\ldots x_{2^n}$ be a truth table of length $2^n$.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104012I - IQ Game

We have a circular arrangement of $n$ sectors, each sector initially holding at most one envelope. After several rounds, only $k$ envelopes remain, and their exact positions on the circle are known in clockwise order.

codeforcescompetitive-programming
CF 104012G - Greatest Common Divisor

We are given an upper bound $n$, and we consider all ordered pairs $(x, y)$ where both values lie between 1 and $n$. For each such pair, we run a modified version of the Euclidean algorithm.

codeforcescompetitive-programming
CF 104012H - Hidden Digits

We are given a sequence of digits of length $n$. For each position $i$, we impose a condition on the number $x + i$: when written in decimal, it must contain the digit $di$ somewhere in its representation.

codeforcescompetitive-programming
CF 104012F - Focusing on Costs

We start with a calculator that only stores a single real number and repeatedly applies one of six unary functions to it: sine, cosine, tangent and their inverses. The initial value is fixed at zero.

codeforcescompetitive-programming
CF 104012E - Easily Distinguishable Triangles

We are given an $n times n$ grid where each cell is either already painted black, already white, or empty. Empty cells are candidates where Eva may optionally draw a special black triangle.

codeforcescompetitive-programming
CF 104012D - Dice Grid

We are given an $n times n$ grid where each cell has a fixed color value. A cube starts at the top-left cell and must be moved to the bottom-right cell.

codeforcescompetitive-programming
CF 104012B - Bricks in the Wall

We are given a rectangular grid representing a wall, where each cell is either blocked or free. On the free cells we are allowed to place up to two additional rectangular bricks.

codeforcescompetitive-programming
CF 104012C - Computer Network

We are given a set of computers, each equipped with a single outgoing wire. If a computer uses its wire directly, sending one bit takes a fixed amount of time equal to its own delay value. In addition to these wires, there is a hub with a limited number of ports.

codeforcescompetitive-programming
CF 104012A - Absolutely Flat

We are given four numbers representing the current lengths of the legs of a table. The table is stable only when all four legs end up having exactly the same length.

codeforcescompetitive-programming
CF 104013N - Nunchucks Shop

We are working with a set of binary “sticks”, each stick being a sequence of length n where every position is either quartz or onyx. A finished product, a nunchuck, is formed by choosing two sticks and joining them end to end.

codeforcescompetitive-programming
CF 104013L - Lost Permutation

We are given an unknown permutation π on n elements, but we are not allowed to see it directly. Instead, we can feed the system any permutation f, and we receive back a transformed permutation g defined by conjugation through π, meaning that every value is relabeled by π…

codeforcescompetitive-programming
CF 104013M - Mind the Gap

We are given a set of distinct integers representing cards held by different players. There is also an initial pile that starts with a single card of value 0.

codeforcescompetitive-programming
CF 104013I - Integer Square

We are given a single year in the range from 1995 to 2019. Each year has a fixed contest winner (or a pair of winners in one special case), and the task is to output exactly the winner string corresponding to the given year.

codeforcescompetitive-programming
CF 104013J - Joint Password Storage

We are given several passwords, each a short string of length at most 50 made of digits and English letters. For every password, we must construct a collection of strings, all of the same length as the password, such that if we take the bitwise XOR of ASCII codes column by…

codeforcescompetitive-programming
CF 104013K - Keys and Locks Boolean Logic

We are given a boolean formula built from variables a through h and the operators not, and, and or with standard precedence rules. The formula defines which subsets of variables are considered valid. Each variable corresponds to a band member who may or may not be present.

codeforcescompetitive-programming
CF 104013H - Heroes of Coin Flipping

We are dealing with a complete knockout tournament with $2^k$ participants, where every match is a fair coin flip between two players.

codeforcescompetitive-programming
CF 104013G - Grammar Path

We are given two separate structures that must interact: a context-free grammar in Chomsky Normal Form and a directed graph whose edges are labeled by lowercase letters.

codeforcescompetitive-programming
CF 104013A - Archivist

We are given a single year in the range from 1995 to 2019. Each year has a fixed contest winner (or a pair of winners in one special case), and the task is to output exactly the winner string corresponding to the given year.

codeforcescompetitive-programming
CF 104013E - Easy Compare-and-Set

We are given a collection of operations on a single integer variable that starts with value c. Each operation has the form “if the current value equals a, then replace it with b”, otherwise it does nothing.

codeforcescompetitive-programming
CF 104013F - Futures Market Trends

We are given a sequence of daily oil prices and we want to inspect every contiguous subarray of length at least three. For each such segment, we look at the sequence of day-to-day differences inside it.

codeforcescompetitive-programming
CF 104013C - Corrupted Sort

We are given a hidden array of length $n$, containing a permutation of numbers from $1$ to $n$. We cannot see the array directly. Our only way to interact with it is to pick two positions $i < j$ and ask the judge to compare the values at those positions.

codeforcescompetitive-programming
CF 104013D - Display

We are given a library of pixel fonts where each printable character is represented as a fixed bitmap of size $w times h$. Each bitmap is a grid of and ., where means the pixel is lit and . means it is dark.

codeforcescompetitive-programming
CF 104013B - Bicycle

A cyclist is choosing between two monthly bike rental plans, and we need to compute the total cost of each plan over a fixed month. Each day, the cyclist uses the bike for a total of T minutes.

codeforcescompetitive-programming
CF 104014G - Сапёр 1D

We are given a mine placement on a strip of length $N$, where each position in the top row either contains a mine or is empty.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 74

Let $f(x_1,\dots,x_n)$ be a monotone Boolean function.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104014J - My Grandfather

We are given a directed acyclic structure with $N$ glades (nodes) and $M$ directed paths (edges). Each path has two fixed weights: the number of mushrooms and the number of berries collected when traversing it. Importantly, these values do not change across days.

codeforcescompetitive-programming
CF 104014K - Old Barabarian Rap

I don’t have the actual problem statement for Codeforces 104014K - Old Barabarian Rap in your message (it’s empty in the prompt), so I can’t reliably reconstruct the intended task or produce a correct editorial.

codeforcescompetitive-programming
CF 104014H - Match of the Millennium

I can’t reliably write an editorial for “Codeforces 104014H - Match of the Millennium” because the actual problem statement (and even the contest archive context) isn’t included in your prompt.

codeforcescompetitive-programming
CF 104014I - Piecewise Linear Functions

I can write the full editorial in the required format, but I’m missing the actual problem statement for Codeforces 104014I - Piecewise Linear Functions.

codeforcescompetitive-programming
CF 104014F - Туристы, достопримечательности и телескопы

There is a row of cities, each city containing a known number of attractions. In every city, a telescope is installed. Each telescope has a non-negative integer power.

codeforcescompetitive-programming
CF 104014D - На планете Иворил...

We are given a text consisting of multiple words, and each word is supposed to follow a simple phonetic rule of a fictional language. A word is valid if it is either a “noun” or a “verb” under this language definition.

codeforcescompetitive-programming
CF 104014A - Большой удой

Let $F$ denote the family of 5757 SGB words represented on variables $a1,dots,z5$ as in (131), and let the associated ZDD be constructed in the standard ordered way with variables processed in lexicographic order.

codeforcescompetitive-programming
CF 104014E - История версий

We are given a final version number of a project, written as a positive integer $N$. The project evolves month by month according to a fixed rule: if the current version has $k$ digits, then after one month it increases by the number consisting of $k$ ones.

codeforcescompetitive-programming
CF 104014C - Вендомат

We are given a vending machine that contains a collection of snack packs, each with a name and a price expressed in rubles and kopeks. The buyer also has a fixed amount of money, also expressed in the same format.

codeforcescompetitive-programming
CF 104014B - Сделай 100

We are given a fixed sequence of digits 1 2 3 4 0 in that order, and we are allowed to insert arithmetic operators between them, optionally group parts using parentheses, and optionally concatenate adjacent digits to form multi-digit numbers.

codeforcescompetitive-programming
CF 104015M - The Sum of Good Numbers

We are given a long digit string s that was formed by taking an array of positive integers and concatenating them without separators. Each original array element is a positive integer that does not contain the digit zero.

codeforcescompetitive-programming
CF 104015I - Tree Painting

Let $F$ denote the family of 5757 SGB words represented on variables $a1,dots,z5$ as in (131), and let the associated ZDD be constructed in the standard ordered way with variables processed in lexicographic order.

codeforcescompetitive-programming
CF 104015L - RBS

We are given several strings, each consisting only of opening and closing brackets. We are allowed to reorder these strings arbitrarily and then concatenate them into one long sequence. While scanning this final sequence from left to right, every position defines a prefix.

codeforcescompetitive-programming
CF 104015K - Staircases

We are working on an $n times m$ grid where each cell is either usable or blocked, and the grid changes over time as we toggle individual cells. After each toggle, we must report how many distinct “staircase paths” exist in the current grid.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 73

We are given a virtual address representation p = \pi(p)2^e + \sigma(p), \quad \pi(p)=p \gg e,\quad \sigma(p)=p \bmod 2^e, and we must show that a BDD node stored at address $p$ does not need to store...

taocpmathematicsalgorithmsvolume-4medium
CF 104015H - Colored Balls

We are given three piles of balls, each pile having a different color. In one move, we pick two balls of different colors, remove both, and replace them with a single ball of the third color.

codeforcescompetitive-programming
CF 104015J - Replacing Letters

We are given a string of lowercase English letters. The goal is to transform it into a string where characters never decrease when read from left to right, meaning each character is at least as large in alphabetical order as the previous one.

codeforcescompetitive-programming
CF 104015F - Coconuts

We are given a sequence of piles of coconuts, where each pile has some integer size. We are allowed to choose a single positive integer base value $x$, and then we only collect coconuts from those piles whose size is an exact positive power of $x$, meaning values of the form…

codeforcescompetitive-programming
CF 104015G - Training Session

We are given a collection of problems, where each problem is described by two attributes: a topic label and a difficulty value.

codeforcescompetitive-programming
CF 104015C - Groups

Let $F$ denote the family of 5757 SGB words represented on variables $a1,dots,z5$ as in (131), and let the associated ZDD be constructed in the standard ordered way with variables processed in lexicographic order.

codeforcescompetitive-programming
CF 104015E - Delete Two Elements

We are given an array of integers and we first compute its average value, which is the total sum divided by the number of elements. This average is not necessarily an integer, but it is a fixed rational value determined by the full array.

codeforcescompetitive-programming
CF 104015D - Rectangle Restoration

We are dealing with a rectangle with unknown side lengths, say $a$ and $b$, both strictly positive real numbers. We are not given the rectangle directly. Instead, we are told two aggregated pieces of information about its sides.

codeforcescompetitive-programming
CF 104015B - Computer Game

We are given a very small game board with exactly two rows and $n$ columns. A player starts at the top-left cell and wants to reach the bottom-right cell. Some cells are blocked by traps, and stepping onto a trap immediately makes the path invalid.

codeforcescompetitive-programming
CF 104015A - Candies

We are given a fixed number of candies and a school split into two groups of students: boys and girls. The principal must choose a positive integer amount of candies for each boy, and a different positive integer amount for each girl.

codeforcescompetitive-programming
CF 104017K - Gastronomic Event

I don’t have the actual statement for Codeforces 104017K - Gastronomic Event in your prompt (the input/output sections are empty), so I can’t reliably reconstruct the problem or produce a correct editorial without guessing.

codeforcescompetitive-programming
CF 104017G - Round Table

Let $F$ denote the family of 5757 SGB words represented on variables $a1,dots,z5$ as in (131), and let the associated ZDD be constructed in the standard ordered way with variables processed in lexicographic order.

codeforcescompetitive-programming
CF 104017L - Circular Maze

I don’t have the actual problem statement for Codeforces 104017L - Circular Maze in your prompt (the section is empty), so I can’t reliably reconstruct the intended solution or editorial.

codeforcescompetitive-programming
CF 104017I - Antennas

I can’t produce a correct editorial for “Codeforces 104017I - Antennas” because the actual problem statement is missing from your prompt.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 72

Algorithm S relies on a “unique table” that maps each triple $(V, LO, HI)$ to a unique node so that identical subfunctions share a single representation.

taocpmathematicsalgorithmsvolume-4medium
CF 104017J - Boundary

I can’t write a correct editorial for this yet because the actual problem statement for Codeforces 104017J - Boundary is missing from your prompt.

codeforcescompetitive-programming
CF 104017H - Pandemic Restrictions

I can’t write a correct full editorial for Codeforces 104017H - Pandemic Restrictions yet because the actual problem statement is missing from your prompt.

codeforcescompetitive-programming
CF 104017F - Bottle Arrangements

I can’t reliably write a correct editorial for this problem yet because the actual problem statement (what “Bottle Arrangements” is asking, the rules, and constraints) is missing from your prompt.

codeforcescompetitive-programming
CF 104017D - Ice Cream Shop

We are given a long straight coastline with huts placed at fixed positions. Hut $i$ sits exactly $100$ meters to the right of hut $i-1$, so the huts form a perfectly uniform line. Each hut contains some number of people who will each buy exactly one ice cream.

codeforcescompetitive-programming
CF 104017B - Drone Photo

A domino tiling of the $8times 8$ board assigns to each unit square a partner square so that every square belongs to exactly one $1times 2$ or $2times 1$ domino. The additional tatami condition forbids any grid vertex where four different dominoes meet.

codeforcescompetitive-programming
CF 104017E - Evolution of Weasels

I can’t write a correct editorial for this problem yet because the actual problem content is missing from what you provided.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 71

Algorithm S in Section 7.

taocpmathematicsalgorithmsvolume-4medium
CF 104017A - Organizing SWERC

I don’t have the actual statement of Codeforces 104017A “Organizing SWERC” in your prompt, and it’s not included in the sections to restate or derive from.

codeforcescompetitive-programming
CF 104017C - Il Derby della Madonnina

I don’t have the actual statement for Codeforces 104017C - Il Derby della Madonnina available in your prompt, and I can’t reconstruct the correct solution or editorial without knowing what the input/output rules are.

codeforcescompetitive-programming
CF 104018H - Громогласность

A domino tiling of the $8times 8$ board assigns to each unit square a partner square so that every square belongs to exactly one $1times 2$ or $2times 1$ domino. The additional tatami condition forbids any grid vertex where four different dominoes meet.

codeforcescompetitive-programming
CF 104018I - 42 причины посетить Вьетнам

I can’t write a correct Codeforces editorial without the actual problem statement. Right now you’ve provided the title and metadata, but the core content (what is given, what must be computed, constraints, and samples) is missing.

codeforcescompetitive-programming
CF 104018A - Сумма остатков

A domino tiling of the $8times 8$ board assigns to each unit square a partner square so that every square belongs to exactly one $1times 2$ or $2times 1$ domino. The additional tatami condition forbids any grid vertex where four different dominoes meet.

codeforcescompetitive-programming
CF 104018G - Сложная логистика

The task describes a production system where each “plan” is a vector of non-negative integers indicating how many units of each product type we manufacture. There are $n$ product types, but only $n-1$ types of raw materials.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 70

Let $LCOUNT[l]$ denote the number of nodes (or items) that must be accommodated at level $l$ in step S4 of Algorithm S, and let $b$ determine a table size $2^b$ used for storage at that level.

taocpmathematicsalgorithmsvolume-4medium
CF 104018F - Поиск сокровищ

I can’t write a correct editorial for this yet because the actual problem statement for Codeforces 104018F - “Поиск сокровищ” is missing from your prompt.

codeforcescompetitive-programming
CF 104018D - Невиданная наглость!

I cannot reliably locate the exact statement for Codeforces 104018D - “Невиданная наглость!” from the available data, and without the problem text any editorial would risk inventing details, which would defeat the purpose of a correct solution write-up.

codeforcescompetitive-programming
CF 104018E - Следы на полях

I can’t write a correct editorial yet because the problem statement for Codeforces 104018E - “Следы на полях” is missing from your prompt.

codeforcescompetitive-programming
CF 104018B - Ограбление века

I can write the full editorial in the exact format you want, but I’m missing the actual problem statement for Codeforces 104018B - “Ограбление века”.

codeforcescompetitive-programming
CF 104018C - Найти ладью

I don’t have the actual statement of Codeforces 104018C “Найти ладью” in your prompt, and without it I’d have to guess the rules of the problem, which would make the editorial unreliable.

codeforcescompetitive-programming