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,694 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Bessie's Birthday BuffetChoose patches of strictly increasing quality and walk between them to maximize total quality gained minus E per step.Medium6Dynamic programmingShortest path+1No attempts yet1s256 MBJudgeable
NAFTAFor each K from 1 to S, drill up to K whole columns to drain every touched oil pool and maximize the collected oil.Medium6Dynamic programmingIntervals+1No attempts yet2s512 MBJudgeable
Speak your mind!Find the fewest words needed to write an integer as signed powers of two joined by four-word sums and differences.Medium6Dynamic programmingMathNo attempts yet2s256 MBJudgeable
Deque Sort 2Place each number at the front or back of an existing deque or into a new one so the deques join into ascending order with the fewest deques.Medium6Dynamic programmingSorting+1No attempts yet1s256 MBJudgeable
Apples and BananasPick a path from the top left to the bottom right using right, down, and diagonal steps to maximize apples left below plus bananas left above.Medium6Dynamic programmingPrefix sumNo attempts yet1s256 MBJudgeable
Merging FilesCompute the cheapest way to merge consecutive chapter files when each merge costs the sum of the two parts.Medium6Dynamic programmingIntervals+1No attempts yet2s256 MBJudgeable
Safe PassageMove all students from the gate to the dorm alone or in pairs at the slower pace, with someone carrying the cloak back each time, in minimum total time.Medium6GreedySorting+1No attempts yet2s256 MBJudgeable
Save the computerSpend a fixed budget on spare parts to maximize the product of per-part Poisson survival probabilities.Medium6Dynamic programmingMathNo attempts yet1s256 MBJudgeable
Sleeping at WorkSleep exactly M of N minutes in runs of at most R to maximize energy, with the k-th minute of a run worth k times its value.Medium6Dynamic programmingNo attempts yet1s256 MBJudgeable
GG NO RE OMG CHEATZFind the fewest extra attacker units that lift the dice-battle win chance to at least 75 percent.Medium6Dynamic programmingProbability+1No attempts yet3s256 MBJudgeable
Restaurant OrdersGiven menu prices and several order totals, rebuild the exact item multiset behind each total, or report Impossible or Ambiguous.Medium6Dynamic programmingNo attempts yet1s256 MBJudgeable
Chicken JoggersPlace the fewest extra lamps so every trail a jogger who starts at intersection 1 and returns after exactly S meters could use has a lamp on one end.Medium6Dynamic programmingTree+1No attempts yet1s256 MBJudgeable
ProteinsInsert the fewest letters into a DNA string so reading it in blocks of three from the start yields at least n ATG blocks.Medium6Dynamic programmingGreedy+1No attempts yet1s256 MBJudgeable
Magic CheckerboardFill empty cells so rows and columns increase strictly and diagonal neighbors differ in parity with the smallest total sum, or output -1.Medium6Dynamic programmingMath+1No attempts yet5s256 MBJudgeable
Floppy MusicDecide if every drive head can cover its required sound intervals by moving steadily without a forced turn or stray sound.Medium6Dynamic programmingIntervalsNo attempts yet1s256 MBJudgeable
4×n TilingCount the ways to tile a 4 by N board with 1 by 3 and 3 by 1 trominoes modulo 1000000007 for each test case.Medium6Dynamic programmingBit manipulationNo attempts yet2s256 MBJudgeable
Coin Turning GameGiven a row of heads and tails, decide if the first player wins the interval-flip game and report the smallest winning first move.Medium6Game theoryDynamic programming+2No attempts yet2s256 MBJudgeable
Red RectanglesCount the subrectangles of an N by M red and blue grid that contain only red cells.Medium6StackDynamic programming+1No attempts yet1s512 MBJudgeable
Currency ConversionSchedule at most b bank exchanges to meet dated purchase needs while maximizing daily holding rewards minus trip costs.Medium6Dynamic programmingPrefix sumNo attempts yet1s256 MBJudgeable
Drink ResponsiblyDecide whether whole numbers of up to eight drinks can total exactly m in cost and u in alcohol, and print the lexicographically smallest purchase.Medium6Dynamic programmingMathNo attempts yet1s256 MBJudgeable
Dance RecitalReorder the given routines so the total number of dancers shared by consecutive routines is as small as possible.Medium6Dynamic programmingBit manipulationNo attempts yet1s256 MBJudgeable
Perfect DuetTwo singers split the pitch sequence in order so the sum of each singer's consecutive pitch jumps is as small as possible.Medium6Dynamic programmingNo attempts yet2s256 MBJudgeable
MonstersThree monster colors eat each other in a cycle when random mixed pairs meet, and you compute each color's chance to be the last one standing.Medium6ProbabilityDynamic programmingNo attempts yet2s256 MBJudgeable
CYK's very fun graph building gameCount colorings of N vertices with K colors plus edge sets where each vertex points to at most one smaller vertex of a different color, modulo 1000000007.Medium6Dynamic programmingCombinatorics+1No attempts yet1s256 MBJudgeable
Loda TeleportationsGiven N strings in order, find the longest subsequence where each earlier string is both a prefix and a suffix of the later one.Medium6Dynamic programmingString matching+1No attempts yet1s64 MBJudgeable
MillionaireDecide after each correct quiz answer whether to quit or continue so the expected log utility is maximal, then convert that utility into a dollar amount.Medium6Dynamic programmingProbability+1No attempts yet2s256 MBJudgeable
Bundles of JoyBuy the cheapest set of nested or disjoint bundles that covers every dessert type.Medium6Dynamic programmingTreeNo attempts yet3s256 MBJudgeable
Card Game StrategyAlice picks t in [a, b] to maximize the gap while Bob replies with k cards whose sum is closest to t.Medium6Dynamic programmingGame theoryNo attempts yet5s1024 MBJudgeable
Squeeze the CylindersGiven up to 500 ground-resting cylinders with fixed order, compute the minimum wall-to-wall width when squeezed together.Medium6Dynamic programmingGeometryNo attempts yet1s256 MBJudgeable
Tray BienCount the ways to cover a 3 by m shelf with blocked cells using 1 by 1 and domino trays, where only the domino pairings distinguish arrangements.Medium6Dynamic programmingNo attempts yet1s256 MBJudgeable
SkylineBuild N towers to exact heights with 1, 2-adjacent and 3-consecutive floor operations costing 3, 5 and 7 for the least total cost.Medium6Dynamic programmingNo attempts yet2s256 MBJudgeable
BankDecide whether M banknotes can be distributed to N people so each person receives exactly the owed salary.Medium6Dynamic programmingBit manipulationNo attempts yet1s256 MBJudgeable
Two-row tableCount ways to place fixed and shared numbers into two increasing rows so every column increases downward.Medium6Dynamic programmingCombinatoricsNo attempts yet1s256 MBJudgeable
Largest Rectangle of OnesFind the area of the largest all-ones subrectangle in each binary matrix given until 0 0.Medium6StackMatrix+1No attempts yet3s512 MBJudgeable
Two potato storesSplit N potato bags into two stores with one store holding exactly L bags to minimize the product of the two average potato prices.Medium6Dynamic programmingNo attempts yet1s64 MBJudgeable
Orange ShippingPartition the ordered oranges into consecutive boxes of at most M to minimize the sum of K plus size times the size spread in each box.Medium6Dynamic programmingSliding windowNo attempts yet1s256 MBJudgeable
262144Merge adjacent equal numbers into a number one larger in any order to build the largest value possible.Medium6Dynamic programmingIntervalsNo attempts yet2s512 MBJudgeable
The 248 GameMerge adjacent equal numbers into a number one larger to maximize the largest value left.Medium6Dynamic programmingIntervalsNo attempts yet2s512 MBJudgeable
gBalloon (Small)Spend at most Q height-change energy across balloons with layered winds to minimize the time when the last balloon reaches position 0.Medium6Dynamic programmingBinary searchNo attempts yet5s512 MBJudgeable
Finding 123456789Count subsets of occurrences of P in S whose starting positions multiply to a common multiple of 1 through 9, modulo 1000000007.Medium6Dynamic programmingString matching+1No attempts yet1s512 MBJudgeable
Number of Strings Containing a SubstringCount length-L lowercase strings that contain the given word S as a contiguous substring, modulo 1,000,000,009.Medium6Dynamic programmingString matchingNo attempts yet2s512 MBJudgeable
Broken Calculator (Large)Find the fewest digit, multiply, and equals presses that form factors whose product equals X using only working digits.Medium6Dynamic programmingNumber theoryNo attempts yet5s512 MBJudgeable
New Year's Eve Wine PyramidSimulate B bottles poured into the top glass of a wine pyramid where overflow splits into three glasses below and report the amount in glass N on level L.Medium6SimulationDynamic programmingNo attempts yet5s512 MBJudgeable
Last Hit (Small)Choose which monster to shoot or when to pass on each turn so your shots land the killing blow on the most valuable monsters before the tower kills them.Medium6Dynamic programmingGame theory+1No attempts yet5s512 MBJudgeable
Last HitChoose which monsters to last-hit for gold while a tower shoots the closest living monster on its own turns.Medium6Dynamic programmingMathNo attempts yet10s512 MBJudgeable
Falling Diamonds (Small)N diamonds fall onto a pile and slide left or right at random, and you compute the probability that one stops exactly at the given spot.Medium6ProbabilitySimulation+1No attempts yet5s512 MBJudgeable
Garbled Email (Small)Split the received string into dictionary words with changed letters at least 5 apart and as few changes as possible.Medium6Dynamic programmingTrieNo attempts yet30s512 MBJudgeable
Zombie Smash (Large)Plan a route from the origin that smashes the most time-windowed zombies given Chebyshev travel time and a 750 ms weapon recharge.Medium6Dynamic programmingSorting+1No attempts yet5s512 MBJudgeable
Swinging Wild (Small)Decide whether a chain of vine swings, each limited by grip distance and vine length, reaches the far ledge.Medium6GraphDynamic programmingNo attempts yet5s512 MBJudgeable
Box Factory (Small)Match boxes and toys from two run-length encoded lines in order to maximize the number of equal-type pairs.Medium6Dynamic programmingNo attempts yet5s512 MBJudgeable
Google Royale (Small)Compute the best possible chance of growing A dollars to V dollars with capped doubling bets and report the largest opening bet that reaches it.Medium6Dynamic programmingProbability+1No attempts yet10s512 MBJudgeable
A.I. War (Large)Find the smallest connected set of planets from planet 0 that borders planet 1, breaking ties by the largest border, and report both counts.Medium6BFSShortest path+1No attempts yet5s512 MBJudgeable
World Cup 2010 (Small)Buy the cheapest set of knockout match tickets so each team misses at most its allowed number of games whatever the results.Medium6Dynamic programmingTreeNo attempts yet5s512 MBJudgeable
Make It Smooth (Small)Change, delete, or insert pixels at given costs so every pair of neighbors differs by at most M for the lowest total cost.Medium6Dynamic programmingShortest path+1No attempts yet5s512 MBJudgeable
Alphabetomials (Small)Given a degree-4 polynomial and a dictionary, sum its value over all phrases of up to K dictionary words, modulo 10009.Medium6Dynamic programmingMath+2No attempts yet5s512 MBJudgeable
Rainbow TreesCount edge colorings of a small tree with k colors so that any two or three consecutive edges on a path get distinct colors, modulo 1e9+9.Medium6Dynamic programmingTree+1No attempts yet5s512 MBJudgeable
Endless Knight (Small)Count monotone right-and-down knight paths from (1,1) to (H,W) on a grid, avoiding up to 10 blocked squares, modulo 10007.Medium6Dynamic programmingCombinatoricsNo attempts yet5s512 MBJudgeable
Ugly Numbers (Large)Count expressions formed by inserting plus, minus, or nothing between digits whose evaluated value is divisible by 2, 3, 5, or 7.Medium6Dynamic programmingNumber theory+1No attempts yet5s512 MBJudgeable
Increasing Speed LimitsGiven a sequence generated by a small recurrence, count strictly increasing subsequences by position, modulo 1000000007.Medium6Dynamic programmingSorting+2No attempts yet5s512 MBJudgeable
Last three digits of (3 + √5)^nCompute the last three digits before the decimal point of (3 + sqrt(5))^n for n up to two billion.Medium6MathNumber theory+1No attempts yet5s512 MBJudgeable
Don't be lateGiven an undirected weighted graph with per-edge time and fare, find the minimum total fare of a path from node 1 to node N whose total time is at most T.Medium6Shortest pathGraph+2No attempts yet2s128 MBJudgeable
Multiplication GameGiven a set of allowed digits, find the fewest factors (minus one) whose digits all come from the set and whose product is K.Medium6Dynamic programmingNumber theoryNo attempts yet1s128 MBJudgeable
Republic of InhanicaGiven a tree rooted at island 1, cut a minimum-cost set of edges so that every leaf other than the root is disconnected from the root.Medium6TreeDynamic programmingNo attempts yet1s256 MBJudgeable
PalinilapA lowercase string may be modified at exactly one position or left alone; find the maximum number of palindromic substrings achievable.Medium6StringDynamic programming+1No attempts yet1s512 MBJudgeable
UniversitiesOn a tree whose nodes are black or white with weighted happiness, find the maximum total weight of a path that contains equally many black and white nodes.Medium6TreePrefix sum+1No attempts yet1s1024 MBJudgeable
Lexicographic SortingCount subsets of the integers in [A, B] whose lexicographic order as strings matches their numerical order, modulo 1e9+7.Medium6SortingString+1No attempts yet1s1024 MBJudgeable
London UndergroundGiven subway lines with stop times and a line-change cost, find the minimum travel time between two stations.Medium6Shortest pathGraph+1No attempts yet1s512 MBJudgeable
Card Fusion EventMerge adjacent cards until one remains, where a merge pays the sum of both levels and keeps only the left card's level; maximize total gold.Medium6IntervalsDynamic programmingNo attempts yet1s512 MBJudgeable
Jumping MinhoBuy a cheapest subset of jump lengths so every integer on the line is reachable from the start; print -1 if impossible.Medium6Dynamic programmingNumber theory+1No attempts yet2s512 MBJudgeable
MutaliskGiven the health of at most 3 SCVs, find the fewest attacks that deal 9, 3, 1 damage in some order to distinct SCVs and destroy them all.Medium6Dynamic programmingBrute forceNo attempts yet2s512 MBJudgeable
PlaylistCount length-P sequences over N songs where every song appears at least once and any two copies of the same song are separated by at least M other songs.Medium6Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Painting blocksCount colorings of N blocks with 4 colors so that the number of red and yellow blocks are both even, modulo 10007.Medium6CombinatoricsMath+2No attempts yet2s512 MBJudgeable
Path GameGiven a 2 by M grid of white and black cells with a guaranteed left-right white path, find the maximum number of white cells that can be turned black while keeping some left-right path.Medium6Dynamic programmingGraph+2No attempts yet2s512 MBJudgeable
Building a GraphBuild a connected graph (tree) with N nodes and N-1 edges, where each node's score depends on its degree, and maximize the total score.Medium6TreeDynamic programming+1No attempts yet2s512 MBJudgeable
Favorite ArrayCount length-N arrays with entries from 1 to K where no earlier element is a larger multiple of the next.Medium6Dynamic programmingCombinatorics+1No attempts yet2s512 MBJudgeable
Ordinary Knapsack 2Given N item types with weight, satisfaction, and a copy count, choose a multiset whose total weight is at most M and whose total satisfaction is largest.Medium6Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
Collecting starsEach stage yields up to 2 stars when cleared with enough stars in hand; find the minimum number of clears to collect all 2N stars or report it is impossible.Medium6GreedySorting+1No attempts yet2s512 MBJudgeable
Karaoke 2Assign the unclaimed middle pitches to one of two singers to minimize how many times the microphone changes hands across the song.Medium6Dynamic programmingGreedyNo attempts yet2s512 MBJudgeable
Robot MovementA robot walks on an infinite grid following a fixed-length string of U, D, L, R moves. Change at most M characters to maximize how many times it returns to the origin.Medium6Dynamic programmingString+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
TrislePartition N powers into three nonempty groups to maximize the sum of the three XOR values.Medium6Dynamic programmingBit manipulation+1No attempts yet2s512 MBJudgeable
Packing BallsGiven counts of red, green, and blue balls, pack them all into minimum boxes where each box holds 1 to 3 balls of one color or three distinct colors.Medium6GreedyMath+2No attempts yet2s512 MBJudgeable
Tree CountryCount the subsets of K vertices in a tree that form a connected subtree, modulo 1e9+7.Medium6Dynamic programmingTree+2No attempts yet2s512 MBJudgeable
AckaCount the ways to assign each of S songs to a nonempty subset of three singers so that the three singers get exactly D, K, and H songs.Medium6CombinatoricsDynamic programming+1No attempts yet2s512 MBJudgeable
Hongjun and balanced tablesCount the ways to fill a 3-by-C grid with nonnegative integers so that every triple of cells satisfying a + c = 2b sums to S.Medium6CombinatoricsMath+2No attempts yet2s512 MBJudgeable
Happy CowRemove portions from either end of a row over N days; on day d a portion with value H gives H times d. Maximize total happiness.Medium6Dynamic programmingIntervalsNo attempts yet2s512 MBJudgeable
A Dark Flame Dragon Sleeps in My Left HandFor each node in a weighted tree, find the distance to the farthest other node (the tree's eccentricity).Medium6TreeDFS+1No attempts yet2s512 MBJudgeable
Good SetsCount nonempty subsets of {1,...,N} whose decimal digits, pooled together, use each digit 0-9 at most once.Medium6Bit manipulationCombinatorics+1No attempts yet2s512 MBJudgeable
Sum of subtree sizesCount all connected subgraphs of a tree and output the sum of their vertex counts modulo 1e9+7.Medium6TreeDynamic programming+2No attempts yet2s512 MBJudgeable
Mountain ScenesCount vectors of w heights in [0,h] whose sum is at most n and which are not all equal, modulo 1e9+7.Medium6Dynamic programmingCombinatorics+2No attempts yet5s512 MBJudgeable
M and ADecide whether S can be interleaved character by character from a subsequence of S and a subsequence of T, both of the same length as S.Medium6Dynamic programmingStringNo attempts yet5s512 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
Dice Game Win ProbabilityA token moves on states 0 to N, stepping down with probability Q/P and up otherwise; find the probability of ending at N and print it modulo 1e9+7 as a reduced fraction.Medium6Dynamic programmingProbability+1No attempts yet1s512 MBJudgeable
RobotCompute the expected squared distance from the origin after a robot takes N probabilistic left, straight, or right moves, and print it as a fraction modulo 1e9+7.Medium6ProbabilityMath+1No attempts yet1s512 MBJudgeable
Sum of digitsSum every digit that appears in the decimal representations of 0 through n, where n can be as large as 10^16.Medium6MathImplementation+1No attempts yet2s512 MBJudgeable
Dice and CandiesFind the expected number of throws of a fair six-sided die until the running sum reaches at least N, and print the value to six decimals.Medium6Dynamic programmingProbability+2No attempts yet2s512 MBJudgeable
Flipping CoinsEach step flips a uniformly random set of A_i coins; find the expected number of heads after all K steps.Medium6ProbabilityDynamic programming+1No attempts yet2s512 MBJudgeable
Cutting a StringGiven cut positions on a string of length N, find the order of cuts that minimizes the total cost, where each cut of a piece of length L costs L.Medium6Dynamic programmingIntervalsNo attempts yet2s512 MBJudgeable
OR Score of a SequenceSplit the array into K contiguous non-empty groups and maximize the sum of each group's bitwise OR.Medium6Dynamic programmingBit manipulation+1No attempts yet2s512 MBJudgeable