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 results3,689 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Nowhere MoneyRepresent each amount as a sum of T(s) values (T(n) = Fibonacci-like count) with the fewest slots whose sizes differ by at least 2, and print the sizes and values.Medium6GreedyDynamic programming+2No attempts yet1s128 MBJudgeable
Stacking BallsPick balls from a triangular pile, where each ball needs both balls above it picked first, to maximize the total score; stopping early is allowed.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Another CrisisGiven a company tree and a threshold T percent, find the minimum number of leaf workers who must petition so that a petition reaches the root.Medium6TreeDFS+2No attempts yet1s128 MBJudgeable
Drop the TriplesPlayers alternate drawing cards from a stock and may drop valid triples; each maximizes perfect triples then common triples. Report the winner or a tie.Medium6GreedyDynamic programming+2No attempts yet1s128 MBJudgeable
ICPC Strikes AgainGiven a DAG of task dependencies, basic significances, and which employees perform which tasks, compute each employee's salary as the sum of significances of tasks they perform that no other task they perform depends on.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
Long Night of MuseumsWith at most 20 museums, viewing times, and travel times, find the largest number of distinct museums a 420-minute tour can include.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Duty Free ShopAssign each box entirely to one of two brands so both totals stay within limits, printing the greedy canonical assignment or Impossible to distribute.Medium6GreedyDynamic programming+2No attempts yet1s128 MBJudgeable
Class PackingGiven enrollments for seven grades, find the fewest classes where each class holds one grade or two consecutive grades within the group size limits (20, 25, or 30).Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Wi-Fi SetupCover all cow positions on a line with base stations, where a station covering an interval of length 2r costs A + B*r; minimize total cost.Medium6Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
Balanced Cow BreedsCount the ways to 2-color the parentheses in a string so that each color class, read in order, forms a balanced parenthesis sequence.Medium6Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Cows in a SkyscraperGiven up to 18 cow weights and an elevator capacity, find the minimum number of trips that carry every cow without exceeding the capacity.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
LandscapingEach flowerbed has a current and target dirt amount, and dirt can be bought, removed, or moved between beds at a per-unit distance cost; find the cheapest way to hit every target.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Nearby CowsOn a tree of N fields with C(i) cows at each field, report for every field the total cows within distance K, where K is at most 20.Medium6TreeDFS+2No attempts yet1s128 MBJudgeable
Villain RobotsChoose a string of K characters over {A,B,C} maximizing the total number of substring occurrences of the given pattern strings.Medium6Dynamic programmingString matching+2No attempts yet1s128 MBJudgeable
Umbrellas for CowsGiven cow positions on a line and a price for each umbrella width, find the cheapest set of umbrellas that covers every cow, allowing overlaps.Medium6Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
Visiting CowsGiven a tree with N vertices, choose the largest set of vertices with no two adjacent, which is the maximum independent set on a tree.Medium6TreeDynamic programming+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
Dividing the GoldGiven N coins with values, find the minimum difference between two piles and count the subsets forming the lighter pile, modulo 1,000,000.Medium6Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Mowing the LawnGiven N cows in a row with efficiencies, pick a subset that never includes more than K adjacent cows and maximize the total efficiency.Medium6Dynamic programmingSliding window+2No attempts yet1s128 MBJudgeable
Video Game TroublesGroup knapsack: buy at most one of each console, and only games whose console is already bought, maximizing total production value within budget V.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Great Cow GatheringPick a node of a weighted tree with node weights as the gathering point, and minimize the sum of cow count times distance to that node.Medium6TreeDFS+2No attempts yet1s128 MBJudgeable
Driving Out the PiggiesA bomb starts at city 1 of an undirected graph, detonates at each visit with probability P/Q and otherwise moves to a random neighbor; find the detonation probability for every city.Medium6ProbabilityGraph+2No attempts yet1s128 MBJudgeable
Mixed Up CowsCount permutations of N serial numbers (N at most 16) where every adjacent pair differs by more than K.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Buying HayGiven N package types with unlimited supply, each weighing P_i and costing C_i, find the minimum total cost to buy at least H pounds of hay.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
ChocolateFor C equally likely colors, after N draws where matching pairs are eaten, find the probability that exactly M colors remain on the table.Medium6Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Bulls and CowsCount binary sequences of length N where every pair of bulls has at least K cows between them, modulo 5000011.Medium6Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Cow Frisbee TeamCount the nonempty subsets of N cows whose rating sum is divisible by F, modulo 100000000.Medium6Dynamic programmingMath+2No attempts yet1s128 MBJudgeable
CakePartition the sequence of slice lengths into consecutive blocks, bottom to top, so each block's sum is at least the one above, and maximize the number of blocks.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Milking TimeChoose non-overlapping milking intervals, each separated by at least R rest hours, to maximize the total milk produced over N hours.Medium6Dynamic programmingBinary search+2No attempts yet1s128 MBJudgeable
Cell Phone NetworkGiven a tree of N pastures, choose the fewest vertices so that every vertex is chosen or adjacent to a chosen one.Medium6TreeDynamic programming+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
Round NumbersCount integers in [Start, Finish] whose binary form has at least as many zeroes as ones.Medium6Dynamic programmingBit manipulation+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
Cow TrafficIn a DAG where every edge goes from a lower to a higher numbered node, count how many source-to-barn paths cross each edge and output the maximum.Medium6GraphDynamic programming+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
Party at Hali-BulaGiven a company hierarchy tree, find the largest set of employees with no boss and employee both chosen, and report whether that maximum set is unique.Medium6TreeDynamic programming+2No attempts yet1s128 MBJudgeable
Xavier Is Learning to CountGiven m distinct positive integers and a size p (at most 5), count for every attainable sum the number of p-element subsets that add up to it, listing sums in increasing order.Medium6Dynamic programmingCombinatorics+2No attempts yet5s512 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
Always on the runFind the cheapest sequence of exactly k daily flights from city 1 to city n, where each ordered pair has a periodic price schedule over days.Medium6Dynamic programmingGraph+2No attempts yet1s128 MBJudgeable
RobberyGiven time-stamped rectangular exclusions, find the robber's position at each time step where it is uniquely determined, moving at most one cell per step.Medium6Dynamic programmingSimulation+1No attempts yet1s128 MBJudgeable
DividingGiven counts of marbles worth 1 to 6, decide whether the collection can be split into two sets of equal total value.Medium6Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Economic Phone CallsGiven a chronologically ordered call log with some entries marked important, keep the fewest entries so all important ones stay and the listed year-recovery rule still gives each kept call its original year.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Even a Kindergartner Could Solve ThisDecide whether each string over the alphabet {, }, and comma is a valid set by the given grammar, where brace characters can be either delimiters or atoms.Medium6StringDynamic programming+2No attempts yet2s128 MBJudgeable
Fixed Partition Contest ManagementAssign up to 10 problems to at most 3 members and order each member's load to minimize the sum of completion times, where a problem's duration depends on the solver's brightness.Medium6Brute forceDynamic programming+2No attempts yet1s128 MBJudgeable
Mondrian's DreamCount the number of ways to tile an h by w rectangle (up to 11 by 11) with 2 by 1 dominoes, for several test cases.Medium6Dynamic programmingBit manipulation+2No attempts yet1s256 MBJudgeable
ArbitrageGiven currencies and exchange rates, decide whether some cycle of conversions turns one unit of a currency into more than one unit.Medium6Shortest pathGraph+2No attempts yet1s128 MBJudgeable
The Tower of BabylonGiven block types with unlimited copies, each reorientable, find the maximum height of a stack where each block's base is strictly smaller than the one below.Medium6Dynamic programmingSorting+1No attempts yet1s128 MBJudgeable
Ambiguous ResultGiven a parenthesis-free expression of numbers joined by + and *, restore parentheses to find the smallest and largest values it can evaluate to.Medium6Dynamic programmingIntervals+2No attempts yet1s128 MBJudgeable
Collecting BeepersGiven Karel's start and up to 8 beepers on a grid, find the shortest Manhattan-distance round trip visiting every beeper.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Christmas PresentsChoose a subset of children whose total price is at most p, maximizing excitement of chosen minus frustration of unchosen, and output the lexicographically smallest optimal 0/1 string.Medium6Dynamic programmingGreedyNo attempts yet1s128 MBJudgeable
A Language for ConstantsFor each nonzero integer C, output the shortest sequence of C+1/C-1 to start, then INCR and DBL, that builds C, breaking ties by total runtime with DBL cost T and INCR cost 2T.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
The Hungary GamesGiven a directed weighted graph, find the second smallest distinct total length among all walks from node 1 to node N, or -1 if fewer than two exist.Medium6Shortest pathGraph+2No attempts yet2s512 MBJudgeable
Vampire TunnelsFind the shortest path from node 0 to N-1 where the total length of above-ground edges is at most S.Medium6Shortest pathDynamic programming+1No attempts yet2s512 MBJudgeable
Tree PruningGiven a rooted binary tree with colored nodes, prune subtrees to make the whites minus blacks equal exactly D, minimizing the number of prunes.Medium6TreeDynamic programming+2No attempts yet2s512 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
CandySplit multiset candies with counts and calorie values into two groups so the two calorie totals differ as little as possible.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Bowling for NumbersGiven a row of valued pins, pick up to k non-overlapping blocks of exactly w consecutive pins to maximize the total score.Medium6Dynamic programmingPrefix sumNo 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
To bet, or not to betGiven a board of movement and skip instructions, compute the probability the chip reaches End within T turns and decide the bet.Medium6Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
Little Shop of FlowersPlace F ordered bunches into a row of V vases to maximize total aesthetic value, then output the lexicographically smallest optimal assignment.Medium6Dynamic programmingNo attempts yet1s128 MBJudgeable
FlattenDistribute chips between neighboring piles at a cost equal to the chips moved, and find the minimum total transferred to make all piles equal.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Recycling ProteinsGiven a source and target chain of amino acids, compute the minimum cost to convert one into the other using delete, insert, and replace with per-type costs.Medium6Dynamic programmingStringNo attempts yet1s128 MBJudgeable
Grazing on the RunBessie starts at position L and walks a line to eat N grass clumps; minimize the sum of times at which each clump is eaten.Medium6Dynamic programmingIntervals+1No attempts yet1s128 MBJudgeable
Dividing the PathPartition the segment [0, L] into consecutive pieces of even length between 2A and 2B so no cut lands strictly inside any cow's interval, and minimize the number of pieces, or report that no partition exists.Medium6Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
A Decorative FenceGiven N and a rank C, output the C-th alternating (zigzag) permutation of 1..N in lexicographic order.Medium6Dynamic programmingCombinatorics+1No 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
Cutting Out of FactorialsGiven k from 2 to 500, remove the fewest of 1!, 2!, ..., k! so the remaining product is a perfect square, and report that count.Medium6MathNumber theory+2No attempts yet1s128 MBJudgeable
Algarvu-ScrabbleGiven up to 8 digit tiles, place them one by one at either end of a row to maximize prime-direction scoring minus penalties for unused tiles.Medium6BacktrackingBrute force+2No attempts yet1s1024 MBJudgeable
BacteriaEach adult produces one young per second while young mature into adults; find the total population after T seconds modulo K, given initial counts.Medium6MathCombinatorics+2No attempts yet1s1024 MBJudgeable
Operator SignsInsert + or - between adjacent numbers so the left-to-right value equals the target, keeping every partial result within 10000, and print the lexicographically smallest expression.Medium6Dynamic programmingBacktracking+2No attempts yet1s1024 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
CourierDeliver parcels to cities on a line before their deadlines, minimizing the time to return to the warehouse, or report impossibility.Medium6Dynamic programmingSortingNo attempts yet1s1024 MBJudgeable
Unit TransformationFind the minimum cost to build a target number from 1 using only operations on the last digit.Medium6Dynamic programmingBFS+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
ConcertGive K spectators a +1 height boost so that the maximum number of people stand strictly taller than everyone in front of them.Medium6Dynamic programmingGreedyNo attempts yet1s1024 MBJudgeable
Word GroupingSplit N words into the fewest groups so that each group shares at least one common letter, with at most 15 distinct letters.Medium6Bit manipulationDynamic programming+1No 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
PassengersGiven each request's row and earliest time, find the least total time for the attendant to serve all and return to row 1.Medium6Dynamic programmingGreedy+1No attempts yet1s1024 MBJudgeable
Airplane PassengersGiven requests at row a made no earlier than minute b, find the minimum minutes for an attendant starting at row 1 to reach every request row on time.Medium6Dynamic programmingSorting+2No attempts yet1s1024 MBJudgeable
Optimal KeypadSplit a 30-character alphabet tape into 12 labeled pieces to minimize total keystrokes for a word dictionary, printing the lexicographically smallest optimal cut string.Medium6Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
Calendar GameOn a fixed 1900-2001 calendar, two players alternately advance a date by one day or to the same day next month; decide if the first player wins.Medium6Game theoryDynamic programming+1No attempts yet1s128 MBJudgeable
Gene FunctionAlign two DNA sequences by inserting blanks to maximize the sum of position-wise match values from a given table.Medium6Dynamic programmingStringNo attempts yet1s128 MBJudgeable
Joke with TurtlesEach turtle claims a count of turtles ahead and behind it; choose positions to maximize how many claims hold at once.Medium6Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
String FoldingFind the length of the shortest folded sequence, using repeat counts like 3(AB), that unfolds to the given uppercase string.Medium6Dynamic programmingStringNo attempts yet2s128 MBJudgeable
The Dog TaskBob walks a polygonal path through N points; Ralph may leave each segment to visit at most one interesting place and never reuse a place. Maximize places visited.Medium6GeometryGraph+2No attempts yet1s128 MBJudgeable
EmbassyOrder N people in a queue to minimize the total fee paid for those who finish after their train departure time.Medium6GreedySorting+1No attempts yet1s128 MBJudgeable
SoccerGiven 16 teams, a fixed bracket, and pairwise win probabilities, compute each team's probability of winning the single-elimination tournament.Medium6Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
Pimp My RideGiven n jobs with base prices and pairwise surcharges paid when a later job follows an earlier one, find the cheapest order to finish all jobs.Medium6Dynamic programmingBit manipulationNo attempts yet1s128 MBJudgeable
Jamie's Contact GroupsAssign each of N friends to one of M allowed groups so that every friend lands in exactly one group and the largest group size is as small as possible.Medium6Binary searchGraph+2No 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
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
Infinite GameGiven sets A and B of positive steps taken alternately right and left, decide whether every integer can be reached.Medium6Number theoryDynamic programming+2No attempts yet5s128 MBJudgeable
Four Gate PushGiven mineral and gas budgets and per-unit strengths, maximize total strength over non-negative counts of three unit types.Medium6Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
BonsaiRoot a weighted tree and cut edges of minimum total weight so that no original leaf stays connected to the root.Medium6TreeDFS+2No attempts yet1s128 MBJudgeable
Number GameWith Ellie's responses fixed by a1..a20, decide if the first player can force reaching 0 in a subtraction game.Medium6Game theoryDynamic programming+1No attempts yet1s128 MBJudgeable
Leap FrogGiven sorted positions, Jack and Jill alternate hopping over each other within distance 10; find the minimum total jumps until one lands on the last position.Medium6Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
SpamCount how many plain-text messages encode to the same spam encoding as a given message.Medium6Dynamic programmingStringNo attempts yet1s128 MBJudgeable
Colored StonesRemove the fewest stones so that in the remaining row every color appears in one contiguous block.Medium6Dynamic programmingBit manipulationNo attempts yet1s128 MBJudgeable
Cake CuttingSplit a w by h rectangle into m axis-aligned integer rectangles, each cut dividing one piece, to minimize the largest piece's area.Medium6Dynamic programmingDivide and conquer+1No attempts yet1s128 MBJudgeable
BracketsGiven a bracket string, find the maximum length of a regular bracket sequence obtainable as a subsequence.Medium6Dynamic programmingIntervals+1No attempts yet1s128 MBJudgeable