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,800 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Dividing the LootGiven N item values and P other pirates, choose a set of items for yourself so no other pirate gets more items than you, maximizing your total value.Medium6GreedySorting+2No attempts yet1s128 MBJudgeable
King Jaguar's PyramidPlace an a by b pyramid and an interior c by d chamber on a grid to maximize the sum of base squares minus chamber squares.Medium6Prefix sumBrute force+2No attempts yet1s128 MBJudgeable
Drawing with XOREach XOR call flips a rectangle anchored at the bottom right, so the number of calls equals the count of pixels that differ from the pixel below and the pixel to the right, plus the bottom-right pixel.Medium6ArrayMatrix+2No attempts yet1s512 MBJudgeable
Light Bulb DecorationGiven a binary string, flip at most one contiguous range so that some contiguous alternating substring becomes as long as possible, and report that length.Medium6ArrayPrefix sum+2No attempts yet1s128 MBJudgeable
Card Game is FunAnna may delete arbitrary cards from her sequence and Bruno may trim cards from the top and bottom of his; find the longest common subarray obtainable.Medium6Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
First GradeCount the ways to place + or - between the first N-1 digits and = before the last digit so that left-to-right evaluation never leaves the range 0 to 20 and the total equals the last digit.Medium6Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
Splitting the SnackChoose which of the N-1 cut points to cut so that both people get exactly N/2 pieces, minimizing the total force of the chosen cuts.Medium6Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Hop-Hop River CrossingStarting from the near bank, hop across stones in n rows using normal jumps or at most m row-skipping jumps, minimizing total jump danger.Medium6Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
BacteriaSimulate K bacteria moving on a grid, each turning by a digit read from its own matrix, and report when all share the trap cell.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
Warp Speed IIFor each hop sequence, pick a warp-drive state per hop minimizing switch plus hop energy, and return the lexicographically smallest optimal state sequence.Medium6Dynamic programmingGreedy+2No attempts yet5s128 MBJudgeable
Grandpa's Rubik CubeGiven a Rubik's cube configuration and a list of face rotations, decide whether applying them all yields a solved cube with each face a single color.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
CrossNumberFill a digit-grid puzzle where each across and down run must match a given digit sum, always leaving a word with one blank cell to solve.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
Farm PaintingGiven up to 50,000 non-intersecting axis-aligned rectangles, count how many are not contained inside any other rectangle.Medium6SortingArray+2No attempts yet1s128 MBJudgeable
Cow LineupGiven a sequence of N breed IDs, remove at most K distinct breed IDs so that the longest run of equal IDs in the remaining sequence is maximized.Medium6Sliding windowTwo pointers+2No attempts yet1s128 MBJudgeable
Painting the FenceBessie walks along a number line and each segment she covers gains a coat of paint; find the total length covered by at least K coats.Medium6IntervalsSorting+2No attempts yet1s128 MBJudgeable
Above the MedianGiven N cow heights, count contiguous ranges whose defined median (the ceil(K/2)-th smallest) is at least a threshold X.Medium6Prefix sumBinary search+2No attempts yet1s128 MBJudgeable
Treasure ChestTwo players alternately take a coin from either end of a row of N coins; find the maximum total the first player can guarantee with optimal play.Medium6Dynamic programmingGame theory+2No attempts yet1s128 MBJudgeable
Trick or Treat on the FarmEach stall has one outgoing next pointer. For every starting stall, count how many distinct stalls the walk visits before it first revisits a stall.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
Super PaintballGiven up to 100000 opponent positions on an N by N grid, count cells from which a shot along its row, column, or either diagonal would pass through every opponent.Medium6Brute forceImplementation+2No attempts yet1s128 MBJudgeable
River CrossingSplit N cows into consecutive groups, each crossing costs M plus the cumulative marginal cost, and add M for every return trip; minimize the total time.Medium6Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Big SquarePlace one extra 'J' on an empty cell of an N by N grid so that the four corners of some 'J' square have the largest possible area.Medium6GeometryBrute force+2No attempts yet1s128 MBJudgeable
Cow Roller CoasterChoose components that tile [0, L] with no gaps or overlaps, maximizing total fun while keeping total cost within budget B.Medium6Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
Standing Long JumpRemove exactly m of n interior stones so the smallest gap between consecutive stepping points from 0 to d is as large as possible.Medium6Binary searchGreedy+2No attempts yet1s128 MBJudgeable
Balanced LineupGiven N cow heights and Q ranges, report the difference between the maximum and minimum height within each query range.Medium6Segment treeArray+2No attempts yet1s128 MBJudgeable
Cheapest PalindromeGiven a string and per-letter insertion and deletion costs, find the minimum cost to turn it into a palindrome by adding or removing characters anywhere.Medium6Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Leaking DikeGiven building heights in a row, water pours over a dike on the left at 1 square meter per minute; find how long until a given building's roof sits 1 meter under water.Medium6ArraySimulation+2No attempts yet1s128 MBJudgeable
TrianglesIn each triangular grid of white and black cells, find the area of the largest all-white triangle, which may point up or down.Medium6Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
HeartsSimulate a simplified Hearts game with fixed strategies and report the heart points won by each of the five players, starting with the dealer.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
Shuffling PatienceSimulate a solitaire game that covers complementary pairs or JQK triples across up to 16 piles, and report the final pile sizes or the overflow card number.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
PostScript Printer DriverSimulate a page renderer that places font C1 and 5x6 asterisk-font C5 strings on a 60x60 grid with left, right, center, and absolute justification, where blanks and dots never overwrite.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
Largest Rectangle in a HistogramGiven a histogram of unit-width bars with varying heights, find the area of the largest rectangle that fits inside it, processing several test cases until a 0 terminates input.Medium6StackArray+2No attempts yet1s256 MBJudgeable
Parallel Computer SimulatorSimulate up to ten concurrent programs on one CPU with FIFO scheduling, quantum preemption, and lock/unlock mutual exclusion, then report prints in execution order.Medium6SimulationQueue+2No attempts yet1s128 MBJudgeable
Returning BooksTrack which books are on the shelves and which sit at the desk, then on each SHELVE command report where each returned book belongs by comparing author and title in ASCII order.Medium6SortingArray+2No attempts yet1s128 MBJudgeable
Computer Purchase ReturnChoose exactly one component of each of T types so the total cost stays within budget B and the total value is maximized.Medium6Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
CowsGiven up to 10000 tree coordinates, find the largest convex polygon using any subset as corners, then output its area divided by 50 rounded down.Medium6GeometrySorting+2No attempts yet1s128 MBJudgeable
Stepping on TilesGiven N distinct increasing numbers, find the maximum sum of a 3-or-more element arithmetic subsequence with any common difference, or 0 if none exists.Medium6Dynamic programmingHash map+2No attempts yet1s256 MBJudgeable
Stacking CubesGiven a stacking pattern as non-increasing rows with non-increasing columns, print its left and right rotations as corner stackings.Medium6ArrayImplementation+2No attempts yet1s128 MBJudgeable
TicketsSplit L pages of non-increasing popularity into D contiguous channel blocks to minimize the popularity-weighted sum of within-block delay positions, breaking ties by the lexicographically smallest block boundaries.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Õhne vanaraamatupoodSimulate bots that repeatedly recompute their book price from the previous day's average, and print every bot's price on the morning of day T.Medium6ImplementationSimulation+2No attempts yet1s1023 MBJudgeable
Flipping a Pack of CardsSimulate a deck of n cards under m prefix-reversal-and-flip operations, then report the final position and face direction of s queried cards.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
DragonPick two disjoint blocks of at most K consecutive heads each in a row of N heads to maximize the total fire power removed.Medium6Dynamic programmingPrefix sum+2No attempts yet1s1024 MBJudgeable
Buffet TableOn a circle of N trays, a walker repeatedly jumps K steps clockwise, collecting each visited tray once until it revisits a tray; find the start that maximizes the total.Medium6Number theoryMath+2No attempts yet1s1024 MBJudgeable
The Cat of BitlandTwo rows of K (friendly) and A (allergic) students; the cat moves right in a row or jumps to any later room in the other row, and we want the most rooms it can visit.Medium6Dynamic programmingArray+2No attempts yet1s1024 MBJudgeable
Swimming CompetitionSplit a sorted list of N swimmer times into consecutive heats of size A to B, minimizing the largest within-heat gap between fastest and slowest.Medium6Binary searchGreedy+2No attempts yet1s1024 MBJudgeable
Square IceGiven an alternating sign matrix, render the corresponding square ice grid using H, O, dashes, bars, and an asterisk border.Medium6ImplementationMatrix+2No attempts yet1s128 MBJudgeable
DefragmentGiven files spread over N disk clusters, find the minimum number of single-cluster moves to place them contiguously in order, with file i starting after file i-1.Medium6GreedyArray+2No attempts yet1s128 MBJudgeable
Four Integers Summing to ZeroCount the number of index tuples (a, b, c, d) with A[a] + B[b] + C[c] + D[d] = 0, given four arrays of size n.Medium6Hash mapSorting+2No attempts yet12s1024 MBJudgeable
CitystarFor each street, find the five house numbers whose span (max minus min plus 1) is smallest, breaking ties by the smallest house numbers.Medium6SortingSliding window+2No attempts yet1s128 MBJudgeable
Castle WallsGiven blue and red hooks with distinct line positions, count blue-red pairs whose endpoints satisfy the crossing inequality.Medium6SortingPrefix sum+1No attempts yet1s128 MBJudgeable
Lining Up in OrderGiven a permutation of 1..N, find the fewest children to move to either end so the line becomes increasing; the answer is N minus the longest run of consecutive values that already appears in increasing order.Medium6ArrayDynamic programming+1No attempts yet1s256 MBJudgeable
ProbeGiven range-sum probe results on a length-K binary road, find the lexicographically smallest object placement satisfying all of them, or NONE.Medium6ArrayPrefix sum+2No attempts yet1s128 MBJudgeable
AppChoose a subset of active apps to deactivate whose freed memory is at least M while minimizing the total deactivation cost.Medium6Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
Cell phone tunesDecide whether a given tune is good (no adjacent equal-multiset blocks), contains all n sounds, and cannot be extended by a single sound on either end.Medium6String matchingImplementation+1No attempts yet1s32 MBJudgeable
Pizza Delivery ScheduleGiven recorded pizza deliveries by week and weekday, find the fixed weekly-cycle schedule of period 1 to 4 weeks that minimizes mismatched days.Medium6Brute forceImplementation+2No attempts yet1s128 MBJudgeable
TerrariumSimulate up to 26 snakes crawling one cell per second on an N x N grid for T seconds and print the final board.Medium6SimulationImplementation+1No attempts yet3s128 MBJudgeable
The DragonPick an order of pastures from either end each day, losing a sheep per day everywhere, to maximize total sheep eaten.Medium6GreedySorting+1No attempts yet1s128 MBJudgeable
Cheap TravelsPick a sequence of hotels so consecutive stops are at most 800 km apart, minimizing total price (ties: fewest nights), and also minimizing nights (ties: lowest price).Medium6Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Two CakesTwo cakes must be built layer by layer from two given permutations, using one dedicated worker per layer type; find the minimum total time.Medium6GreedyArray+2No attempts yet4s128 MBJudgeable
RooksComplete a partially filled n by n board to a full non-attacking rook placement, choosing the lexicographically smallest completion.Medium6GreedySorting+2No attempts yet1s128 MBJudgeable
KangaroosFor each lens interval, find the longest contiguous block of sighting intervals that all overlap it.Medium6IntervalsSorting+2No attempts yet5s128 MBJudgeable
Speed LimitsGiven speed limits on intervals of a highway plus a car's top speed, pick the single limit whose removal maximizes total satisfaction (distance times speed).Medium6ArrayPrefix sum+2No attempts yet1s128 MBJudgeable
NumberEaterCount the number of distinct value sets obtainable as the set of a contiguous subarray of the given sequence.Medium6Hash mapArray+1No attempts yet1s128 MBJudgeable
Longest Common Increasing SubsequenceFind the length of the longest strictly increasing sequence that is a subsequence of both given sequences.Medium6Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
AlgebraDecide whether a target permutation can be reached from the identity using only rotations of three distinct positions.Medium6MathArrayNo attempts yet1s128 MBJudgeable
Genome EvolutionCount the shared gene blocks of length above one that appear as consecutive runs in both chromosomes.Medium6IntervalsArrayNo attempts yet1s128 MBJudgeable
CirclelandYou start at room R1 on a corridor cycle and visit every room, then leave through any exit while walking the shortest total corridor distance.Medium6GreedyPrefix sum+1No attempts yet1s256 MBJudgeable
Kabaleo LitePick a stack for your last chip so your hidden colour stays the strictly most visible colour whatever rivals play, and list every stack with that guarantee.Medium6GreedyArray+1No attempts yet1s128 MBJudgeable
Longest Arithmetic ProgressionFind the length of the longest subsequence of the given sorted list that forms an arithmetic progression.Medium6Dynamic programmingArrayNo attempts yet2s1024 MBJudgeable
Mascot SongMaintain an array under point updates and left rotations, reporting the number of maximal strictly increasing runs after each query.Medium6ArraySimulationNo attempts yet1s32 MBJudgeable
EraserGiven a sequence, add the products of every triple of entries at distinct positions with three different values, modulo 1,000,000,007.Medium6CombinatoricsMath+1No attempts yet1s256 MBJudgeable
Parcel PostsSplit the elevation array into the most contiguous parcels so each parcel contains a triple whose middle value is strictly above or below both outer values.Medium6GreedyArrayNo attempts yet20s1024 MBJudgeable
Mine Layer (Small)Given a small Minesweeper-style clue grid (R is 3 or 5, C is 3 to 5), find the maximum number of mines the middle row can hold over all layouts that match the clues.Medium6Brute forceBacktracking+2No attempts yet5s512 MBJudgeable
Pat PatAfter point swaps in an array, answer queries asking whether a subarray is nondecreasing.Medium6Segment treeArrayNo attempts yet1s256 MBJudgeable
Colorful VillageMaintain N houses under range repaint operations and answer queries counting how many of the T colors appear in a range.Medium6Segment treeBit manipulation+2No attempts yet2s512 MBJudgeable
Delete the X-th smallest numberMaintain a multiset under insertions and queries that report and delete the X-th smallest element, with values and query count up to 2e6.Medium6Segment treeBinary search+2No attempts yet2s512 MBJudgeable
Number LockGiven two equal-length digit strings S and T, find the minimum number of turns where each turn adds 1 or subtracts 1 (mod 10) to every dial in some contiguous range.Medium6Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Time Travel and MultisetProcess insert, delete, and count operations on a time-indexed multiset, where each value's count at time t depends on prior operations with time at most t.Medium6Dynamic programmingBinary search+2No attempts yet2s512 MBJudgeable
Colorful Village 2For each query range in a nondecreasing brightness array, report how many times the most frequent value appears.Medium6ArrayBinary search+1No attempts yet2s512 MBJudgeable
Shifting a MatrixParse a compressed shift-operation string with nested repetitions, apply the row and column rotations to an N by N matrix, and print the result.Medium6SimulationImplementation+2No attempts yet5s512 MBJudgeable
Maximum Clique of an Interval GraphGiven N intervals, find a largest set of pairwise overlapping intervals, and output its size plus the vertex indices in lexicographically smallest order.Medium6SortingGreedy+2No attempts yet1s512 MBJudgeable
Happy KindergartenSplit a non-decreasing array of heights into K contiguous groups to minimize the sum of each group's max-minus-min.Medium6Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
Cocktail Shaker SortSimulate cocktail shaker sort on a permutation and report the number of swaps performed in each of the N steps.Medium6ArraySimulation+1No attempts yet1s512 MBJudgeable
JetpackFind the lexicographically smallest schedule of screen holds that moves Barry right across N columns through a 10-row grid while avoiding obstacles.Medium6Dynamic programmingGreedy+2No attempts yet1s64 MBJudgeable
CardsGiven an even row of cards with integers, two players alternately take an end card; the first player maximizes his total sum while the second minimizes it. Report the best score the first player can guarantee.Medium6Dynamic programmingGame theory+2No attempts yet2s512 MBJudgeable
Parking LotSimulate a single-line parking lot where each arriving vehicle takes the first free gap from the entrance that fits, and total the fees for vehicles that park.Medium6SimulationImplementation+2No attempts yet2s512 MBJudgeable
Musical PlagiarismGiven a song as a sequence of notes and a suspect excerpt, decide whether the excerpt appears in the song under some transposition (key change).Medium6String matchingArray+2No attempts yet2s512 MBJudgeable
Earl's Extremely Efficient EncryptionGiven a growing set of stored image indices, find the longest run of consecutive unmarked indices below each query length w_j.Medium6ArraySorting+2No attempts yet2s512 MBJudgeable
Flipping SwitchesSimulate the given local-search procedure: repeatedly flip the lowest-numbered switch that increases the number of shining lights, then print the final setting.Medium6SimulationGreedy+2No attempts yet7s512 MBJudgeable
Step Step EvolutionGiven a sequence of dance-pad arrows, find the minimum number of adjacent pairs pressed by the same foot, respecting the left/right column rule.Medium6Dynamic programmingGreedy+2No attempts yet8s512 MBJudgeable
CommuteGiven a grid of vertical/horizontal blocks and a fixed set of moves, find the fewest steps from any vertical block in row 0 to row R-1.Medium6BFSGraph+1No attempts yet1s256 MBJudgeable
Suspicious SamplesFor each condition, count samples whose value is greater or less than the min, max, or average of samples in the preceding time window.Medium6Sliding windowQueue+2No attempts yet2s512 MBJudgeable
PohlepkoFind the lexicographically smallest string read along a monotone path from the top-left to the bottom-right cell of a grid of lowercase letters.Medium6Dynamic programmingGreedy+2No attempts yet1s64 MBJudgeable
RAMProcess files one by one; after each, count how many times a given letter appears in the last K characters seen so far.Medium6ArraySimulation+2No attempts yet2s512 MBJudgeable
Big TableEach row of a huge table repeats a short digit period; answer rectangle-sum queries without materializing the table.Medium6Prefix sumMath+2No attempts yet4s128 MBJudgeable
ArchitectGiven N tree points and Q axis-aligned polygons of at most 12 vertices, count for each polygon how many trees lie inside it, border included.Medium6GeometryArray+2No attempts yet1s64 MBJudgeable
Array CharacteristicMove one element to any position and maximize the weighted sum of A_i times its new index.Medium6ArrayPrefix sumNo attempts yet2s512 MBJudgeable
Fortune telling with sticksGiven an n by m letter grid and p query words, find for each word the longest contiguous substring that can be placed along a row or column in one of four directions.Medium6Brute forceImplementation+2No attempts yet2s512 MBJudgeable
Foehn PhenomenaAfter each range add to altitudes, report the wind temperature at spot N, where the total depends on the altitude differences between adjacent spots.Medium6ArrayPrefix sum+1No attempts yet1s256 MBJudgeable
Sequence and Queries 16Maintain an array under point updates and range queries that ask for the leftmost index of the minimum value in a subarray.Medium6Segment treeArray+2No attempts yet2s512 MBJudgeable
Sequence and Queries 17Maintain an array under point updates and answer range-minimum queries over subarrays.Medium6Segment treeArray+2No attempts yet2s512 MBJudgeable