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,692 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Buying FeedBuy at least K pounds of feed from stores along a 1D route, paying purchase cost plus K^2 cents per mile for the load carried, and minimize the total.Hard8Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
CandyGiven starting candies, allowed daily eating amounts, and favorite numbers that trigger bonus candies, maximize total candies eaten or report -1 if infinite.Hard8Dynamic programmingGraph+2No attempts yet1s128 MBJudgeable
The TriangleGiven a triangular grid of values, find the sub-triangle (either orientation, side at least K) whose truncated average is largest.Hard8Binary searchPrefix sum+2No attempts yet2s128 MBJudgeable
Coin GameTwo players alternately take coins from the top of a pile, where each move may take between 1 and twice the previous move's count; find the maximum total value the first player can guarantee with optimal play from both sides.Hard8Dynamic programmingGame theory+2No attempts yet1s32 MBJudgeable
Cow Toll PathsFor each query, find the cheapest s-t trip where cost is the sum of edge tolls plus the single largest pasture toll on the route. N=250, K=10000.Hard8GraphShortest path+2No attempts yet1s128 MBJudgeable
Cow TelephonesGiven a tree with cows at its leaves and vertex capacity K plus unit edge capacity, find the maximum number of disjoint leaf-to-leaf conversation paths.Hard8TreeDynamic programming+2No attempts yet1s128 MBJudgeable
Water SlidesOn a DAG where each node leading to the sink, Bessie maximizes her worst-case path sum when up to K times she is forced down the worst outgoing edge.Hard8Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Telephone LineRaise each pole to height at least its original, paying squared increase plus C times adjacent height gaps, and minimize the total.Hard8Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Grabbing LandSplit N rectangles into groups, each group costing the product of its max width and max height, minimizing the total cost.Hard8SortingDynamic programming+1No attempts yet1s128 MBJudgeable
Silver Lilypad PondOn a grid with knight moves, place the fewest new lilypads so the cow can travel from start to goal, then count the shortest such paths.Hard8GraphShortest path+2No attempts yet1s128 MBJudgeable
Fire Evacuation PlanGiven a grid with walls, flowers, people, and one exit, find the minimum time for everyone to reach the exit, where no two people may occupy the same cell at the same second.Hard8BFSGraph+2No attempts yet1s128 MBJudgeable
Rectangular PaintingGiven a nesting tree of rectangles and photo leaf sizes, orient each sibling group horizontally or vertically to minimize the root rectangle area.Hard8TreeDFS+2No attempts yet1s128 MBJudgeable
Minimum-Cost Prefix-Free LanguageGiven n and d character costs, find the minimum total cost of a prefix-free set of exactly n words; multiple test cases end with 0 0.Hard8Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Brunhilda's BirthdayFor each n, find the minimum number of calls of primes from a given set that reduce n to 0 by replacing n with p*floor(n/p), or report infinity.Hard8Dynamic programmingNumber theory+2No attempts yet1s256 MBJudgeable
AppendGiven an LZ-style encoding as a list of (back-reference, length) pairs, count how many prefix positions split it into two valid non-empty encodings whose concatenation reproduces the original string.Hard8StringImplementation+2No attempts yet1s128 MBJudgeable
FoldGiven the sequence of A/V fold directions along an unfolded paper strip, find the minimum number of all-layer folding steps that produce it.Hard8Dynamic programmingRecursion+2No attempts yet1s128 MBJudgeable
Domino TilingCover a grid with pre-placed tiles and all given dominoes, then output the lexicographically smallest valid tiling and the count of other tilings.Hard8BacktrackingDynamic programming+2No attempts yet1s128 MBJudgeable
Letter LiesCount the number of length-L paths from a greeting sentence to a closing sentence in a directed graph whose successor rules guarantee no sentence repeats.Hard8Dynamic programmingGraph+2No attempts yet3s128 MBJudgeable
Careful DeclarationMerge two word sequences into the shortest common supersequence, breaking ties by choosing the lexicographically smallest result.Hard8Dynamic programmingString+2No attempts yet2s128 MBJudgeable
Tree InsertionsCount how many permutations of a given sequence build the same binary search tree; values may repeat and answers need big integers.Hard8TreeCombinatorics+2No attempts yet1s128 MBJudgeable
Money Money Money, Must Be FunnyGiven limited cash held by a customer and a shopkeeper, find the minimum number of coins and notes that must change hands to settle an exact amount.Hard8Dynamic programmingGreedy+1No attempts yet1s256 MBJudgeable
Failing RoadsGiven an expression tree of merge and complement operations, compute the maximum independent set of the resulting graph.Hard8TreeDynamic programming+2No attempts yet1s128 MBJudgeable
Go EndgameGiven starting scores, region values, and sente flags, compute the final scores when Alice and Bob alternately pick regions and respond until all are settled.Hard8Dynamic programmingGame theory+2No attempts yet1s128 MBJudgeable
Base NumbersFor each digit string, count the ways to insert parentheses and dashes so it decodes to a valid decimal-encoded number in some base greater than 1.Hard8Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Software CompanyAssign m subprojects of each of two projects to n employees, who work sequentially, to minimize the largest total working time.Hard8Binary searchGreedy+2No attempts yet1s128 MBJudgeable
The Winds of WarChoose a convex net containing the origin that covers as many enemy units as possible while covering as few friendly ones, and report the maximum difference.Hard8GeometrySorting+2No attempts yet2s512 MBJudgeable
SwitchGiven a row of K lights with no four consecutive on, find the fewest off-to-on switches needed so that all lights end up off, given the automatic clearing of any block of four or more on.Hard8Dynamic programmingGreedy+1No attempts yet2s512 MBJudgeable
Fixing DisksGiven a master stack and your own stack of N labeled disks, use three limited reorder moves on the top K disks to remove disks cheaply; minimize total cost under a removal-order constraint.Hard8Dynamic programmingStack+2No attempts yet2s512 MBJudgeable
Nutrient TreeGiven a binary tree whose leaves produce nutrients and whose edges have capacity (1+w)^2 after spending w agents, distribute X agents over edges and leaves to maximize the flow reaching the root.Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
A Weighty ProblemChoose which coins to hand over for a purchase so that the total weight of unspent coins plus the store's greedy change is minimized.Hard8Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
GerrymanderingMerge adjacent ridings into blocks so Party 1 strictly wins a majority of the remaining ridings, minimizing the number of merges.Hard8Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
OrkoGiven ten cards for player A and the rest for B, compute how many of the ten rounds A wins when both play optimally, with A leading first.Hard8Game theoryBacktracking+2No attempts yet1s128 MBJudgeable
PartitionsGiven k and a, output the a-th partition of k in lexicographic order, or Too big when a exceeds the partition count.Hard8Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Ransom NoteGiven a target note and a newspaper text, find the minimum number of contiguous clips (letters and spaces only, case-insensitive, reusable) needed to paste the note.Hard8Dynamic programmingString+2No attempts yet1s128 MBJudgeable
The Game of 31Given a partly played game of 31 with four cards of each value 1 to 6, determine the winner under perfect play.Hard8Game theoryDynamic programming+2No attempts yet1s128 MBJudgeable
GradingGiven point values and a threshold K, find the smallest integer at least K that cannot be any total score over all correct/wrong answer patterns.Hard8Dynamic programmingNumber theory+2No attempts yet2s128 MBJudgeable
Railway ConnectionFind the cheapest route from station s to g in a multigraph where each maximal run of same-company edges is priced by that company's piecewise linear, concave fare table.Hard8GraphShortest path+2No attempts yet1s128 MBJudgeable
Cow Ski AreaBuild the directed graph where each square has edges to same-or-lower neighbors, then find the minimum number of bidirectional edges to add so the whole graph becomes strongly connected.Hard8GraphDFS+2No attempts yet1s128 MBJudgeable
SweetsCount the ways to take up to m_i candies from each of n jars so the total is between a and b, modulo 2004.Hard8Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Bugs Integrated, Inc.Given a grid with some blocked cells, find the maximum number of 2x3 or 3x2 non-overlapping rectangles that fit on good cells.Hard8Dynamic programmingBit manipulationNo attempts yet15s128 MBJudgeable
Sevens, Twos and ZerosFind the smallest multiple of n that is at least n, uses only digits 7, 2, 0, and has at most 20 digits, or report NAV.Hard8BFSDynamic programming+2No attempts yet1s128 MBJudgeable
TollA billionaire sets tolls on K new roads of his choosing so that the minimum spanning tree routing all traffic to town 1 maximizes his revenue, where K is at most 20.Hard8Minimum spanning treeGreedy+2No attempts yet3s128 MBJudgeable
Flooding FieldsGiven an n by n grid, k cows, and h hourly flood levels, find the maximum number of cows that can survive by moving each hour before the water rises.Hard8Dynamic programmingGraph+2No attempts yet1s512 MBJudgeable
FootballSplit a row of N player skills into K consecutive segments of at least M each so that the minimum segment average is maximized, and print that value as a reduced fraction.Hard8Binary searchDynamic programming+2No attempts yet1s1024 MBJudgeable
The Palindromes Strike BackFor every position i, count the subsets of positions that include i and form a palindrome, then XOR all i times that count mod 1e9+7.Hard8Dynamic programmingCombinatorics+2No attempts yet2s1024 MBJudgeable
Dorm PartyGiven a bipartite interest graph, pick a minimum set of edges to dance so that no edge joins two undanced vertices.Hard8GraphDynamic programming+2No attempts yet15s1024 MBJudgeable
Address MatchingMatch each student address to a distinct teacher address with minimum total weighted edit distance, and among optimal matchings output the lexicographically smallest index sequence.Hard8Dynamic programmingGreedy+2No attempts yet3s1024 MBJudgeable
Electric CarFind the minimum total time to drive from city 1 to city N, where each road costs 1 hour and L energy, and charging takes whole hours at rate c_i per city.Hard8GraphShortest path+2No attempts yet1s1024 MBJudgeable
Transformation from OneStarting from 1, you may add 1 to the first or last digit for cost 1, or multiply it by 2..9 for cost 2; find the minimum cost to reach each given number, or -1.Hard8BacktrackingBFS+2No attempts yet1s1024 MBJudgeable
Coat RackSort garments and targets; sliding garments keeps their order and may stack them, so assign each target to a position minimizing total distance under order constraints.Hard8Dynamic programmingDivide and conquer+2No attempts yet1s1024 MBJudgeable
ThievesGiven a tree with K robbed cities, block some cities at cost a_i so that the reachable set of cities from the robbed nodes through unblocked cities is minimized in total cost (blocking plus M per searched city).Hard8TreeDynamic programming+2No attempts yet1s1024 MBJudgeable
KortosCount the distinct ordered piles a player can build from N distinct cards where each new card matches the top card's number, or matches its suit with a larger number, modulo 1e9+7.Hard8Dynamic programmingCombinatorics+2No attempts yet2s1024 MBJudgeable
BouquetCount distinct flower sequences a robot can collect moving left, right, or down, picking at least one flower per floor, modulo 1e9+7.Hard8Dynamic programmingCombinatoricsNo attempts yet1s1024 MBJudgeable
ASMFind the fewest add/multiply/print commands in a one-variable program whose printed concatenation matches every test's required output.Hard8Brute forceDynamic programming+2No attempts yet1s1024 MBJudgeable
Color TunnelsGiven a color sequence and colored line-segment tunnels, find the shortest path from source to destination that traverses tunnels in the required color order.Hard8GeometryShortest path+1No attempts yet1s128 MBJudgeable
Painting a BoardGiven up to 15 rectangles with colors and vertical precedence constraints, find the minimum number of brush pick-ups to paint every rectangle.Hard8Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Crossed MatchingsGiven two rows of positive integers, draw the maximum number of equal-value matching segments between the rows so that each segment crosses exactly one other and no number is used twice.Hard8Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Magazine DeliveryThree cars start at L1 and must deliver to locations in strict order 2,3,...,N, with only one car moving at a time; minimize the total completion time.Hard8Dynamic programmingShortest path+2No attempts yet1s128 MBJudgeable
Order of TreesGiven n, print the n-th binary tree under a canonical ordering by node count and by (left subtree number, right subtree number) recursively.Hard8CombinatoricsDynamic programming+2No attempts yet1s128 MBJudgeable
Word EncodingGiven up to 1000 forbidden substrings of length 1 to 3, rank valid words by length then alphabetically; answer queries converting a word to its index and an index to its word.Hard8Dynamic programmingString matching+2No attempts yet1s128 MBJudgeable
Bring Them ThereFind the minimum number of days to send K ships from S to T through an undirected graph where each edge carries at most one ship per day.Hard8GraphBFS+2No attempts yet2s128 MBJudgeable
Farmer Bill's ProblemPlace non-overlapping, non-touching rectangles inside a rectangular field so all given circles lie within them, minimizing total rectangle area, and output the remaining harvestable area.Hard8GeometryDynamic programming+2No attempts yet2s128 MBJudgeable
FrontierChoose a subset of the polygon's vertices, in clockwise order, forming a convex polygon that strictly contains all given points, minimizing its perimeter.Hard8GeometryDynamic programming+2No attempts yet1s128 MBJudgeable
Incredible! Impossible!Count n by 3 tables of non-negative integers with given row sums and column sums, modulo 10 to the 17.Hard8Dynamic programmingCombinatorics+2No attempts yet2s64 MBJudgeable
Experiment "X": Explosions ExpectedCount valid mixtures (at most S total ounces, at least two ingredients used) that are not dominated coordinatewise by any of M given exploding mixtures, modulo nothing.Hard8CombinatoricsDynamic programming+2No attempts yet1s512 MBJudgeable
PlatformsGiven points with distinct x, find the longest chain of flights where each next point has larger x and no larger y, then report every point lying on some longest chain.Hard8Dynamic programmingSorting+2No attempts yet2s128 MBJudgeable
Lucky TicketsCount lucky n-digit numbers among k consecutive values starting at a uniformly random s in [a,b], and print the expected count as a fraction.Hard8Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Robotic InvasionEdit as few commands as possible in a movement string so the robot reaches a trap, breaking ties by earliest capture and then lexicographic order.Hard8BFSDynamic programming+2No attempts yet1s128 MBJudgeable
DNA LaboratoryGiven up to 15 DNA strings, find the shortest string that contains all of them as substrings, breaking ties by lexicographic order.Hard8Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Missing LettersReconstruct a space-free corrupted string into words from a known vocabulary, choosing the highest-scoring word segmentation and breaking ties alphabetically.Hard8Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Jury CompromisePick exactly m candidates minimizing the prosecution minus defence imbalance, breaking ties by the largest total value, then by lexicographically smallest candidate list.Hard8Dynamic programmingSorting+1No attempts yet1s128 MBJudgeable
Tree SimilarityGiven two ordered rooted trees, find the minimum number of node relabel, delete, and insert operations to turn the first tree into the second.Hard8Dynamic programmingTree+2No attempts yet3s128 MBJudgeable
Drunken WalkIn a weighted DAG, remove at most one edge to maximize the expected number of edges walked from vertex 0 before reaching a sink.Hard8GraphDynamic programming+2No attempts yet2s512 MBJudgeable
Rectangles Too!Find the longest chain of rectangles where each rectangle lies strictly below and to the left of the next one.Hard8SortingDynamic programming+1No attempts yet3s128 MBJudgeable
Globulous GumdropsGiven spheres of radii r_i and a tube of diameter d, find the shortest cylinder length holding them all.Hard8GeometryDynamic programming+2No attempts yet1s128 MBJudgeable
CensorshipGiven a text and a filter word set, remove occurrences repeatedly to make the shortest possible result and report its length.Hard8Dynamic programmingString+1No attempts yet1s128 MBJudgeable
RSI: Two-Finger Numeric TypingGiven a digit string, type it on a two-finger keypad in the fewest time units, keeping the left finger always in a strictly smaller column than the right.Hard8Dynamic programmingNo attempts yet1s128 MBJudgeable
Vigenère CipherGiven a ciphertext and pair frequencies, find the key length-K shift maximizing the total frequency of adjacent plaintext letter pairs.Hard8Dynamic programmingString+1No attempts yet5s64 MBJudgeable
ByephoneFind the longest common subsequence of two strings up to length 10000 within 3MB of memory, breaking ties by the lexicographically smallest result.Hard8Dynamic programmingString+2No attempts yet2s3 MBJudgeable
NecklaceGiven a target cyclic bead order and a removal order from a pin, minimize the largest number of beads held aside while building the necklace from both ends.Hard8Dynamic programmingGreedyNo attempts yet1s16 MBJudgeable
EncodingFind the shortest encoding length for a target string under dynamic coding, where a changing marker toggles between verbatim and interpreted modes.Hard8Dynamic programmingStringNo attempts yet1s128 MBJudgeable
Increasing SubsequencesCount permutations of 1..N whose longest increasing subsequence has length exactly B, modulo 1,000,000,000.Hard8Dynamic programmingCombinatorics+1No attempts yet4s128 MBJudgeable
KBTU PartyCount the ways to choose r disjoint acquainted girl-boy pairs when girl j knows exactly the first 2j-1 boys, modulo 2946859.Hard8CombinatoricsDynamic programming+2No attempts yet2s128 MBJudgeable
Panda Land 5: Panda Programming LanguageReorder up to 18 functions to satisfy call-before-use ordering, minimizing a move cost weighted by line counts, or report impossibility.Hard8Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Counting BSTCount insertion sequences of distinct values from 1..M that build a BST with the same shape as a given sequence, modulo 1000003.Hard8CombinatoricsTree+2No attempts yet1s128 MBJudgeable
Fire DrillPlan rescues in a multi-floor grid so the total points collected within the time limit is maximized, where a laden move costs double.Hard8Dynamic programmingGraph+1No attempts yet1s128 MBJudgeable
Harder Sokoban ProblemChoose player and container start cells to maximize the minimum Sokoban moves needed to push the container onto the single destination cell.Hard8BFSGraph+2No attempts yet5s128 MBJudgeable
GarlandsSplit a weighted sequence of n pieces into m segments of even length, each half-segment at most d pieces, minimizing the maximum half-segment weight.Hard8Binary searchDynamic programming+2No attempts yet2s512 MBJudgeable
Prison rearrangementGiven a bipartite conflict graph between two prisons of size m, find the largest k <= m/2 so that k prisoners can be swapped across while keeping every conflicting pair apart.Hard8GraphBFS+2No attempts yet1s128 MBJudgeable
The PicnicGiven up to 99 points, find the largest convex polygon whose vertices are points and whose interior contains no other point.Hard8GeometryDynamic programming+2No attempts yet1s128 MBJudgeable
Arithmetic RectangleGiven an n by m grid of integers, find the largest rectangle in which every row and every column forms an arithmetic sequence, and output its area in unit squares.Hard8Dynamic programmingArray+2No attempts yet3s128 MBJudgeable
Bytean Road RaceGiven a planar south/east DAG from node 1 to node n, answer queries asking whether some monotone path passes through both given crossings.Hard8GraphDFS+2No attempts yet3s64 MBJudgeable
CaveGiven a tree of n nodes, find every k such that the tree splits into k connected parts of equal size.Hard8TreeDFS+2No attempts yet3s256 MBJudgeable
FirefighterOn a graph with max degree 3, fire spreads one step per hour while one house can be protected each hour; maximize houses kept safe.Hard8GraphTree+2No attempts yet1s128 MBJudgeable
TetrisCount ways to fully tile a 4-by-n board with seven Tetris pieces (long piece has 3 cells), given some cells of the first row already covered, modulo 10^6.Hard8Dynamic programmingMatrix+2No attempts yet1s128 MBJudgeable
Vending MachineGiven snack prices, stocks, and a budget, choose purchases so that each buy also dispenses one free snack of every cheaper kind still in stock, maximizing total value received.Hard8Dynamic programmingGreedyNo attempts yet1s128 MBJudgeable
Shut Down the MachinesGiven devices that either shut down alone with a strong shock or reactivate a multiset of other devices with a cheaper weak shock, find the minimum total power, counting each activation separately.Hard8Dynamic programmingGraph+1No attempts yet1s256 MBJudgeable
Catching MolesChoose at most k holes to shoot on a circle; each shot removes the target's moles and pushes neighbors' moles outward, maximizing the total removed.Hard8Dynamic programmingGreedy+2No attempts yet1s256 MBJudgeable
C-algaeDecide whether each given undirected graph can be built from single vertices by disjoint union and complete join.Hard8GraphDivide and conquer+2No attempts yet3s128 MBJudgeable
Numerals of the PrzesmyksConvert numerals over {- , +} with at most m1 consecutive minuses into their rank-ordered representation under the bound m2.Hard8CombinatoricsMath+2No attempts yet1s128 MBJudgeable