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
Find the Playing NoteGiven note durations that partition a timeline, answer queries asking which note covers a given beat by locating the prefix sum that brackets it.Medium4Prefix sumBinary search+2No attempts yet1s128 MBJudgeable
Dining CowsGiven a sequence of 1s and 2s, find the minimum number of values to change so the sequence becomes nondecreasing.Medium4Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Long Distance RacingGiven a terrain string and per-unit times, find the farthest segment index k whose round-trip time stays within M seconds.Medium4ArrayPrefix sum+2No attempts yet1s128 MBJudgeable
Cow SolitaireGiven an N by N grid of cards with point values, find the maximum total score along a monotone path from the lower-left corner to the upper-right corner moving only right or up.Medium4Dynamic programmingMatrix+2No attempts yet1s128 MBJudgeable
Bridge TransportGiven car weights and a bridge that holds at most 4 cars, find the largest prefix that can cross without any window of 4 consecutive cars exceeding the weight limit.Medium4Sliding windowArray+2No attempts yet1s128 MBJudgeable
Grandpa's Lottery GamesGiven daily lottery spending and winnings, report the overall profit sign, the single day with the largest loss, and the consecutive run with the largest total loss.Medium4ArrayPrefix sum+2No attempts yet1s1024 MBJudgeable
Buffer ManagerGiven buffer states (free, digit worthiness, or locked) in a string, find the starting position of the K-length window without locked buffers whose digit sum is smallest.Medium4Sliding windowPrefix sum+2No attempts yet1s128 MBJudgeable
Rat AttackGiven weighted points on a 1025x1025 grid and a Chebyshev distance d, find the integer center covering the maximum total weight, breaking ties by smallest x then y.Medium4Prefix sumMatrix+1No attempts yet2s128 MBJudgeable
Handong the Salesman!Given a tree, start at node 1 and visit m listed nodes in order, summing the tree distances between consecutive stops.Medium4GraphTree+2No attempts yet1s128 MBJudgeable
Density MapFor each cell of an n by n binary grid, sum the entries within Chebyshev distance r, using a 2D sliding-window or prefix-sum over the square neighborhood.Medium4Prefix sumMatrix+1No attempts yet3s128 MBJudgeable
CalendarsConvert each given date to its day of year with one calendar, then locate the matching month and day in the other calendar.Medium4Prefix sumBinary searchNo attempts yet1s512 MBJudgeable
Gathering MushroomsChoose the earliest day t of at least 1 that maximizes the total weight of mushrooms still edible, where each weight grows daily.Medium4Prefix sumArrayNo attempts yet1s128 MBJudgeable
Flipping the Vegetable GardenApply up to one million rectangle flips to an n by n binary garden and print the final layout.Medium4Prefix sumMatrixNo attempts yet1s128 MBJudgeable
Dome StadiumChoose the village coordinate that minimizes the total fan-weighted travel distance.Medium4Prefix sumNo attempts yet1s256 MBJudgeable
Maximum DetourGiven the vertices of a polygonal path in order, compute the largest ratio of along-path length to straight-line distance over all vertex pairs.Medium4GeometryBrute force+1No attempts yet1s128 MBJudgeable
And Now For Something Completely Different!The program scans a chore record for split points where both halves favor the opposite child from the total and prints each match with rounded percentages.Medium4Prefix sumSimulation+1No attempts yet1s128 MBJudgeable
Longest Balanced Sub-SequenceFind the length of the longest contiguous block with equal counts of positive and negative numbers.Medium4Prefix sumHash mapNo attempts yet1s128 MBJudgeable
Diamond Mining ProfitsFind the contiguous period with the largest total gain across up to 2000 test cases, breaking ties by shorter length then earlier start.Medium4Dynamic programmingArray+1No attempts yet1s128 MBJudgeable
Counting SubsthreengsCount the contiguous digit-only substrings of S whose value is a multiple of 3.Medium4Prefix sumMathNo attempts yet3s256 MBJudgeable
Algorithms Final ExamGiven the final order listed by midterm rank, print for each student how many midterm superiors they passed minus how many inferiors passed them.Medium4Segment treePrefix sumNo attempts yet1s256 MBJudgeable
Train TravelCount how many times each rail is crossed and pay the cheaper of single tickets or a discount card plus cheap fares for every rail.Medium4Prefix sumGreedyNo attempts yet1s256 MBJudgeable
ACMSplit the task list into three nonempty consecutive blocks and assign one member to each block to minimize the summed difficulty estimates.Medium4Prefix sumBrute forceNo attempts yet1s64 MBJudgeable
Remainder Subarray CountCount contiguous intervals whose sum is divisible by M using prefix remainder frequencies.Medium4Prefix sumHash mapNo attempts yet1s256 MBJudgeable
Kindergarten ExcursionCount the minimum adjacent swaps needed to reorder a string of 0s, 1s, and 2s into sorted order.Medium4SortingPrefix sumNo attempts yet1s256 MBJudgeable
Icelandic MotorclubsFind the smallest-numbered station from which a rider who takes all gas at every stop can complete one clockwise lap.Medium4GreedyPrefix sumNo attempts yet3s256 MBJudgeable
Farey Sequence LengthCompute 1 plus the sum of Euler totient values up to N for each of up to 10000 data sets.Medium4Number theoryPrefix sum+1No attempts yet1s256 MBJudgeable
Word Clouds RevisitedPlace N ordered boxes of given widths and heights into width-limited rows to minimize the sum of row heights.Medium4Dynamic programmingPrefix sumNo attempts yet2s256 MBJudgeable
Two-Dimensional Range SumCompute the sum of each queried rectangle in an N by N table using a 2D prefix sum.Medium4Prefix sumMatrixNo attempts yet1s256 MBJudgeable
Subsequences Summing to SevensFind the length of the longest contiguous group of cows whose IDs sum to a multiple of 7.Medium4Prefix sumHash mapNo attempts yet2s512 MBJudgeable
Collecting Stamps 2Insert one J, O, or I stamp at any position to maximize the number of triples that read J, O, I in order.Medium4Prefix sumCombinatoricsNo attempts yet2s256 MBJudgeable
Sums of Sums (Small)You sort every contiguous subarray sum of an array and answer range sums over the sorted list.Medium4SortingPrefix sumNo attempts yet5s512 MBJudgeable
Sum of ImperfectionsAdd up, for every integer from A to B, the absolute gap between the number and the sum of its proper divisors.Medium4Number theoryPrefix sumNo attempts yet3s128 MBJudgeable
Pretty Good Proportion (Small)Given a binary string and a target fraction F, find the start index of the contiguous substring whose share of 1s is closest to F.Medium4Brute forcePrefix sumNo attempts yet5s512 MBJudgeable
Household LedgerProcess point additions and range-sum queries on a ledger of N days.Medium4Prefix sumNo attempts yet1s512 MBJudgeable
Climbing to the Information Science BuildingFind the crossing point k minimizing left-road distance from 1 to k plus crosswalk k plus right-road distance from k to n; output the smallest such k and the minimum distance.Medium4Prefix sumArray+2No attempts yet2s512 MBJudgeable
Important TestFor each variant, find the longest prefix solvable in t minutes given he may replace at most one task time with t0. Since order is fixed, choose the single task in that prefix whose copying saves the most time.Medium4ArrayPrefix sum+1No attempts yet2s512 MBJudgeable
Counting Equilateral TrianglesGiven arc lengths around a circle and points at the boundaries, count equilateral triangles whose three vertices are among the points.Medium4Prefix sumMath+1No attempts yet2s512 MBJudgeable
Sum of Divisor SumsGiven L and R, compute the sum of divisor sums f(n) for every n from L to R.Medium4MathNumber theory+1No attempts yet1s64 MBJudgeable
Counting HaybalesGiven N distinct haybale positions and Q interval queries, count how many positions fall inside each inclusive range [A, B].Medium4SortingBinary search+2No attempts yet2s512 MBJudgeable
Company culture 1Given each employee's manager and a list of praises, propagate every praise value down the whole subtree and print the total each employee receives.Medium4TreeDFS+2No attempts yet2s512 MBJudgeable
Safe Squares (Small)Count all axis-aligned D by D subgrids of an R by C grid that contain no monster cell.Medium4Dynamic programmingMatrix+2No attempts yet5s512 MBJudgeable
Hoof, Paper, Scissors (Silver)Given FJ's sequence of N gestures, find the most games Bessie can win if she switches her own gesture at most once.Medium4Prefix sumBrute force+1No attempts yet2s512 MBJudgeable
A Taste of QueriesGiven a sequence of n numbers, process q queries that either report a range sum and then swap two positions, or report one range sum minus another.Medium4ArrayPrefix sum+2No attempts yet2s256 MBJudgeable
TelescopeCount the horizontal shifts of an m by l weight grid over an m by n path where the weighted sum exceeds W.Medium4Sliding windowPrefix sum+2No attempts yet1s512 MBJudgeable
Jaehong's LadderGiven a rectangle's width, height, and a number of vertical strips, sum the lengths of the N-1 rungs where the strips cross the rectangle's diagonals.Medium4MathGeometry+2No attempts yet2s512 MBJudgeable
Sum of all pairwise productsGiven n integers, compute the sum of x_a * x_b over all pairs with a < b.Medium4MathPrefix sum+2No attempts yet2s512 MBJudgeable
Halfway PointGiven n, find the value printed when the pair-comparison loop reaches its halfway point (the last item index printed there).Medium4Binary searchMath+2No attempts yet1s512 MBJudgeable
Programming ExamFor each query, decide whether two given substrings of S are anagrams, printing DA or NE.Medium4Prefix sumHash map+1No attempts yet3s128 MBJudgeable
AutomobileStarting from a matrix where each cell holds its row-major index, apply K row and column multiplications and report the total sum modulo 1e9+7.Medium4MathImplementation+2No attempts yet1s64 MBJudgeable
Frosting on the CakeGiven vertical stripe widths A and horizontal stripe heights B, find the total area of each of the three colors where each cell's color is (i+j) mod 3.Medium4ArrayMath+2No attempts yet5s512 MBJudgeable
JujisuGiven an N by M grid of populations, answer K queries for the sum of people inside each requested rectangle.Medium4Prefix sumArray+2No attempts yet2s512 MBJudgeable
1, 2, 3 Sum 3Count the ordered ways to write n as a sum of 1, 2, and 3, with each test case answered modulo 1,000,000,009.Medium4Dynamic programmingMath+2No attempts yet1s512 MBJudgeable
ÜberwatchGiven a sequence of opponent counts over n time slices and a cooldown m, choose firing times at least m slices apart to maximize total opponents defeated.Medium4Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Human-Computer InteractionCount how often a given lowercase letter appears inside each query interval [l, r] of a fixed string S, answering up to 200,000 queries.Medium4Prefix sumArray+1No attempts yet1s256 MBJudgeable
Afraid of the DarkGiven an R x C grid of brightness values and Q rectangle corner queries, compute each rectangle's mean using integer division.Medium4Prefix sumMatrixNo attempts yet1s512 MBJudgeable
Plate ParityCount integers in [A, B] whose rightmost nonzero digit is odd versus even, where A and B go up to 10^16.Medium4MathImplementation+2No attempts yet1s512 MBJudgeable
Generic QueriesGiven an array and range queries, compute each interval XOR and output the XOR of all answers mixed with the given k values.Medium4Prefix sumBit manipulation+2No attempts yet2.5s512 MBJudgeable
Tabs vs SpacesFor each of up to 366 days, count tab and space guests from N intervals, then report occupancy days, peak headcount, fight-free days, peak headcount among those, and the longest stay length.Medium4ArraySimulation+2No attempts yet2s512 MBJudgeable
Sequence and Queries 21Support range-add updates and point queries on an array of up to 100,000 elements with up to 100,000 operations.Medium4ArrayPrefix sum+1No attempts yet2s512 MBJudgeable
Goldbach PartitionFor each even N up to one million, count the unordered pairs of primes that sum to N.Medium4Number theoryMath+2No attempts yet0.5s512 MBJudgeable
Goldbach Partition 2For each even N up to 1,000,000, count unordered pairs of primes that sum to N.Medium4Number theoryPrefix sum+2No attempts yet0.5s512 MBJudgeable
Array PlayGiven an N by N grid and M rectangle-add operations, output the final sum of each row and each column.Medium4Prefix sumArray+2No attempts yet2s512 MBJudgeable
Sum of Divisors 2Given N, compute the sum over all y from 1 to N of the sum of divisors of y, by counting how often each integer divides some value up to N.Medium4MathNumber theory+2No attempts yet0.5s512 MBJudgeable
Inquiry ISplit the array into a prefix and a suffix at some index k; maximize the sum of squares of the prefix times the sum of the suffix.Medium4Prefix sumArray+2No attempts yet3s512 MBJudgeable
Tired TerryGiven a circular sleep pattern of length n, count for how many seconds i the preceding p seconds contain fewer than d seconds of sleep.Medium4Sliding windowPrefix sum+2No attempts yet1s512 MBJudgeable
Short SellGiven N daily prices and a daily interest K per 100 borrowed coins, pick a borrow day and a repay day to maximize profit.Medium4ArrayPrefix sum+2No attempts yet1s512 MBJudgeable
MinecraftGiven N by M ground heights and B starting blocks, pick a target height that minimizes flattening cost (remove 2s, place 1s, no outside blocks), breaking ties by the highest target.Medium4ImplementationBrute force+2No attempts yet1s1024 MBJudgeable
ABBGiven a string of colors, find how many characters must be appended at the end so the resulting string becomes a palindrome.Medium4StringString matching+2No attempts yet2s512 MBJudgeable
Round TripA runner travels out and back along N courses given by their lengths; given total distance K, print which course the runner is on or about to enter.Medium4ArrayPrefix sum+2No attempts yet1s256 MBJudgeable
Moving 3A path from (0,0) to (N,M) using only down and right steps costs A[r] per down move and B[c] per right move; find the cheapest path.Medium4GreedyMath+1No attempts yet2s512 MBJudgeable
Maximum Subarray 2147483647Given a sequence of n integers, find the maximum possible sum of a contiguous subarray, choosing at least one element.Medium4Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
On Becoming the Strongest Competitive Programmer After 200 Years of SeclusionGiven contests in fixed order, each with a prize cap and a prize amount, decide whether Yeondu can skip at most one contest while never exceeding the running cap.Medium4GreedyImplementation+2No attempts yet1s1024 MBJudgeable
DunesEach gust adds +x to l and then alternates signs up to r; answer m queries for the final height at given positions.Medium4ArrayPrefix sum+2No attempts yet2s512 MBJudgeable
Dividing a Rectangle into ThreeSplit a digit grid into three non-overlapping rectangles covering all cells and maximize the product of their digit sums.Medium5Prefix sumBrute force+2No attempts yet2s128 MBJudgeable
Counting Crossing EdgesGiven M cross edges between two labeled vertex sets of size N, count how many unordered pairs of edges cross each other.Medium5SortingDivide and conquer+2No attempts yet2s128 MBJudgeable
Baking PizzaSimulate inserting pizza doughs into a tapering tube oven, each settling as deep as possible above prior doughs, and report the final dough's position or 0 if any fails to fit.Medium5Binary searchPrefix sum+2No attempts yet2s256 MBJudgeable
Balanced LineupGiven fans sorted by x-coordinate with a gender bit each, find the longest contiguous segment that has an equal number of men and women.Medium5Prefix sumHash map+2No attempts yet2s256 MBJudgeable
Sum of Subarrays from Two ArraysCount pairs of contiguous subarrays, one from each of two arrays, whose sums add up to a given target T.Medium5ArrayHash map+1No attempts yet2s64 MBJudgeable
Number BeadsSplit an ordered array into M contiguous groups to minimize the largest group sum, then output that value and the group sizes.Medium5Binary searchGreedy+1No attempts yet1s128 MBJudgeable
Minimum Cost for Restaurant OrdersGiven first-dish and later-dish prices for N dishes, compute for every k the minimum total cost of ordering exactly k dishes.Medium5GreedySorting+1No attempts yet2s256 MBJudgeable
Viewership Popularity SurveyGiven N viewing intervals (possibly wrapping past midnight) over a day, use a difference array over seconds to answer Q sum-of-popularity queries divided by interval length.Medium5Prefix sumArray+1No attempts yet1s128 MBJudgeable
FootnotesGiven text lines and footnotes attached to specific lines, compute the minimum number of pages so that each page holds consecutive text lines plus their footnotes within a line limit K.Medium5Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Safe LockGiven N positions on a circular ring of size 10,000,000, find the minimum total distance to move all points to a common position, minimizing sum of circular distances.Medium5SortingPrefix sum+2No attempts yet1s128 MBJudgeable
Reversible LaneSimulate traffic queues on a reversible bridge lane over all possible switch times to find the switch time minimizing total waiting cars.Medium5SimulationPrefix sum+1No attempts yet1s128 MBJudgeable
Non-negative Partial SumsGiven a cyclic array, count how many rotations make every prefix sum of the rotated sequence non-negative.Medium5Prefix sumArrayNo attempts yet3s128 MBJudgeable
Ferry Loading VGiven distinct vehicle weights, split them between two lanes so the totals differ as little as possible. Output the minimum difference.Medium5Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
Curvy Little BottlesGiven a polynomial and x bounds that define a bottle of revolution, find the x positions where the cumulative volume hits each increment, up to 8 marks.Medium5MathBinary search+2No attempts yet1s128 MBJudgeable
Factstone BenchmarkFor each year, compute the word size by doubling every decade from 4 bits in 1960, then find the largest n with n! <= 2^b - 1.Medium5MathBinary search+2No attempts yet1s128 MBJudgeable
Fuel StopsFind all valid starting cities in a circular tour where fuel supply matches demand, and the tank never goes negative.Medium5GreedyPrefix sum+1No attempts yet2s128 MBJudgeable
PERMSFor each query (n, k), count permutations of 1..n having exactly k inversions, with n up to 18 and k up to 200.Medium5Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
GerrymanderingSplit n precincts, each with P and Q vote counts, into two nonempty districts; find how many districts P can win (0, 1, or 2).Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
BallsThere are n balls and n holes. Balls fall straight down from (i,h) to holes at (i,0). Placing exactly one obstacle (a segment between two integer columns) that tilts right redirects all balls in its column range to its right (lower) end; tilting left redirects them to its left (lower) end. For each orientation, maximize the total score over all valid placements (both orientations must be used, i.e., one obstacle of the specified tilt is mandatory, even if it reduces the total). Constraints n up to 3e5, c_i up to 1e9 in absolute value, so O(n log n) or O(n) required, answers in 64-bit.Medium5ArrayPrefix sum+2No attempts yet1s128 MBJudgeable
Gene ShuffleTwo permutations of 1..N are given; split [1,N] into the shortest pieces where each piece holds the same set of genes in both. - use plain EnglishMedium5Prefix sumHash mapNo attempts yet1s128 MBJudgeable
Northwest WindCount pairs of islands where one can sail to the other moving only east or south (both coordinates monotone between the two points).Medium5SortingPrefix sum+2No attempts yet1s256 MBJudgeable
ImagineMaintain a 1024x1024 grid that starts as a checkerboard and process stickers plus rectangle queries for counts of each letter.Medium5Prefix sumArray+2No attempts yet1s256 MBJudgeable
JJOOIIFind the largest k such that k J's, then k O's, then k I's appear consecutively in the given string.Medium5StringPrefix sum+1No attempts yet1s128 MBJudgeable
StrollSimulate the letters on a grid as N successive walks from the top-left, and report the endpoint of the N-th walk.Medium5SimulationDynamic programming+1No attempts yet2s128 MBJudgeable
Largest Prime SubstringGiven a digit string, find the largest-valued contiguous substring that is prime and at most 100000.Medium5StringBrute force+2No attempts yet1s128 MBJudgeable
Drunk CodingMaintain a sequence under point updates and answer range-product sign queries (+/-/0) for each test case until EOF.Medium5Segment treePrefix sum+2No attempts yet1s256 MBJudgeable
Klingon Course LevelsPick a score threshold T that splits every division into basic and advanced groups, minimizing the sum over divisions of |basic - advanced|. Output that minimum.Medium5SortingPrefix sum+2No attempts yet1s128 MBJudgeable