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,179 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Value of a TriangleGiven up to 400 rows of a triangular grid of unit triangles, find the sub-triangle with the largest sum of unit values.Medium7Dynamic programmingPrefix sum+2No attempts yet1s256 MBJudgeable
I Hate Number TheoryFor each query interval [L, U] below one million, find the maximum of a score built from prime-factor counts over all subintervals [a, b].Medium7Number theoryPrefix sum+1No attempts yet1s128 MBJudgeable
Moogle MapsChoose c of h house locations to store so that the average linear interpolation error over all houses is minimized, with endpoints always stored.Medium7Dynamic programmingMath+2No attempts yet1s128 MBJudgeable
Water?Given an h by w grid of letters and a set of special letters, find the subrectangle with both sides at least m whose fraction of special pixels is maximum, breaking ties by larger area.Medium7Prefix sumBrute force+2No attempts yet1s128 MBJudgeable
SpiralOn an N by N grid with blocked fountain cells, find the longest path made of four straight segments turning only right, never revisiting a field.Medium7Brute forceImplementation+2No attempts yet5s128 MBJudgeable
Top 2000Partition a fixed sequence of singles into contiguous blocks, letting each block run under or over M minutes with per-minute penalties, and minimize the total penalty.Medium7Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
MerchantChoose a subset of markets to visit in nondecreasing opening-day order along a river, starting and ending at home, to maximize profits minus asymmetric upstream/downstream fuel costs.Medium7Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
SailsPlace K sails on each mast (height H) to minimize the total count of same-height sails behind each sail.Medium7GreedySorting+1No attempts yet1s128 MBJudgeable
Post OfficePlace P post offices in some of V villages on a line so that the sum of each village's distance to its nearest post office is minimized.Medium7Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
NailsGiven up to 500000 upward triangles on a triangular grid of N nails per side, count the nails covered by at least one triangle.Medium7ArrayPrefix sum+2No attempts yet1s128 MBJudgeable
Optimal Space WayFor each test case, fit a weighted straight line through the plane minimizing the mean squared perpendicular distance from given points, and answer queries that give one point extra weight.Medium7GeometryMath+2No attempts yet5s128 MBJudgeable
RadioactivityFor each pair of radiation radii, count houses not covered by either plant after houses in both zones donate a spare unit.Medium7GeometrySorting+2No attempts yet1s128 MBJudgeable
Your WaysCount monotone lattice paths from (0,0) to (W,H) modulo 2552 for K days, where each day blocks up to 100 unit street/avenue segments with no two blocked segments on a common monotone path.Medium7Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Arranging HeapsGiven N heaps at increasing positions with weights, merge them into exactly K heaps where each heap moves only downriver, minimizing total weight times distance moved.Medium7Dynamic programmingDivide and conquer+2No attempts yet2s128 MBJudgeable
Jupiter Attacks!Maintain an array under point updates and queries of a polynomial hash over a subarray modulo a prime, printing each hash result.Medium7Segment treePrefix sum+2No attempts yet1s128 MBJudgeable
Shrinking Inscribed PolygonGiven arc lengths around an inscribed polygon, find the minimum number of vertices to delete so the remaining vertices form a regular polygon, or report -1.Medium7Number theoryMath+2No attempts yet1s128 MBJudgeable
Land Division TaxSplit a ring of N lots one at a time; each split costs F times the larger resulting piece. Find the minimum total tax.Medium7Dynamic programmingIntervals+2No attempts yet1s128 MBJudgeable
Rice HubGiven sorted field positions on a line and a budget B, choose an integer hub position maximizing how many fields can be reached within total transport cost B.Medium7Two pointersPrefix sum+2No attempts yet1s256 MBJudgeable
NecklaceGiven a string and a pattern, delete the fewest characters so the pattern no longer appears as a contiguous substring.Medium7Dynamic programmingString matching+2No attempts yet1s128 MBJudgeable
Poker HandsGiven card counts per rank, find the fewest contiguous-rank straights whose unit cards sum to exactly those counts.Medium7GreedyArray+2No attempts yet1s128 MBJudgeable
Running Away From the BarnFor every node in a weighted tree rooted at node 1, count the descendants within total distance L along the downward path, including the node itself.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Concurrently Balanced StringsGiven K parenthesis strings of length N, count index ranges whose substring is balanced in all K strings at once.Medium7Hash mapPrefix sum+2No attempts yet1s128 MBJudgeable
Haybale RestackingGiven N piles in a circle with current and target amounts of hay, move bales at cost equal to circular distance to reach the target with minimum total work.Medium7GreedyPrefix sum+2No attempts yet1s128 MBJudgeable
Wrong DirectionsGiven a command string of F, L, and R, count the distinct final positions reachable by changing exactly one character to a different one.Medium7SimulationHash map+2No attempts yet1s128 MBJudgeable
OverplantingGiven up to 1000 axis-aligned rectangles, compute the total area of their union.Medium7GeometrySorting+1No attempts yet1s128 MBJudgeable
Cow PhotographsGiven a permutation of 1 to N, find the fewest adjacent swaps to reach a rotation of 1..N starting at some cow s, minimized over all s.Medium7ArraySorting+2No attempts yet1s128 MBJudgeable
Generic Cow ProtestsCount the ways to split a sequence into contiguous groups so that every group sum is nonnegative, modulo 1,000,000,009.Medium7Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Brownie SlicingPartition a grid into A horizontal strips, then cut each strip into B vertical pieces independently, maximizing the minimum piece sum.Medium7Binary searchGreedy+2No attempts yet1s128 MBJudgeable
Slowing downFor each cow in order, count how many pastures already occupied by earlier cows lie on the tree path from node 1 to that cow's pasture.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
The Baric BovineChoose the smallest subset of N pressure readings so the total interpolation-style error stays within E, and report that size plus the least error for it.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
The LeprechaunGiven an N x N matrix on a torus, find the contiguous circular run along any row, column, or either diagonal with the largest sum.Medium7ArrayDynamic programming+2No attempts yet1s128 MBJudgeable
RestaurantSplit a sequence of N foods into consecutive groups, where a group costs the square of its number of distinct foods, and minimize the total cost.Medium7Dynamic programmingDivide and conquer+2No attempts yet1s128 MBJudgeable
The Bovine Accordion and Banjo OrchestraChoose increasing pairs between two length-N sequences to maximize the sum of A_i*B_j minus the squared sums of each maximal block of unpaired elements on both sides.Medium7Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Building a New BarnPlace a barn at integer coordinates not used by any cow to minimize the total Manhattan distance to all cows, and count how many such optimal spots exist.Medium7MathSorting+2No attempts yet1s128 MBJudgeable
Gold Balanced LineupGiven N cows each with a K-bit feature ID, find the longest contiguous range where every one of the K features appears the same number of times.Medium7Hash mapPrefix sum+2No attempts yet1s128 MBJudgeable
Calculating Taxi FareGiven a sequence of streets with lengths and per-kilometer times, compute a passenger's fare between two streets using tiered per-kilometer pricing plus night and traffic surcharges.Medium7SimulationImplementation+2No attempts yet1s128 MBJudgeable
AtlantisGiven up to 100 axis-aligned rectangles, compute the area of their union and print it with two decimals.Medium7GeometrySegment tree+2No attempts yet1s128 MBJudgeable
To the MaxFind the contiguous rectangular subregion of an N by N integer matrix with the largest possible sum and print that sum.Medium7Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Huffman's GreedWe build the optimal binary search tree for weighted key and gap frequencies, minimizing weighted comparison counts.Medium7Dynamic programmingTree+2No attempts yet1s128 MBJudgeable
Measuring Problem DifficultyGiven three permutations of the numbers 1 to N, count pairs whose relative order is identical in all three orderings.Medium7SortingDivide and conquer+2No attempts yet3s128 MBJudgeable
ParadeMaintain a list of N perimeter-rotation commands on a 4x4 grid under Q cumulative point updates, printing the resulting grid after each update.Medium7SimulationImplementation+2No attempts yet1s128 MBJudgeable
Bowling for Numbers++Choose at most k windows of length w, possibly overlapping beyond the row ends, so the sum of the covered pins is as large as possible.Medium7Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Two SawmillsPlace two extra sawmills along a road so that every tree's downhill haul to the first mill at or below it is minimized.Medium7Dynamic programmingDivide and conquer+2No attempts yet1s128 MBJudgeable
GradesInsert Juku into a presentation order to maximize the grades he receives, where grades either reflect project value or reciprocate a prior grade.Medium7GreedyPrefix sum+1No attempts yet1s1024 MBJudgeable
DiscoGiven N disjoint lit intervals on a line of L lamps and M switches that each flip a range, decide if some subset of switches turns every lamp off.Medium7IntervalsGreedy+2No attempts yet1s1024 MBJudgeable
Energy CollectionGiven non-overlapping axis-aligned squares, find an axis-aligned collector square that overlaps strictly and is no larger than the cells it collects, maximizing the count.Medium7GeometryBinary search+2No attempts yet1s128 MBJudgeable
Maximum Sum of K Non-Overlapping SubmatricesPick exactly K pairwise non-overlapping rectangular submatrices from an N x M matrix to maximize the sum of their elements.Medium7Dynamic programmingPrefix sum+2No attempts yet2s32 MBJudgeable
NeighboursGiven n peaks on a w by h grid, count non-peak grid points by how many of their four axis directions contain a peak.Medium7SortingHash map+2No attempts yet2s64 MBJudgeable
B-MatrixFind two non-overlapping all-zero rectangles in a binary grid maximizing the total number of cells they cover.Medium7Dynamic programmingMatrix+2No attempts yet1s128 MBJudgeable
Lightning Energy ReportGiven a tree and many path updates that each add a value to every vertex on a path, report the final total at every vertex.Medium7TreePrefix sum+2No attempts yet1s256 MBJudgeable
One is Good, but Two is BetterGiven an N by M grid of 0, 1, and 2, cover every 2 with two rectangles that avoid 1, minimizing the total area covered.Medium7Brute forcePrefix sum+2No attempts yet1s128 MBJudgeable
Beach cutGiven a polyline shoreline, pick two vertices at distance at most L and connect them below the shore to maximize the enclosed beach area.Medium7GeometryTwo pointers+1No attempts yet1s128 MBJudgeable
Better and Faster!Compute a CRC-style bit checksum of a string after each of up to 1e5 character substitutions, fast enough that recomputing from scratch times out.Medium7Bit manipulationMath+1No attempts yet2s512 MBJudgeable
ArtifactGiven n row intervals, choose k consecutive columns and pay the cost to extend each row's interval to cover them, minimizing total added tiles.Medium7Prefix sumSliding window+1No attempts yet1s128 MBJudgeable
I'll Do It TomorrowGiven n jobs with lengths and deadlines, find the longest idle prefix of days, counting from day 1, before some work must begin.Medium7GreedySorting+2No attempts yet2s256 MBJudgeable
ParcelGiven an n by n grid of 0 (arable) and 1 (waste), find the largest all-zero rectangle and print its area. n can be up to 2000.Medium7StackDynamic programming+2No attempts yet3s512 MBJudgeable
GoldmineGiven n points and an axis-aligned rectangle of fixed width s and height w, find the maximum number of points the rectangle can cover, borders included.Medium7SortingTwo pointers+2No attempts yet3s512 MBJudgeable
Where to Build a Brewery?On a ring of cities with given edge lengths and demands, pick the city minimizing total demand-weighted shortest-path distance around the ring.Medium7Prefix sumTwo pointers+2No attempts yet3s512 MBJudgeable
MapPartition n populations into m groups to minimize the sum over each group of |value - group median|, where the median can be any value meeting the half-half condition.Medium7Dynamic programmingSorting+2No attempts yet3s128 MBJudgeable
BoxesBoxes stand in a circle with at most n balls total; move balls to neighbors so each box holds at most one, minimizing the number of moves.Medium7GreedyPrefix sum+2No attempts yet1s128 MBJudgeable
Aesthetic TextSplit a sequence of words into lines of length at most m, minimizing the total absolute difference between consecutive line lengths.Medium7Dynamic programmingPrefix sumNo attempts yet1s128 MBJudgeable
PalindromesGiven n distinct palindromes, count ordered pairs whose concatenation is also a palindrome, with total length up to 2,000,000.Medium7StringHash map+2No attempts yet5s256 MBJudgeable
WeightsGiven container capacities and weights whose masses form a divisibility chain, maximize how many weights fit.Medium7GreedySorting+2No attempts yet3s128 MBJudgeable
BBBFind the minimum cost to fix a + and - statement so the balance starts at p, never goes negative, and ends at q, using character flips and rotations.Medium7GreedyPrefix sum+1No attempts yet1s128 MBJudgeable
Multiset Permutation RankGiven one permutation of a multiset, compute its lexicographic rank among all distinct permutations, modulo m.Medium7CombinatoricsMath+2No attempts yet2s128 MBJudgeable
Ticket InspectorChoose k of the n-1 travel segments so that the total number of passengers present on at least one chosen segment is maximized.Medium7Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
LollipopFor each query k, find the lexicographically smallest contiguous segment of a T/W string whose weight (T=2, W=1) equals k, or print NIE if none exists.Medium7Prefix sumTwo pointers+2No attempts yet1s128 MBJudgeable
Letter Frequency DifferencePick any contiguous fragment of a lowercase word to maximize the gap between its most and least frequent letters.Medium7Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
CloakroomFor each query (m, k, s), decide whether some items with a_i <= m and b_i > m+s have values summing to exactly k.Medium7Dynamic programmingSorting+2No attempts yet2s128 MBJudgeable
BanjoPick two separate one-minute intervals to maximize the number of people present for at least one full minute.Medium7ArraySorting+2No attempts yet5s128 MBJudgeable
Alien InvasionFind the maximum total residents the aliens can abduct, given that a warning from an attacked city reaches city k one day later per unit distance.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
SunsetsFor each cell of an n x n grid, output the tallest height among all cells within Manhattan distance k.Medium7Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
Farmer's FieldCount placements of a c-by-d or d-by-c rectangle fully inside a field whose every row is one contiguous segment.Medium7Sliding windowStack+2No attempts yet1s128 MBJudgeable
Land SwindleFor each meadow square choose at most one rectangle ending there, maximize the total perimeter, where each rectangle must contain only meadow squares.Medium7Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
TowerPartition the sequence of brick widths into consecutive blocks so that block sums do not increase from bottom to top, maximizing the number of blocks.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Sunset Views 2For each point on an n by n grid, take the maximum building height within Manhattan distance k, then sum all these maxima.Medium7ArrayPrefix sum+2No attempts yet1s128 MBJudgeable
Guessing GameFind the largest prefix of interval parity answers that stays consistent with some 0/1 sequence of length one billion.Medium7Union-findPrefix sum+1No attempts yet1s128 MBJudgeable
Bridge PillarsPick a modulus m above 1 that keeps the largest group of pillar heights sharing one remainder, with ties broken toward the larger m.Medium7Number theoryPrefix sumNo attempts yet1s128 MBJudgeable
Weights and ScalesPlace one gray weight on the empty pan, then repeatedly merge each balanced scale in the nested tower, and report the fewest weights that can remain.Medium7Prefix sumHash mapNo attempts yet1s128 MBJudgeable
The StructureA tower splits the top load equally down its columns, and after each strength update you report how many queued visitors from the front it can hold.Medium7Segment treePrefix sum+1No attempts yet1s128 MBJudgeable
RoundupCount the axis-aligned squares of side at least 2 whose border cells are all 1 in an n by n binary grid.Medium7Prefix sumMatrix+1No attempts yet1s128 MBJudgeable
SpringsPick one integer target length for the k shortest springs to minimize the total triangular stretching cost.Medium7Prefix sumBinary search+1No attempts yet1s128 MBJudgeable
ABCFind the length of the longest nondecreasing common subsequence of two strings over a, b, and c.Medium7Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Almost LCSGiven two binary strings up to 100000 characters, find the longest 0^a1^b or 1^a0^b string that is a subsequence of both.Medium7Prefix sumTwo pointers+1No attempts yet1s128 MBJudgeable
GC-RatioFind the contiguous segment of length at least L with the largest share of ones, breaking ties by shorter length then earlier start.Medium7Binary searchPrefix sumNo attempts yet2s128 MBJudgeable
DeliveryJim starts at 0, carries at most one parcel at a time between points on a road, and returns to 0 after delivering all parcels over the shortest total distance.Medium7GreedySorting+1No attempts yet1s128 MBJudgeable
TokensFor each token with given length and lookahead, compute how far back its text affects earlier token boundaries.Medium7Two pointersPrefix sumNo attempts yet1s128 MBJudgeable
Flight Boarding OptimizationYou split the rows into k contiguous zones and order their boarding phases, keeping queue order inside each zone, to minimize total boarding difficulty.Medium7Dynamic programmingIntervals+1No attempts yet2s256 MBJudgeable
International EventFind the minimum distance for a robot starting and ending at A to move every flag along a line from its old pole to a pole requesting that nation.Medium7GreedyPrefix sum+1No attempts yet5s128 MBJudgeable
Join two kingdomsTwo trees with up to 40000 nodes each are joined by one uniformly random cross edge, and you must output the expected diameter of the combined tree.Medium7TreeSorting+2No attempts yet1s128 MBJudgeable
No ChangePay the ordered purchases with distinct coins, each covering one consecutive group within its value, to maximize unused value, or print -1.Medium7Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Hack ProtectionCount the subarrays of the given array whose bitwise XOR equals their bitwise AND.Medium7Bit manipulationPrefix sum+2No attempts yet1s128 MBJudgeable
Shortest Subsequence With Sum at Least XFind the length of the shortest contiguous subarray whose sum is at least X, or report -1 when none exists.Medium7Prefix sumQueueNo attempts yet3s256 MBJudgeable
Super AntsAn ant on a grid cell collects its value and spawns clones along eight rays within the remaining time, and you compute the total score modulo 1e9+7.Medium7Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
Fair PhotographyAfter sorting cows by position, find the widest contiguous group containing at least K breeds with each present breed appearing equally often.Medium7Prefix sumHash mapNo attempts yet1s128 MBJudgeable
Split the sequenceSplit the sequence into k+1 contiguous parts so the total product score from the cuts is maximal, and print the score with one optimal cut list.Medium7Dynamic programmingDivide and conquer+2No attempts yet2s128 MBJudgeable
Early Exam EvacuationEach of M writers seated in an N-row auditorium exits front or back to minimize passing plus crowding cost.Medium7Dynamic programmingSorting+1No attempts yet2s256 MBJudgeable
Around the worldFor each plane range, find the fewest refueling landings to circle all airports from the best start, or report impossible.Medium7GreedyPrefix sum+1No attempts yet5s24 MBJudgeable
CarpetFind the area of the largest subrectangle of a flawed carpet grid that holds at most one flaw.Medium7StackPrefix sum+1No attempts yet4s256 MBJudgeable
Gold MinesPick an axis-aligned rectangle over weighted points to maximize the sum of enclosed weights.Medium7Dynamic programmingPrefix sum+1No attempts yet3s256 MBJudgeable