brain
tamnd's digital brain — notes, problems, research
43815 notes
We are given a line of ships, each with some durability, and a fixed attack pattern that always targets the current leftmost surviving ship, then the current rightmost surviving ship, and repeats this alternation until a total of $k$ attacks have been made or all ships sink.
Codeforces 483B: Friends and Presents
Codeforces 1975B: 378QAQ and Mocha's Array
Codeforces 1975E: Chain Queries
Codeforces 485A: Factory
Monocarp has a single log of wood that weighs exactly $2^n$ grams. He needs to split this log into pieces such that he can assemble exactly $k$ grams of wood for today's fireplace, leaving the remaining $2^n-k$ grams for tomorrow.
We have an array $a$, and a recursively defined value: $$f(1)=sqrt{a1}, qquad f(i)=sqrt{f(i-1)+ai}.$$ After every point update $ak leftarrow x$, we need the integer part of $f(n)$. The first obstacle is that the recurrence uses real numbers.
Codeforces 1976E: Splittable Permutations
We are given a fixed starting height $b0$ and we imagine building an integer path $b0, b1, ldots, bn$ where each step moves by exactly $+1$ or $-1$, but the path is never allowed to go below zero. This is a standard “walk on the non-negative integers” with unit steps.
We are given several independent games, each defined by a list of piles containing stones. Two players alternate turns.
We are asked to construct an exact sum using coins of values 1, 3, and 5. For each target amount n, we want to pay exactly n using any number of 3 and 5 coins, and we are only forced to use 1-coins when it becomes unavoidable.
We are given an $n times m$ grid sitting at height $z=1$, where each cell already contains a unit cube with a color.
We are given a circle of baskets numbered from 1 to $m$, and $n$ balls initially placed in distinct baskets. Alice repeatedly chooses one of the balls uniformly at random and moves it clockwise to the next basket.
We are asked to decide whether Alice can paint a ribbon of n parts using m colors such that Bob, who can repaint at most k parts into the same color, cannot make the entire ribbon monochromatic.
We are asked to count subsegments of length m in an array a that are “good” relative to another array b of length m. A subsegment is considered good if, after rearranging its elements, at least k of them match elements from b.
Codeforces 1976C: Job Interview
We are given a circle of n monsters, each with an initial energy level ai. They are numbered from 1 to n, and each monster attacks its clockwise neighbor simultaneously in a single round.
We are given up to 50,000 independent queries. For each query, a number n is provided, where 1 ≤ n ≤ 100000. A number is called a binary decimal if every digit in its usual decimal representation is either 0 or 1. Examples include 1, 10, 11, 101, and 1001.
We are given the names of the home and away teams, followed by a chronological list of card events during a football match. Each event specifies the minute, which team the player belongs to, the player's jersey number, and whether the referee gives a yellow card or a red card.
We are given a connected simple undirected graph with up to 50 vertices and at most 50 edges. Each edge can be used multiple times in a constructed multigraph, and we control how many copies of each edge we create through a non-negative integer array $x$.
We are given a sequence of basketball players, each with a passing range expressed as an interval $[li, ri]$. The players are numbered from 1 to $n$.
Codeforces 1973B: Cat, Fox and the Lonely Array
Codeforces 1976B: Increase/Decrease/Copy
We are given a village with n houses aligned in a row. Each resident has a preference for which side of a street they want to live on: left (0) or right (1).
We need to construct an array of length n such that exactly k of its cyclic shifts are sorted in nondecreasing order. A cyclic shift chooses some position as the new beginning of the array and wraps the remaining elements around.
We are given a tree and an operation that does not act on a single node, but on a layer of nodes: if we pick a center vertex $v$ and a distance $d$, we recolor every vertex whose shortest-path distance from $v$ is exactly $d$.
We are given a string s of length n. We want to find the smallest possible length L such that there exists a pattern string k of length L, repeated exactly n / L times, producing a string c of length n, and c differs from s in at most one position.
We are given a queue of n people waiting to ask Seraphim the Owl a question. Kirill arrives at the end of the line and wants to move forward so that he is among the first m people.
Complete Sindarin number system: cardinals 1–1000, ordinals 1st–10th, number compounds, duodecimal counting, and number words in place names.
We are asked to build a square city on a 2D Cartesian map such that it encloses all given mines, represented as points with integer coordinates. The sides of the square must remain parallel to the axes, and our goal is to minimize the area of the square.
We are given a set of cards, each labeled with a number from 1 to n. For each number i, we have ai cards of that type.
Codeforces 1976F: Remove Bridges
Each observation tower sits at a fixed position on a number line from 1 to n and has a current viewing radius given by its height. A tower can “see” every integer point whose distance from its position does not exceed its height.
Comprehensive guide to HSK 3 grammar: 把 construction, 被 passive, complements, conditionals, and intermediate patterns — with tables and examples.
We are given a rectangular grid of integers. A move starts at the top-left cell and ends at the bottom-right cell, and at each step we can only go either one cell down or one cell right. Every such move sequence forms a monotone path.
We are asked to consider a network of islands where initially every pair of islands is connected by a bridge. There are n islands, numbered from 1 to n, and Everule lives on island 1. Dominater can destroy up to k bridges to reduce the number of islands that Everule can reach.
The city is a rectangular grid. Every hotel and every restaurant is located at an intersection with coordinates $(x,y)$.
We are asked to decipher a message that has been encoded by a simple substitution cipher. Each letter in the original message is replaced with a fixed letter, so the mapping is one-to-one: different letters map to different letters, and the same letter always maps to the same…
Each vertex of the tree initially contains exactly one ant. A move chooses an edge $(u,v)$ and orders all ants currently gathered at $u$ to move to $v$. The ants obey only when the destination already contains at least as many ants as the source.
Comprehensive guide to HSK 9 grammar: native-level classical Chinese, literary production, oral defense mastery, and full C2+ control of written and spoken registers.
We are asked to construct a rooted tree with a specific number of vertices having 0, 1, or 2 children. The input gives three numbers: a vertices with 2 children, b vertices with 1 child, and c vertices that are leaves.
Codeforces 1975I: Mind Bloom
We are asked to distribute a fixed number of skill points between two attributes: damage per hit and hits per second, in order to minimize the total time to kill a sequence of monsters.
Codeforces 1973E: Cat, Fox and Swaps
Codeforces 1974B: Symmetric Encoding
We are given an array of integers, and two players split the array into two groups. Kirill is allowed to choose a subset that is neither too small nor too large, specifically at least two elements and at most $n-2$ elements. Those chosen elements form the red group.
We are simulating a queue of students where the front of the queue is repeatedly served for a limited number of minutes. Each student, once served, leaves to “process” their porridge for a fixed number of minutes, and then returns to the queue.
Codeforces 1975D: Paint the Tree
Codeforces 1975F: Set
We are given a line of monsters, each with some initial health. One operation consists of choosing a single monster as the starting point of a “chain lightning”.
We are given times expressed in the 24-hour clock format, for example 00:00 for midnight, 13:45 for one forty-five in the afternoon, or 23:59 for one minute before midnight. Our task is to convert each time into the 12-hour clock format, which uses the familiar AM and PM labels.
Each building has two independent pieces of information. The first string describes what class is held there. A building may need a mathematics professor, a computer science professor, or no professor at all. The second string describes which professor is initially located there.
We are asked to help Elsie evaluate her paintings on a 1D canvas of n cells. Each cell can be painted or left empty, and the painting's beauty is determined by a 2D array a.
We are given an $n times n$ grid that is fully determined by three values: the top-left cell, and two fixed increments that govern movement downwards and rightwards. Moving one step down always adds $c$, and moving one step right always adds $d$.
The clock is not a normal continuous display, it behaves like a repeating cycle of three states. Every cycle has length $3k$ seconds.
We are asked to maintain a rooted tree where each node starts with zero peaches. Two kinds of operations can happen. In a growth operation at node $x$, we can increase the number of peaches on the parent of $x$ or any node in the subtree of $x$.
We are asked to simulate a two-player game on an array of integers, but with a compressed representation where we only know the frequencies of each integer.
We are given an array where each position contains a value in the range $1$ to $m$, and a second array that defines a deterministic transformation on values: every value $x$ has a fixed replacement $bx$.
We are given a line of staircase steps, each step either needing repair or already fine. If a step is fine, it behaves like a zero in the input. If it is broken, it carries a positive cost value that represents its repair difficulty. The repair process is constrained by days.
We are given a long sequence of floating-point numbers, and we are asked to output a description of how to compute their total sum.
We are given an increasing list of positions, and a process that repeatedly deletes players from a line. In each round, we look at the current lineup and try to remove the players standing at positions $a1, a2, ldots, ak$.
In this problem, we are given a string of digits that a robot has produced. The robot operates under a simple but peculiar rule: for each digit in the string, if the digit is even, it will remain in the output string as-is.
We are given a circle of monsters, each with an energy level. The monsters attack their neighbor in a fixed clockwise order: monster 1 attacks monster 2, monster 2 attacks monster 3, and so on, with the last monster attacking the first.
The deck contains four kinds of cards. A draw-0 card consumes one playable card from your hand and gives nothing back. A draw-1 card replaces itself. A draw-2 card consumes one card and gives two new cards, so it increases your future drawing power by one.
We are given a collection of balls, each assigned one of n distinct colors, where color i has ai balls. We are allowed to group these balls, but each group can have at most two balls, and no two balls in the same group can have the same color.
Codeforces 491A: Up the hill
We are asked to count ordered pairs of integers $(a, b)$ with $1 le a le n$ and $1 le b le m$ such that $b cdot gcd(a, b)$ is divisible by $a+b$. The inputs are multiple test cases, each specifying a pair of limits $n$ and $m$.
We are given a string and we are allowed to cut it into contiguous pieces. The goal is to decide whether we can cut it so that every resulting piece is not a palindrome. If it is possible, we must also construct one such cut.
Codeforces 1974D: Ingenuity-2
We are asked to reverse a Fenwick Tree construction. A Fenwick Tree is normally defined for an array a of length n such that each element sk stores the sum of a contiguous subarray of a whose length is the lowest set bit of k.
We are given a square matrix of size $n times n$ initially filled with zeroes. Nene can perform two types of operations: either set an entire row to a permutation of $1$ through $n$ or set an entire column to such a permutation.
We are given a permutation, which is just an ordering of the numbers from 1 to n. We repeatedly apply a transformation that removes elements which are strictly smaller than at least one of their immediate neighbors.
We are given two binary strings of equal length. The first string, call it the reference string, defines a constraint on how a valid target string must behave. The second string is the one we want to stay as close as possible to after we adjust it into a valid configuration.
We are given an array a of length n, constructed from some unknown permutation p of the integers 0 through n-1. Each element of a satisfies the relation a[i] = MEX(p[1..i]) - p[i]. The task is to reconstruct any valid permutation p that produces this a.
Codeforces 1974E: Money Buys Happiness
We are given a collection of sticks, each with an integer length. The goal is to build as many regular polygons as possible using these sticks, with the restriction that each side of a polygon must be exactly one stick, and no stick can be reused.
The task is to reconstruct a set of four integers representing candy counts in boxes such that three properties are equal: the arithmetic mean, the median, and the range. We are given some subset of these four numbers (0 to 4) in arbitrary order.
Kirill wants to gather mushrooms under a Wise Oak to brew an elixir. Each mushroom has a magic power, and the strength of an elixir made from a group of mushrooms is the product of the count of mushrooms and the minimum magic power among them.
Codeforces 495B: Modular Equations
Maxim wants to buy exactly n yogurts from a store where a single yogurt costs a burles, but there is a promotion offering two yogurts for b burles. For each test case, we must calculate the minimum amount he can spend to buy exactly n yogurts.
We are given two rooted trees on the same labeled vertex set from 1 to n, both rooted at 1. Each tree is described by its parent array, so every node knows its immediate parent except the root.
We have an $n times n$ board. The white queen starts at the top-left corner $(1,1)$, and the black queen starts at the top-right corner $(1,n)$. Every other square contains a green pawn. A move is mandatory. On each turn, a player must capture some piece with their queen.
The task is to buy exactly k concert tickets over n days, with each day offering a ticket price ai. You are limited to buying at most m tickets per day. Additionally, every ticket you buy increases the price of all future tickets by the number of tickets bought on that day.
Codeforces 1975H: 378QAQ and Core
We are given three digits, a, b, and c, and must classify their relationship. A sequence is called a stair when the values strictly increase from left to right, meaning a < b < c.
Codeforces 1973A: Chess For Three
The problem asks us to find all integers x less than or equal to a given integer n such that x can be expressed as the sum of cubes of two positive integers in at least two distinct ways.
The problem defines a sequence of blocks, where each block contains the product of a consecutive range of integers.
We are given a string s containing only lowercase English letters (a-z) and digits (0-9). Each character has a corresponding mirror character: - Letters are mirrored across the alphabet. - a ↔ z - b ↔ y - c ↔ x - and so on. - Digits are mirrored across the digit range.
The problem asks us to determine if it is possible to construct a new array nums2 of the same length as nums1 where all elements are either all odd or all even.
Here is the full, detailed technical solution guide for LeetCode 3791 - Number of Balanced Integers in a Range, following your requested structure. The problem asks us to count all integers between low and high inclusive that are balanced.
The problem asks us to design an EventManager class that manages a set of events, each identified by a unique eventId and associated with a priority.
This problem asks us to find the smallest positive integer composed entirely of the digit 1 that is divisible by a given integer k. The input k is guaranteed to be between 2 and 100,000.
This problem gives us a string s of length n consisting of lowercase English letters. For every index i, we compare two characters: - The character at position i, which is s[i] - The character at the mirrored position from the other end, which is s[n - i - 1] We must find the…
We are given an m × n grid of integers. Starting from the top-left cell (0, 0), we must reach the bottom-right cell (m - 1, n - 1) by moving only right or down.
This problem asks us to determine the minimum cost required to acquire a set of items that satisfy two separate type requirements. We have three types of items: type 1, type 2, and type 3.
The problem asks us to compute the number of non-decreasing arrays of integers where each integer satisfies a specific digit sum constraint.
The problem gives us an integer array nums where every element is guaranteed to be one of three values: 0, 1, or 2.
The problem asks us to maximize a "score" obtained by splitting an integer array nums at a valid index i. For each split index i, the score is calculated as the sum of all elements from the beginning of the array up to i (prefixSum) minus the minimum value in the remaining…
We are given n people standing in a line, indexed from 0 to n - 1. Each person independently chooses one of two directions: - 'L' means the person is visible only to people on their right. - 'R' means the person is visible only to people on their left.