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
| Title | Level | Topics | Solved | Time limit | Memory limit | Judge |
|---|---|---|---|---|---|---|
| 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. | Medium4 | Prefix sumBinary search+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Dining CowsGiven a sequence of 1s and 2s, find the minimum number of values to change so the sequence becomes nondecreasing. | Medium4 | Dynamic programmingPrefix sum+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Long Distance RacingGiven a terrain string and per-unit times, find the farthest segment index k whose round-trip time stays within M seconds. | Medium4 | ArrayPrefix sum+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | Dynamic programmingMatrix+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | Sliding windowArray+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | ArrayPrefix sum+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| 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. | Medium4 | Sliding windowPrefix sum+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | Prefix sumMatrix+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Handong the Salesman!Given a tree, start at node 1 and visit m listed nodes in order, summing the tree distances between consecutive stops. | Medium4 | GraphTree+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | Prefix sumMatrix+1 | No attempts yet | 3s | 128 MB | Judgeable |
| CalendarsConvert each given date to its day of year with one calendar, then locate the matching month and day in the other calendar. | Medium4 | Prefix sumBinary search | No attempts yet | 1s | 512 MB | Judgeable |
| Gathering MushroomsChoose the earliest day t of at least 1 that maximizes the total weight of mushrooms still edible, where each weight grows daily. | Medium4 | Prefix sumArray | No attempts yet | 1s | 128 MB | Judgeable |
| Flipping the Vegetable GardenApply up to one million rectangle flips to an n by n binary garden and print the final layout. | Medium4 | Prefix sumMatrix | No attempts yet | 1s | 128 MB | Judgeable |
| Dome StadiumChoose the village coordinate that minimizes the total fan-weighted travel distance. | Medium4 | Prefix sum | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | GeometryBrute force+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | Prefix sumSimulation+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Longest Balanced Sub-SequenceFind the length of the longest contiguous block with equal counts of positive and negative numbers. | Medium4 | Prefix sumHash map | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium4 | Dynamic programmingArray+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Counting SubsthreengsCount the contiguous digit-only substrings of S whose value is a multiple of 3. | Medium4 | Prefix sumMath | No attempts yet | 3s | 256 MB | Judgeable |
| 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. | Medium4 | Segment treePrefix sum | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | Prefix sumGreedy | No attempts yet | 1s | 256 MB | Judgeable |
| ACMSplit the task list into three nonempty consecutive blocks and assign one member to each block to minimize the summed difficulty estimates. | Medium4 | Prefix sumBrute force | No attempts yet | 1s | 64 MB | Judgeable |
| Remainder Subarray CountCount contiguous intervals whose sum is divisible by M using prefix remainder frequencies. | Medium4 | Prefix sumHash map | No attempts yet | 1s | 256 MB | Judgeable |
| Kindergarten ExcursionCount the minimum adjacent swaps needed to reorder a string of 0s, 1s, and 2s into sorted order. | Medium4 | SortingPrefix sum | No attempts yet | 1s | 256 MB | Judgeable |
| Icelandic MotorclubsFind the smallest-numbered station from which a rider who takes all gas at every stop can complete one clockwise lap. | Medium4 | GreedyPrefix sum | No attempts yet | 3s | 256 MB | Judgeable |
| Farey Sequence LengthCompute 1 plus the sum of Euler totient values up to N for each of up to 10000 data sets. | Medium4 | Number theoryPrefix sum+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Word Clouds RevisitedPlace N ordered boxes of given widths and heights into width-limited rows to minimize the sum of row heights. | Medium4 | Dynamic programmingPrefix sum | No attempts yet | 2s | 256 MB | Judgeable |
| Two-Dimensional Range SumCompute the sum of each queried rectangle in an N by N table using a 2D prefix sum. | Medium4 | Prefix sumMatrix | No attempts yet | 1s | 256 MB | Judgeable |
| Subsequences Summing to SevensFind the length of the longest contiguous group of cows whose IDs sum to a multiple of 7. | Medium4 | Prefix sumHash map | No attempts yet | 2s | 512 MB | Judgeable |
| 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. | Medium4 | Prefix sumCombinatorics | No attempts yet | 2s | 256 MB | Judgeable |
| Sums of Sums (Small)You sort every contiguous subarray sum of an array and answer range sums over the sorted list. | Medium4 | SortingPrefix sum | No attempts yet | 5s | 512 MB | Judgeable |
| Sum of ImperfectionsAdd up, for every integer from A to B, the absolute gap between the number and the sum of its proper divisors. | Medium4 | Number theoryPrefix sum | No attempts yet | 3s | 128 MB | Judgeable |
| 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. | Medium4 | Brute forcePrefix sum | No attempts yet | 5s | 512 MB | Judgeable |
| Household LedgerProcess point additions and range-sum queries on a ledger of N days. | Medium4 | Prefix sum | No attempts yet | 1s | 512 MB | Judgeable |
| 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. | Medium4 | Prefix sumArray+2 | No attempts yet | 2s | 512 MB | Judgeable |
| 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. | Medium4 | ArrayPrefix sum+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Counting Equilateral TrianglesGiven arc lengths around a circle and points at the boundaries, count equilateral triangles whose three vertices are among the points. | Medium4 | Prefix sumMath+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Sum of Divisor SumsGiven L and R, compute the sum of divisor sums f(n) for every n from L to R. | Medium4 | MathNumber theory+1 | No attempts yet | 1s | 64 MB | Judgeable |
| Counting HaybalesGiven N distinct haybale positions and Q interval queries, count how many positions fall inside each inclusive range [A, B]. | Medium4 | SortingBinary search+2 | No attempts yet | 2s | 512 MB | Judgeable |
| 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. | Medium4 | TreeDFS+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Safe Squares (Small)Count all axis-aligned D by D subgrids of an R by C grid that contain no monster cell. | Medium4 | Dynamic programmingMatrix+2 | No attempts yet | 5s | 512 MB | Judgeable |
| 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. | Medium4 | Prefix sumBrute force+1 | No attempts yet | 2s | 512 MB | Judgeable |
| 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. | Medium4 | ArrayPrefix sum+2 | No attempts yet | 2s | 256 MB | Judgeable |
| TelescopeCount the horizontal shifts of an m by l weight grid over an m by n path where the weighted sum exceeds W. | Medium4 | Sliding windowPrefix sum+2 | No attempts yet | 1s | 512 MB | Judgeable |
| 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. | Medium4 | MathGeometry+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Sum of all pairwise productsGiven n integers, compute the sum of x_a * x_b over all pairs with a < b. | Medium4 | MathPrefix sum+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Halfway PointGiven n, find the value printed when the pair-comparison loop reaches its halfway point (the last item index printed there). | Medium4 | Binary searchMath+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Programming ExamFor each query, decide whether two given substrings of S are anagrams, printing DA or NE. | Medium4 | Prefix sumHash map+1 | No attempts yet | 3s | 128 MB | Judgeable |
| 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. | Medium4 | MathImplementation+2 | No attempts yet | 1s | 64 MB | Judgeable |
| 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. | Medium4 | ArrayMath+2 | No attempts yet | 5s | 512 MB | Judgeable |
| JujisuGiven an N by M grid of populations, answer K queries for the sum of people inside each requested rectangle. | Medium4 | Prefix sumArray+2 | No attempts yet | 2s | 512 MB | Judgeable |
| 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. | Medium4 | Dynamic programmingMath+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Ü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. | Medium4 | Dynamic programmingArray+2 | No attempts yet | 2s | 512 MB | Judgeable |
| 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. | Medium4 | Prefix sumArray+1 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | Prefix sumMatrix | No attempts yet | 1s | 512 MB | Judgeable |
| Plate ParityCount integers in [A, B] whose rightmost nonzero digit is odd versus even, where A and B go up to 10^16. | Medium4 | MathImplementation+2 | No attempts yet | 1s | 512 MB | Judgeable |
| Generic QueriesGiven an array and range queries, compute each interval XOR and output the XOR of all answers mixed with the given k values. | Medium4 | Prefix sumBit manipulation+2 | No attempts yet | 2.5s | 512 MB | Judgeable |
| 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. | Medium4 | ArraySimulation+2 | No attempts yet | 2s | 512 MB | Judgeable |
| 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. | Medium4 | ArrayPrefix sum+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Goldbach PartitionFor each even N up to one million, count the unordered pairs of primes that sum to N. | Medium4 | Number theoryMath+2 | No attempts yet | 0.5s | 512 MB | Judgeable |
| Goldbach Partition 2For each even N up to 1,000,000, count unordered pairs of primes that sum to N. | Medium4 | Number theoryPrefix sum+2 | No attempts yet | 0.5s | 512 MB | Judgeable |
| Array PlayGiven an N by N grid and M rectangle-add operations, output the final sum of each row and each column. | Medium4 | Prefix sumArray+2 | No attempts yet | 2s | 512 MB | Judgeable |
| 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. | Medium4 | MathNumber theory+2 | No attempts yet | 0.5s | 512 MB | Judgeable |
| 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. | Medium4 | Prefix sumArray+2 | No attempts yet | 3s | 512 MB | Judgeable |
| 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. | Medium4 | Sliding windowPrefix sum+2 | No attempts yet | 1s | 512 MB | Judgeable |
| 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. | Medium4 | ArrayPrefix sum+2 | No attempts yet | 1s | 512 MB | Judgeable |
| 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. | Medium4 | ImplementationBrute force+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| ABBGiven a string of colors, find how many characters must be appended at the end so the resulting string becomes a palindrome. | Medium4 | StringString matching+2 | No attempts yet | 2s | 512 MB | Judgeable |
| 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. | Medium4 | ArrayPrefix sum+2 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium4 | GreedyMath+1 | No attempts yet | 2s | 512 MB | Judgeable |
| Maximum Subarray 2147483647Given a sequence of n integers, find the maximum possible sum of a contiguous subarray, choosing at least one element. | Medium4 | Dynamic programmingArray+2 | No attempts yet | 2s | 512 MB | Judgeable |
| 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. | Medium4 | GreedyImplementation+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| DunesEach gust adds +x to l and then alternates signs up to r; answer m queries for the final height at given positions. | Medium4 | ArrayPrefix sum+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Dividing a Rectangle into ThreeSplit a digit grid into three non-overlapping rectangles covering all cells and maximize the product of their digit sums. | Medium5 | Prefix sumBrute force+2 | No attempts yet | 2s | 128 MB | Judgeable |
| Counting Crossing EdgesGiven M cross edges between two labeled vertex sets of size N, count how many unordered pairs of edges cross each other. | Medium5 | SortingDivide and conquer+2 | No attempts yet | 2s | 128 MB | Judgeable |
| 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. | Medium5 | Binary searchPrefix sum+2 | No attempts yet | 2s | 256 MB | Judgeable |
| 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. | Medium5 | Prefix sumHash map+2 | No attempts yet | 2s | 256 MB | Judgeable |
| 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. | Medium5 | ArrayHash map+1 | No attempts yet | 2s | 64 MB | Judgeable |
| Number BeadsSplit an ordered array into M contiguous groups to minimize the largest group sum, then output that value and the group sizes. | Medium5 | Binary searchGreedy+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium5 | GreedySorting+1 | No attempts yet | 2s | 256 MB | Judgeable |
| 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. | Medium5 | Prefix sumArray+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium5 | Dynamic programmingGreedy+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium5 | SortingPrefix sum+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Reversible LaneSimulate traffic queues on a reversible bridge lane over all possible switch times to find the switch time minimizing total waiting cars. | Medium5 | SimulationPrefix sum+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Non-negative Partial SumsGiven a cyclic array, count how many rotations make every prefix sum of the rotated sequence non-negative. | Medium5 | Prefix sumArray | No attempts yet | 3s | 128 MB | Judgeable |
| Ferry Loading VGiven distinct vehicle weights, split them between two lanes so the totals differ as little as possible. Output the minimum difference. | Medium5 | Dynamic programmingPrefix sum+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium5 | MathBinary search+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium5 | MathBinary search+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Fuel StopsFind all valid starting cities in a circular tour where fuel supply matches demand, and the tank never goes negative. | Medium5 | GreedyPrefix sum+1 | No attempts yet | 2s | 128 MB | Judgeable |
| PERMSFor each query (n, k), count permutations of 1..n having exactly k inversions, with n up to 18 and k up to 200. | Medium5 | Dynamic programmingCombinatorics+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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). | Medium5 | Dynamic programmingArray+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium5 | ArrayPrefix sum+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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 English | Medium5 | Prefix sumHash map | No attempts yet | 1s | 128 MB | Judgeable |
| Northwest WindCount pairs of islands where one can sail to the other moving only east or south (both coordinates monotone between the two points). | Medium5 | SortingPrefix sum+2 | No attempts yet | 1s | 256 MB | Judgeable |
| ImagineMaintain a 1024x1024 grid that starts as a checkerboard and process stickers plus rectangle queries for counts of each letter. | Medium5 | Prefix sumArray+2 | No attempts yet | 1s | 256 MB | Judgeable |
| JJOOIIFind the largest k such that k J's, then k O's, then k I's appear consecutively in the given string. | Medium5 | StringPrefix sum+1 | No attempts yet | 1s | 128 MB | Judgeable |
| StrollSimulate the letters on a grid as N successive walks from the top-left, and report the endpoint of the N-th walk. | Medium5 | SimulationDynamic programming+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Largest Prime SubstringGiven a digit string, find the largest-valued contiguous substring that is prime and at most 100000. | Medium5 | StringBrute force+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Drunk CodingMaintain a sequence under point updates and answer range-product sign queries (+/-/0) for each test case until EOF. | Medium5 | Segment treePrefix sum+2 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium5 | SortingPrefix sum+2 | No attempts yet | 1s | 128 MB | Judgeable |