Problems

Pick a problem and write your solution in the built-in editor. The judge runs it against real test cases while you watch, and the wider archive is open to read whenever you like.

Total results1,178 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Cow RaceTwo cows run the same total time in constant-speed segments; count how many times the lead switches or is re-taken after a tie.Medium5SimulationImplementation+1No attempts yet1s128 MBJudgeable
TypoGiven a bracket string with at most one typo, count how many single-character flips turn it into a valid balanced bracket string.Medium5StringImplementation+2No attempts yet1s128 MBJudgeable
BookshelfPartition the books in order into shelves whose widths sum to at most L, minimizing the total of each shelf's maximum height.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Pasture WalkingGiven a weighted tree with N vertices and Q queries, find the path length between each queried pair of vertices.Medium5TreeDFS+2No attempts yet1s128 MBJudgeable
Switching LightsMaintain a binary array of N lights under M range-toggle and range-count operations, and print each query result.Medium5Segment treeArray+1No attempts yet1s128 MBJudgeable
Tallest CowGiven the tallest cow's height and index plus pairs where cow a sees cow b, find each cow's maximum possible height consistent with all observations.Medium5GreedyPrefix sum+2No attempts yet1s128 MBJudgeable
Wine Trading in GergoviaGiven net wine demands along a line summing to zero, find the minimum total transport cost (one unit per bottle per adjacent step).Medium5GreedyPrefix sum+2No attempts yet1s128 MBJudgeable
Quantum OperationsCompute the tensor product of several integer matrices and report its element extremes plus maximum and minimum row and column sums.Medium5ImplementationMatrix+2No attempts yet1s128 MBJudgeable
Maximum DamageOn a grid with obstacles, orcs, and blank cells, pick at most T blank cells as stations so the total number of orcs within Manhattan distance R is maximized.Medium5Prefix sumBrute force+1No attempts yet1s512 MBJudgeable
Tax SystemEach client's income is taxed through N progressive brackets with given widths and rates; compute the total tax for M clients, printed to two decimals.Medium5Prefix sumBinary search+2No attempts yet1s1024 MBJudgeable
Polygon AreaGiven a grid-aligned orthogonally convex polygon as a string of unit moves, compute its area.Medium5GeometryImplementation+1No attempts yet1s1024 MBJudgeable
MetroGiven the intervals between adjacent trains, find the wait time for each train so every gap becomes M with the smallest total waiting.Medium5GreedyMath+1No attempts yet1s1024 MBJudgeable
Ship JourneyFind the latest whole-minute departure so the ship reaches 100 km strictly before the deadline, minimizing travel time.Medium5SimulationBrute force+1No attempts yet1s128 MBJudgeable
Catching FishGiven up to 100 fish on a large grid and a fixed net perimeter, find the placement of the net that covers the most fish.Medium5Brute forcePrefix sum+1No attempts yet1s256 MBJudgeable
FactoryGiven two orderings of the same N numbers, count pairs of connecting cables that cross when drawn as straight lines.Medium5SortingPrefix sum+1No attempts yet1s256 MBJudgeable
RailwayGiven a weighted tree, compute the total weight of the unique path between each queried pair of cities.Medium5TreePrefix sum+1No attempts yet1s32 MBJudgeable
PearlsGiven demand and price per pearl for classes in increasing quality order, find the cheapest way to buy all pearls when each class's order may be upgraded to a higher class, paying 10 extra pearls' worth per purchase.Medium5Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
k-Even-Sum SequenceChange the fewest elements so that every contiguous block of length k in the sequence has an even sum.Medium5GreedyMath+2No attempts yet1s256 MBJudgeable
IslandGiven the edge lengths of a cycle, find the maximum over all pairs of towns of the shorter of the two arc distances.Medium5Two pointersPrefix sum+1No attempts yet3s512 MBJudgeable
Building BlocksFind the minimum number of add/remove block moves so that some k consecutive columns end up with equal height.Medium5Sliding windowPrefix sum+2No attempts yet1s128 MBJudgeable
Rectangles 2Count axis-aligned rectangles with vertices on grid points of an n x m grid whose perimeter is at least p.Medium5MathCombinatorics+2No attempts yet2s512 MBJudgeable
EncyclopediaGiven a stack of n pages and n sleeves, swap adjacent elements to make the two types alternate, and output the minimum number of swaps.Medium5GreedyArray+2No attempts yet1s128 MBJudgeable
The TravelerCompute the height and width of the smallest axis-aligned rectangle containing a walk given in repeated direction blocks.Medium5SimulationPrefix sum+1No attempts yet1s512 MBJudgeable
MatchesFlip the fewest matches in a row so fire lit at the left end spreads through every neighboring pair.Medium5Dynamic programmingPrefix sumNo attempts yet1s512 MBJudgeable
MerchantBuy in one city and sell in another along a line to maximize selling price minus buying price minus travel cost.Medium5GreedyPrefix sumNo attempts yet1s512 MBJudgeable
Telephone ExchangePick an integer tower height so the fees from houses fully covered by the circle exceed the height-dependent maintenance cost by as much as possible.Medium5GeometrySorting+2No attempts yet1s512 MBJudgeable
CitiesCount for each city on a directed line how many other cities are reachable through one-way and two-way roads.Medium5ArrayPrefix sumNo attempts yet1s128 MBJudgeable
Paper StripFind the longest contiguous block of numbers that adds up to exactly s, or print BRAK when none exists.Medium5Hash mapPrefix sumNo attempts yet1s128 MBJudgeable
Equalizing Water in GlassesGiven the water levels in n adjacent glasses, find the fewest pours between neighbors that make all levels equal.Medium5GreedyPrefix sumNo attempts yet1s128 MBJudgeable
The BoardFind the longest string of zeros followed by ones that appears as a subsequence of both given binary sequences.Medium5GreedyTwo pointers+1No attempts yet1s128 MBJudgeable
TowerEach resident climbs the steps from the bottom and stops before the first step whose height reaches their own.Medium5Binary searchPrefix sumNo attempts yet1s128 MBJudgeable
KonkotenacjaCount the ways to split the word into nonempty pieces joined by the literal separator kot, modulo 1000000007.Medium5Dynamic programmingPrefix sum+1No attempts yet2s128 MBJudgeable
The Tired Traveling SalesmanFind the integer point off all customer sites that minimizes total Manhattan distance and count how many such points tie.Medium5SortingMath+1No attempts yet1s128 MBJudgeable
Pretty good numbersCount the integers in each interval whose absolute gap between the proper-divisor sum and the number is within the limit.Medium5Number theorySorting+1No attempts yet1s128 MBJudgeable
LightsYou press switches that flip the rectangle from the origin to the switch and need the fewest presses to turn every bulb on.Medium5GreedyPrefix sumNo attempts yet1s128 MBJudgeable
Stacking BlocksReshape both towers into the V-shaped skyline with center height h at the lowest total cost of added and removed blocks.Medium5SortingPrefix sum+1No attempts yet1s128 MBJudgeable
The Lazy CowChoose the cell whose Manhattan diamond of radius K holds the most grass and output that sum.Medium5Prefix sumMatrixNo attempts yet1s128 MBJudgeable
Fair PhotographyAfter sorting cows by position, find the widest interval with equal numbers of G and H cows, where single-breed intervals also count.Medium5Prefix sumHash map+1No attempts yet1s128 MBJudgeable
VacationFrom a start city on a line with a fixed day budget where each move or city visit costs one day, pick the contiguous block with the most attractions.Medium5Two pointersPrefix sum+1No attempts yet5s64 MBJudgeable
Fuleco and the AntGiven positions A and B and a U/D string encoding depth changes along a tree walk, output the tree distance between the two forks.Medium5TreePrefix sum+1No attempts yet1s64 MBJudgeable
Andres IniestaYou remove up to K obstacles and choose a standing cell to maximize visible cells in its row and column.Medium5Brute forcePrefix sum+1No attempts yet1s128 MBJudgeable
Salad BarFind the longest contiguous block of apples and oranges where oranges never fall behind apples when added from either end.Medium5Prefix sumStack+1No attempts yet3s256 MBJudgeable
Market ShoppingYou choose exactly k prices per query to maximize the odd total, printing -1 when no odd sum exists.Medium5GreedySorting+1No attempts yet10s256 MBJudgeable
DebtFor every group size M, choose M loans to minimize M times the largest chosen loan minus their sum, and output the total of these minima.Medium5SortingPrefix sumNo attempts yet1s256 MBJudgeable
Travel CardGiven daily bus and train ride counts, compute the cheapest mix of single fares and 1, 7, and 30 day bus and travel passes.Medium5Dynamic programmingPrefix sumNo attempts yet1s256 MBJudgeable
Cent SavingsSplit up to 2000 item prices in order into at most d+1 consecutive groups so the sum of each group rounded to the nearest 10 cents is smallest.Medium5Dynamic programmingPrefix sumNo attempts yet5s512 MBJudgeable
Ssari and Bird's PyramidCount how many times a given letter appears in a requested pyramid row filled by repeating a word in alternating directions.Medium5MathPrefix sumNo attempts yet1s256 MBJudgeable
WindowFind the largest interior grid-aligned square whose border runs only along domino edges and report its size and top-left corner.Medium5Prefix sumBrute forceNo attempts yet8s256 MBJudgeable
Color BallsFor each ball, add up the sizes of all strictly smaller balls with a different color.Medium5SortingPrefix sum+1No attempts yet1s256 MBJudgeable
Palindrome??Answer up to a million queries asking whether a subarray of the given number sequence reads the same forward and backward.Medium5String matchingPrefix sumNo attempts yet1s256 MBJudgeable
Box BettingThe driver picks a random contiguous run of boxes, and the program reports how often its item sum lands below L, within L to U, or above U.Medium5Prefix sumBinary searchNo attempts yet1s256 MBJudgeable
Alphabet on a CircleStarting at a, walk the 26-letter circle with direction flips at given points and count how often the queried letter occurs in the first n spoken letters.Medium5MathPrefix sum+1No attempts yet2s64 MBJudgeable
Happy NumbersFind the smallest start of K consecutive integers with exactly L numbers that are at most M or prime, or output -1.Medium5Number theoryPrefix sum+1No attempts yet0.5s64 MBJudgeable
Load BalancingPlace one vertical and one horizontal fence between the odd-coordinate cow positions to minimize the largest cow count in any of the four regions.Medium5SortingPrefix sum+1No attempts yet2s512 MBJudgeable
Cleaning the Club Room!Pick exactly M evenings to reset dirt to zero so the sum of daily visitors times dirt since the last cleaning is smallest.Medium5Dynamic programmingPrefix sumNo attempts yet1s128 MBJudgeable
gCube (Large)Answer many range queries asking for the geometric mean of array values with nine digits after the decimal point.Medium5Prefix sumMathNo attempts yet5s512 MBJudgeable
Up and Down (Large)Find the fewest adjacent swaps that turn the sequence into one that rises to a peak and then falls.Medium5GreedyPrefix sumNo attempts yet5s512 MBJudgeable
Password Problem (Large)Choose how many typed characters to keep or erase to minimize the expected keystrokes to finish a password with known per-character correctness odds.Medium5ProbabilityPrefix sum+1No attempts yet5s512 MBJudgeable
Irregular Cakes (Large Input)Find the vertical cut positions that split the region between two polylines into G slices of equal area.Medium5GeometryBinary search+1No attempts yet5s512 MBJudgeable
Theme Park Roller CoasterSimulate R rides where groups at the front board until the next group cannot fit, then return to the back; report total earnings.Medium5QueueSimulation+1No attempts yet5s512 MBJudgeable
Traffic (Small)Given a tree and Q tickets, count how many tickets use each edge along the unique path, then report the edge with the largest count (smallest station pair on ties).Medium5TreePrefix sum+2No attempts yet2s512 MBJudgeable
Birthday PresentsPick a subset of presents whose price range is below D, maximizing total satisfaction.Medium5SortingSliding window+2No attempts yet2s512 MBJudgeable
Centipede legsGiven n and m notes, choose left and right leg counts summing to n, both at least 1, maximizing how many notes have l_i <= left and r_i <= right, breaking ties by smallest left count.Medium5MathPrefix sum+2No attempts yet2s512 MBJudgeable
Distinct rational numbersCount distinct values of a/b with 0 <= a <= b <= N, i.e. fractions in [0,1] with reduced denominator at most N.Medium5MathNumber theory+2No attempts yet2s512 MBJudgeable
WindowPick a uniformly random axis-aligned subrectangle of an H by W grid; find the expected number of cells times 9, modulo 1e9+7.Medium5MathCombinatorics+2No attempts yet1s512 MBJudgeable
Lucky TicketsCount digit strings of length 2N whose first N digits sum to the same value as the last N digits, modulo 1e9+7.Medium5Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
ResortChoose one-day, 3-day, and 5-day passes over a vacation with blocked days so every open day is covered at minimum cost, where 3 coupons buy a free one-day pass.Medium5Dynamic programmingGreedy+1No attempts yet2s512 MBJudgeable
Water PumpPlace one pump in a cell, let water drain toward it from both sides, and find the cell that removes the most water.Medium5ArrayPrefix sumNo attempts yet2s512 MBJudgeable
Isosceles Cube TriangleGiven column heights, find the largest h such that some 2h-1 consecutive columns can all be reduced to the shape 1,2,...,h,...,2,1.Medium5ArrayBrute force+1No attempts yet1s512 MBJudgeable
Mário's LockersGiven the positions of L free lockers, find the minimum number of swaps to gather N of them into consecutive positions.Medium5Sliding windowPrefix sum+2No attempts yet1s512 MBJudgeable
Making the Array PalindromicMerge adjacent elements (each merge sums them) so the resulting array reads the same forwards and backwards, using the fewest merges. All values are positive.Medium5Two pointersGreedy+2No attempts yet1s64 MBJudgeable
Binomial coefficient queriesGiven M pairs N and K, print the binomial coefficient C(N, K) modulo 1,000,000,007.Medium5CombinatoricsMath+1No attempts yet1s512 MBJudgeable
Reading ListTotal lifted books over a sequence of assignments, where each assigned book moves to the top of the tower.Medium5ArraySorting+2No attempts yet1s128 MBJudgeable
Banknotes and RouletteSplit banknotes so the two equal-sum groups leave the smallest leftover, then add half of twice that leftover to each person's total.Medium5Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Score of a SubsequenceFind the maximum over all contiguous subarrays of the weighted sum where the k-th element from the subarray start contributes k times its value.Medium5Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Segments greater than KCount the contiguous subarrays whose sum exceeds k.Medium5Two pointersPrefix sumNo attempts yet2s512 MBJudgeable
Company Culture 2Given a tree of boss relations, apply subtree-wide praise additions in real time and answer point total queries.Medium5TreeDFS+2No attempts yet5s512 MBJudgeable
Company Culture 3Employees sit in a rooted tree. A praise of w given to employee i from a subordinate adds w to i and every ancestor up to the president; type 2 queries ask an employee's running total.Medium5TreeDFS+2No attempts yet2s512 MBJudgeable
ParetoChoose k accounts maximizing B minus A, where A = 100k/N and B is their share of all money as a percent.Medium5GreedySorting+2No attempts yet1s64 MBJudgeable
RainwaterGiven stack heights across a 2D world, compute the total rainwater trapped between the blocks after heavy rain.Medium5ArrayTwo pointers+2No attempts yet1s256 MBJudgeable
Circular HighwayCount starting stations on a circular road where buying all fuel and driving forward never empties the tank before returning.Medium5Prefix sumGreedy+1No attempts yet1s512 MBJudgeable
Rectangles and QueriesGiven an N by N matrix with values at most 10, answer many rectangle queries, each asking how many distinct integers appear inside the submatrix.Medium5Prefix sumMatrix+2No attempts yet2s512 MBJudgeable
Hamming distance queriesGiven binary strings a and b, answer queries asking for the Hamming distance between a substring of a and a substring of b.Medium5Prefix sumString+2No attempts yet6s512 MBJudgeable
Building a ranchGiven an M by N grid with trees and rocks as obstacles, find the side length of the largest square subgrid that contains no obstacle.Medium5Dynamic programmingMatrix+2No attempts yet1s512 MBJudgeable
Stone Skipping (SUJEBI)For each step size d, sum the cells at multiples of d and pick the d with the largest sum, printing 0 0 if that sum is not positive.Medium5MathBrute force+2No attempts yet2s512 MBJudgeable
CuriosityFor each query [a, b], find the primes in the range in order and compute an alternating sum that triples odd-indexed primes.Medium5Number theoryPrefix sum+2No attempts yet1s128 MBJudgeable
Flea MarketEach person has a supply or demand of fleas at unit-distance positions; find the minimum total delivery cost.Medium5GreedyPrefix sum+1No attempts yet1s128 MBJudgeable
Rock Paper Scissors MachineGiven two RPS strings, choose where in the opponent's longer string to start matching your shorter string and report the most wins.Medium5StringString matching+2No attempts yet1s512 MBJudgeable
Purple RainGiven a string of R and B characters, find the contiguous block maximizing |r - b|, breaking ties by westernmost start then westernmost end.Medium5ArrayGreedy+2No attempts yet1s512 MBJudgeable
Candy SalesFor each day j, print the minimum over all i at most j of w_i + (j - i).Medium5ArrayPrefix sum+1No attempts yet6s512 MBJudgeable
DebugEach call increments every index divisible by the given jump; answer range-sum queries over the resulting array.Medium5ArrayMath+2No attempts yet3s512 MBJudgeable
Robot Energy Source OrderReorder n energy sources, each with acceleration a_i and duration s_i, to maximize total distance, and print the gain over the given order.Medium5SortingGreedy+2No attempts yet0.2s128 MBJudgeable
Trunk RoadsChoose one horizontal and one vertical line in an H by W grid to minimize the total distance residents at each cell pay to the nearer chosen line.Medium5Brute forcePrefix sum+1No attempts yet2s512 MBJudgeable
Art ExhibitionChoose a subset of artworks maximizing the sum of values minus the difference between the largest and smallest sizes in the subset.Medium5SortingPrefix sum+1No attempts yet1s256 MBJudgeable
Maximum range sum? 1Maintain an array under point updates. For each range query, find the maximum of U times a subarray sum plus V times its length over all subarrays inside the range.Medium5ArrayBrute force+2No attempts yet1s128 MBJudgeable
Cute RyanGiven a row of N dolls labeled 1 or 2, find the length of the shortest contiguous block containing at least K dolls labeled 1.Medium5Two pointersSliding window+2No attempts yet1s256 MBJudgeable
Roasting Emma is a barista tooGiven a weighted tree, compute for every vertex the sum of shortest distances to all other vertices.Medium5TreeDFS+2No attempts yet1.5s128 MBJudgeable
Rest StopsBessie rests at grass stops along a trail and must never fall behind Farmer John; maximize total tastiness of eaten grass.Medium5GreedySorting+2No attempts yet2s512 MBJudgeable
*Light*Young*Woo*Given N lights that each illuminate a 90-degree upward sector, count for each query point how many sectors contain it.Medium5GeometryPrefix sum+2No attempts yet1s512 MBJudgeable
DollsGiven N numbers in a fixed order, find a contiguous segment of at least K numbers whose standard deviation is minimized, and output that standard deviation.Medium5Brute forcePrefix sum+2No attempts yet1s512 MBJudgeable