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
Magical CraftingGiven binary crafting recipes with diamond costs, decide for each target string of glow stones whether it can be produced from 'A' and find the minimum diamond cost.Hard8Dynamic programmingGreedy+2No attempts yet5s128 MBJudgeable
Disjoint Regular ExpressionsGiven two regular expressions, decide whether any non-empty string matches both, and if so print the shortest lexicographically smallest such string.Hard8Dynamic programmingBFS+2No attempts yet2s128 MBJudgeable
The Great TricksterCount integers from 0 to n whose base-k and base(-k) representations are identical, with n up to 10^15 and k up to 1000.Hard8MathNumber theory+2No attempts yet1s128 MBJudgeable
CommandoPartition soldiers into consecutive blocks, each block's score is a concave quadratic of its sum, and maximize the total score.Hard8Dynamic programmingDivide and conquer+2No attempts yet1s64 MBJudgeable
PatrolBuild K (1 or 2) unit-length shortcuts in a tree so that the shortest closed walk from village 1 covering every edge exactly as required is minimized.Hard8TreeDynamic programming+2No attempts yet1s64 MBJudgeable
Digging for OilPlace three non-overlapping K by K squares on an M by N grid of oil estimates to maximize the total sum covered, with the grid up to 1500 by 1500.Hard8Prefix sumDynamic programming+2No attempts yet2s128 MBJudgeable
ATMGiven a directed graph with cash at each node, find the maximum total cash collectible on a walk from a start node to any restaurant, counting each node once.Hard8GraphShortest path+2No attempts yet2s512 MBJudgeable
Have You Driven a Fjord Lately?Choose integer-length bridges across fjords, each spanning one fjord, to maximize road length saved while total bridge length stays within m.Hard8GeometryDynamic programming+2No attempts yet5s128 MBJudgeable
Target PracticeGiven n points in 3D, find the minimum number of straight lines needed to cover all of them.Hard8GeometryDynamic programming+1No attempts yet1s128 MBJudgeable
Teleport Out!Grid maze with exits; each step you either walk to an adjacent open cell or teleport to a uniformly random open cell. Find the minimum expected number of steps to reach an exit.Hard8Dynamic programmingBFS+2No attempts yet1s128 MBJudgeable
WormsGiven string rewriting rules, find the minimum number of days to grow the target worm from one cell, where each day any subset of cells splits.Hard8Dynamic programmingIntervals+1No attempts yet2s128 MBJudgeable
Paper RouteWith N+1 nodes and exactly N roads, find the cheapest closed walk from node 0 covering all addresses, then add the campus travel cost from wherever you end.Hard8GraphDFS+2No attempts yet1s128 MBJudgeable
DivorcePick two disjoint subsets of up to 24 houses with equal sums, maximizing that common sum, and report the value of the houses left out.Hard8Dynamic programmingBit manipulation+2No attempts yet30s128 MBJudgeable
Stack MachineFor each pair of intersections, find the shortest route whose sequence of board and leave events forms a balanced stack (empty at start and end).Hard8GraphShortest path+2No attempts yet1s128 MBJudgeable
Rotate to RootGiven a binary tree, compute the height of the tree after each node is rotated to the root one at a time.Hard8TreeDFS+2No attempts yet1s128 MBJudgeable
Rocket StagesChoose a subsequence of stages, in order, with total mass at most 10000 kg and never negative net acceleration, to maximize the final burnout velocity.Hard8Dynamic programmingMath+2No attempts yet1s128 MBJudgeable
Bus Driver SeungjaeGiven a graph with hotels, a start, and a sightseeing spot, find the shortest closed route that picks up and drops off each hotel while keeping half of the drop-offs within the first half of pick-ups.Hard8GraphShortest path+2No attempts yet3s128 MBJudgeable
Fibonacci WordGiven a bit pattern p and an index n up to 100, count the possibly overlapping occurrences of p inside the Fibonacci word F(n), whose length grows exponentially.Hard8String matchingDynamic programming+2No attempts yet1s128 MBJudgeable
Robot VacuumGiven a convex polygon and an interior start point, find the shortest closed route that touches (or bumps into) every edge and returns to the start.Hard8GeometryGreedy+2No attempts yet5s128 MBJudgeable
Chip DesignPlace the most widgets on an N x N chip so row counts equal column counts and no row or column exceeds A/B of the total parts.Hard8Dynamic programmingGreedy+2No attempts yet10s128 MBJudgeable
Machine WorksBuy and resell at most one machine at a time over D days, each machine usable from its sale day, to maximize final cash.Hard8Dynamic programmingSorting+2No attempts yet2s128 MBJudgeable
Magic SticksSplit a chain of segments into disjoint runs of consecutive segments, close each run into a cyclic polygon, and maximize the total area, where each polygon's best area is the cyclic one.Hard8Dynamic programmingGeometry+2No attempts yet8s128 MBJudgeable
PyramidsGiven a count of stones, find the smallest set of distinct high or low pyramids (height at least 2) that uses every stone, breaking ties by maximizing sizes lexicographically, or report impossible.Hard8Dynamic programmingGreedy+2No attempts yet5s512 MBJudgeable
GangsRank all lattice paths of E and S steps from (1,1) to the diagonal at (N,N) by a recursive 'OG' order, and output the run at rank M or ERROR.Hard8CombinatoricsDynamic programming+2No attempts yet1s128 MBJudgeable
CarpoolSplit n people into the fewest 5-seat cars, route each car through its passengers' errand stops, and minimize the maximum car travel time.Hard8GraphShortest path+2No attempts yet1s128 MBJudgeable
A Brief GerrymanderChoose A avenue boundaries including 1 and 100 to maximize the number of vertical strips that contain at least one marked neighborhood, given fixed street boundaries.Hard8Dynamic programmingSorting+1No attempts yet1s128 MBJudgeable
Jogging TrailsFind the shortest closed walk that traverses every undirected weighted edge at least once, where the walk may start at any vertex.Hard8GraphShortest path+2No attempts yet1s128 MBJudgeable
Snow ClearingFind the minimum time to plow every directed lane of a city's two-way streets and return to the hangar, given faster travel on already-cleared lanes.Hard8GraphShortest path+2No attempts yet1s128 MBJudgeable
Saruman's Level UpFor each N up to 10^16, count how many integers i in [1, N] have a binary digit sum that is a multiple of 3.Hard8Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Tile CutGiven a grid of W, I, N letters, find the maximum number of disjoint straight or L-shaped triominoes spelling WIN.Hard8GraphDynamic programming+2No attempts yet1s128 MBJudgeable
Zombie SwallowsFor each of up to 30 swallows, decide whether some subset of up to 150 insect weights sums to a value in the range [Cmin, Cmax].Hard8Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Spare the Ewoks!Given an m by n grid with blocked cells, choose up to three non-overlapping axis-aligned rectangles to maximize the total covered area.Hard8Dynamic programmingPrefix sum+1No attempts yet3s128 MBJudgeable
Power GridCount the minimum-size edge sets connecting all living quarters to the power station on an 8x8 grid, modulo 1e9.Hard8Dynamic programmingGraph+2No attempts yet1s128 MBJudgeable
Optimal Strategy for the ICPCGiven up to 15 problem solving times, schedule them on three parallel workers within 300 minutes to maximize solved count, then minimize total completion-time penalty, with lexicographically smallest order.Hard8Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Cover UpGiven up to 5000 boards, each with d columns of distinct digits, compute the probability the contestant eventually wins Cover Up, assuming uniform random picks among untried digits in unfinished columns.Hard8ProbabilityDynamic programming+2No attempts yet1s128 MBJudgeable
Operation: Merchant BoorineiGiven moving vessels and a faster sleigh that spends one hour unloading at each, find the minimum time to visit every vessel and return to the start.Hard8Dynamic programmingGeometry+2No attempts yet1s128 MBJudgeable
Panic RoomGiven a house of rooms with directed doors, intruder positions, and a panic room, find the minimum number of doors to lock so no intruder reaches it, or report impossible.Hard8GraphMinimum spanning tree+2No attempts yet1s128 MBJudgeable
The Mark of a WizardOn a small DAG, find the shortest path from A to F and the fewest intersections to mark so that following marks still guarantees the shortest time.Hard8GraphShortest path+2No attempts yet1s128 MBJudgeable
Quick SearchGiven a small graph and k officers all starting at A, find the minimum time for the officers to jointly visit every node, where each officer walks a path.Hard8GraphDynamic programming+1No attempts yet1s128 MBJudgeable
GHOSTGiven a GHOST position and dictionary, decide whether the computer should challenge, add the smallest safe letter, or bluff.Hard8Game theoryTrie+2No attempts yet1s128 MBJudgeable
Unhappy NumbersCount numbers in [lo, hi] that never reach 1 under the digit-square-sum map; bounds go up to 1e18 so answers need digit DP over precomputed unhappy states.Hard8MathDynamic programming+2No attempts yet1s128 MBJudgeable
Sloppy SortGiven a possibly inconsistent comparison function as an n by n table, find the permutation of 0 to n-1 with the fewest inversions, breaking ties by the lexicographically smallest one.Hard8Dynamic programmingBit manipulation+2No attempts yet3s128 MBJudgeable
Function OverloadingParse nested overloaded function calls; for each, determine whether resolution is unique, impossible, or ambiguous, counting ambiguity cases up to 1000.Hard8Dynamic programmingImplementation+2No attempts yet2s128 MBJudgeable
Pattern MatchingDecide whether digit sequences match patterns where digits match exactly and * and # stand for even and odd counts of arbitrary digits.Hard8Dynamic programmingString matchingNo attempts yet1s128 MBJudgeable
City MergerGiven up to 14 uppercase city names, find the length of the shortest string that contains every name as a consecutive substring, allowing overlaps.Hard8Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
Captain Q's TreasureGiven a grid with at most 15 digit cells, each stating how many chests lie in its 3x3 neighborhood, find the minimum number of chests consistent with all digits.Hard8BacktrackingBrute force+2No attempts yet3s128 MBJudgeable
Private SpaceChoose the smallest widest row width X (at most 12) so that all groups fit into triangular rows of widths X down to 1, keeping one empty seat between neighboring groups in a row.Hard8Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Borg BoogieGiven a connected undirected graph and a fixed walk, find the probability that a random-walking sentry never collides or swaps with the captain during the walk.Hard8Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
Code PermutationsCount permutations of 1..N whose order (LCM of cycle lengths) equals K, modulo 2^31-1.Hard8CombinatoricsDynamic programming+2No attempts yet2s128 MBJudgeable
DNA CopyGiven a source string S of length at most 18, find the minimum number of copy operations (each taking a contiguous substring of S or of the already-built target, optionally reversed) needed to assemble T.Hard8Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Circle of DebtGiven three people's debts and the exact bills and coins each holds, find the minimum number of pieces that must change hands to settle all debts.Hard8Dynamic programmingBacktracking+2No attempts yet1s128 MBJudgeable
Different DigitsFor each n below 65536, find the smallest positive multiple of n whose decimal form uses the fewest distinct digits.Hard8BFSDynamic programming+2No attempts yet1s128 MBJudgeable
Lego Brick WallsDecide whether a rectangular wall can be tiled with given bricks of widths 1 to 3, respecting fixed bricks and the rule that joints in adjacent rows never align, given brick counts.Hard8Dynamic programmingBacktracking+1No attempts yet1s128 MBJudgeable
Packages Par AvionProcess parcels arriving at airport 0, route each to its destination with a shortest-hop tie-break, then fill departing planes by 0/1 knapsack and report each flight's loaded value.Hard8GraphShortest path+2No attempts yet1s128 MBJudgeable
Safety PrecautionsGiven a DAG where each node fails only after at least t dependencies have failed, choose nodes to protect so node n never fails, minimizing protection cost.Hard8Dynamic programmingGraph+2No attempts yet1s128 MBJudgeable
Stock TradingGiven known daily prices for n stocks over D days, starting capital C, and at most t buy or sell actions, maximize final cash.Hard8Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Game of StonesGiven a directed acyclic graph with stones on nodes, two players alternately slide one stone along an edge; decide whether the first player wins.Hard8Game theoryGraph+2No attempts yet1s128 MBJudgeable
Grid NimTwo players alternately remove a heap from either end of a row; a player cannot take three heaps in a row on their own turns, and the first player wins if their coin total is at least the second player's.Hard8Game theoryDynamic programming+2No attempts yet1s128 MBJudgeable
Shortest PathsFor each edge on a given shortest a-b path, report the length of the shortest a-b route that avoids that edge.Hard8Shortest pathGraph+2No attempts yet1s128 MBJudgeable
The Best TeamsGiven N players each with an age and distinct skill, and forbidden pairs that are adjacent in skill order, answer T queries each asking the maximum sum of at most K players with age at most A.Hard8Dynamic programmingSorting+2No attempts yet2s128 MBJudgeable
HeritageDivide a region under a polygonal line into parcels whose areas match given ratios, choosing vertical cuts that minimize the total fence length.Hard8Dynamic programmingGeometry+2No attempts yet0.3s64 MBJudgeable
Strange DreamCount ways to pick plates from boxes in a forward then backward pass so the recorded product is divisible by k, modulo l.Hard8Dynamic programmingNumber theory+1No attempts yet1s128 MBJudgeable
The Stairways of SaharnaSplit a sequence into k disjoint non-decreasing subsequences to maximize the total number of chosen elements, and output this maximum for every k up to the point where all n elements are used.Hard8Dynamic programmingGreedy+2No attempts yet0.2s128 MBJudgeable
The Twin TowerCount perfect matchings of a 3x3xN grid graph where each of the 9N rooms pairs with an adjacent room, modulo 10007.Hard8Dynamic programmingBit manipulation+2No attempts yet1s256 MBJudgeable
BlackjackGiven the exact order of the remaining deck, decide which hands to play, how much to bet, and when to hit or stand, to maximize total profit.Hard8Dynamic programmingGame theory+2No attempts yet1s128 MBJudgeable
Shepherds and EngineersGiven s sheep needed in town after b bridges whose tolls follow a strict divisibility rule, find the minimum starting number of sheep.Hard8Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Another Dice GameCompute the probability that Jan reaches a target score of n in Pickomino with optimal play, given the dice, set-aside and worm rules.Hard8Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
Good CoalitionEach party has seats and a survival probability; find the party subset holding at least 76 seats whose product of probabilities is maximized, and print it as a percentage.Hard8Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
BancopiaPlace up to m police posts, each halving one road's robbery probability, so that the safest a-to-b route has the smallest possible robbery probability.Hard8GraphShortest path+2No attempts yet1s128 MBJudgeable
FishGiven fish lengths and gem kinds, count how many distinct gem-count combinations a single fish can ever hold, modulo M, where a fish can eat another only if at least twice as long.Hard8Dynamic programmingSorting+2No attempts yet3s128 MBJudgeable
Balanced Garden in a RowCount balanced binary strings of length N whose every substring has at most two more L than P, and find the lexicographic rank of a given string modulo M.Hard8Dynamic programmingCombinatorics+2No attempts yet2s128 MBJudgeable
Sabotaging the Marathon TrainingGiven a spanning tree of paved edges plus weighted unpaved edges, delete cheap unpaved edges so that no even-length simple cycle remains.Hard8GraphDynamic programming+2No attempts yet1s128 MBJudgeable
TwofiveMap between a valid 5x5 standard Young tableau word and its rank, the count of valid words lexicographically before it.Hard8CombinatoricsDynamic programming+1No attempts yet1s128 MBJudgeable
DepotGiven the final row placement produced by the depot insertion rule, count how many arrival orders of the containers could have produced it.Hard8Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
PolygonRemove one edge of a polygon, then repeatedly merge adjacent vertices by the intervening + or *, and report the maximum final value plus every edge whose removal reaches it.Hard8Dynamic programmingIntervals+2No attempts yet1s128 MBJudgeable
Souvenir Shopping Plan (Gifts)On an H by W grid with blocked houses, move from the top-left to the bottom-right, taking at most K steps north or west, and maximize the number of distinct souvenir shops visited.Hard8Dynamic programmingMatrix+1No attempts yet15s128 MBJudgeable
Zigzag NumbersCount numbers in [A, B], up to 500 digits, that are divisible by M and whose adjacent digit comparisons alternate up then down.Hard8Dynamic programmingMath+2No attempts yet2s128 MBJudgeable
Bingo GameCount N x N grids with distinct values from 1 to M, columns increasing downward, each column larger than all columns to its left, and total sum S, modulo 100000.Hard8Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Moving Cups Across Three TraysCups of sizes 1..n sit stacked (largest on top) on three trays; with moves allowed only between A-B and B-C, find the minimum number of moves to gather every cup onto A or C, or report -1 if more than m are needed.Hard8BFSDynamic programming+2No attempts yet1s128 MBJudgeable
AltarCount the sequences of nonnegative column heights reachable by repeatedly raising the interior of any equal-height range by 1, matching known heights where not stolen (-1).Hard8Dynamic programmingCombinatorics+2No attempts yet1s256 MBJudgeable
Ultimate DeviceEach of n distinct cycle lengths is chosen by a fair coin; find the expected LCM of the chosen subset, output as (r * 2^n) mod 10007 or "not integer".Hard8Dynamic programmingMath+2No attempts yet10s128 MBJudgeable
Spelling SuggestionGiven weighted edit costs including keyboard-aware substitution and transposition, find the dictionary words closest to each query word.Hard8Dynamic programmingString+2No attempts yet12s128 MBJudgeable
Tree PathGiven a directed tree, find the minimum number of reversed-edge paths to add so that every node can reach every other node.Hard8TreeGraph+2No attempts yet1s128 MBJudgeable
Totally Important EdgesGiven a directed flow network, count the edges whose capacity decrease by 1 lowers the maximum flow by exactly 1.Hard8GraphShortest path+1No attempts yet1s256 MBJudgeable
Highway PatrolChoose a subset of directed edges to patrol, containing all forced edges and at least one edge, with equal patrolled in-degree and out-degree at every vertex, minimizing total patrol plus surveillance cost.Hard8GraphDynamic programming+2No attempts yet1s128 MBJudgeable
Boxes and StonesCount the initial distributions of S indistinguishable stones among the first B-1 boxes from which Carole, moving second each round, can force a win against Paul.Hard8Game theoryCombinatorics+2No attempts yet1s128 MBJudgeable
Game of TilesTwo players alternately extend a path of numbered tiles on a grid with blocked cells; the player unable to move loses. Determine the winner under optimal play.Hard8GraphGame theory+2No attempts yet1s128 MBJudgeable
Code LockGiven a target lowercase string starting from all 'a', find the minimum number of moves where each move shifts a contiguous block of wheels up or down by one.Hard8Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
GrapevineGiven a monotone matrix of heights and height-interval queries, find for each query the largest square submatrix whose heights all fall in the interval.Hard8Binary searchDynamic programming+2No attempts yet1s128 MBJudgeable
DNA SubsequenceFind the longest common subsequence of two words where every maximal matched run must be a contiguous block of at least K characters in both words.Hard8Dynamic programmingString+1No attempts yet1s128 MBJudgeable
Power GenerationBuild the tree formed by attaching each new plant to the nearest older one, then split it into the most connected subtrees each having total capacity at least C.Hard8TreeDynamic programming+2No attempts yet3s128 MBJudgeable
Optical FiberGiven a tree of cities, each with up to 50 candidate router sites, pick one site per city to minimize the sum of Euclidean edge lengths.Hard8Dynamic programmingTree+2No attempts yet1s128 MBJudgeable
Kryptonite MineFind the route from start to exit that minimizes walking distance, using at most N teleports between booths that share an unobstructed line of sight.Hard8GeometryGraph+2No attempts yet1s128 MBJudgeable
Monkey BusinessCount the ways to distribute exactly B fruits and vegetables among G groups so each group satisfies the per-group rules and totals, modulo a prime.Hard8Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
The Crocodile's Underground CityFind the minimum guaranteed escape time from room 0 to any exit room when a gatekeeper blocks one corridor at each room before Chulsoo moves.Hard8GraphShortest path+2No attempts yet2s256 MBJudgeable
ElephantsAfter each of M moves that relocate one elephant, report the minimum number of length-L segments needed to cover all current positions.Hard8Segment treeDynamic programming+2No attempts yet12s256 MBJudgeable
PhotoGiven intervals each containing exactly one marked point, find the maximum number of marked points, or -1 if no assignment is consistent.Hard8Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Route DesignGiven two banks of valued sites and a set of non-crossing routes, find the maximum total value of a tour that alternates between banks without intersecting routes.Hard8Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
Gangs of CowstantinopleGiven gang sizes, decide if gang 1 can control the field at the end, and find the lexicographically earliest arrival order maximizing the surviving gang-1 cows.Hard8GreedyImplementation+2No attempts yet1s128 MBJudgeable
Balanced TreesGiven a tree whose nodes are labeled with parentheses, find the maximum nesting depth over all paths that spell a balanced parenthesis string.Hard8TreeDFS+2No attempts yet1s128 MBJudgeable