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,705 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Polly Wants a CrackerMatch each spoken word to a distinct original word minimizing total Levenshtein edit distance, and report that minimum sum.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Shuriken GameTwo players remove 1 to N shurikens from a pile, but a player cannot repeat the opponent's previous move; find the smallest winning first move.Medium7Dynamic programmingGame theory+1No attempts yet1s128 MBJudgeable
EvolutionGiven N DNA strings linked in an unknown parent-child order, compute each creature's probability of being the original ancestor.Medium7ProbabilityBit manipulation+1No attempts yet1s128 MBJudgeable
Serial NumberGiven distinct serial numbers and a modulus M, choose the largest subset whose sum is a multiple of M.Medium7Dynamic programmingNumber theoryNo attempts yet3s128 MBJudgeable
Flipping NetworksMaintain an undirected graph under edge toggle operations and count, after every flip, how many hosts are reachable from host 1 but only by paths longer than 10 hops.Medium7GraphBFS+2No attempts yet1s128 MBJudgeable
MondriaanGiven non-overlapping rectangles that tile a big rectangle, count the 3-colorings of the adjacency graph where orthogonally touching regions differ and white is a fourth free option.Medium7GeometryGraph+2No attempts yet1s128 MBJudgeable
Nim/3Three-player Nim where each player has a preferred winner; find player 1's optimal move with smallest stack then smallest count.Medium7Game theoryDynamic programming+2No attempts yet1s128 MBJudgeable
MerchantChoose a subset of markets to visit in nondecreasing opening-day order along a river, starting and ending at home, to maximize profits minus asymmetric upstream/downstream fuel costs.Medium7Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
MinersAssign each of N shipments in order to one of two mines; each shipment scores 1 to 3 based on how many distinct kinds appear among it and the previous two shipments at that mine, and the goal is to maximize the total.Medium7Dynamic programmingString+1No attempts yet1s128 MBJudgeable
The Valley of MexicoGiven a graph on cities placed in convex position, find a crossing-free Hamiltonian path (visiting every vertex once) that is lexicographically smallest, or report none.Medium7GraphDynamic programming+2No attempts yet1s128 MBJudgeable
HermesHermes walks on an infinite grid and must, in order, reach either the row or the column of each given point, starting at the origin; find the minimum total travel distance.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Comparing CodeFind the longest run of HAL's lines that matches a run of RBN's lines up to injective variable renaming and swapping the two right-hand operands.Medium7String matchingHash map+1No attempts yet1s128 MBJudgeable
Post OfficePlace P post offices in some of V villages on a line so that the sum of each village's distance to its nearest post office is minimized.Medium7Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Run, IOI TrainDiscard a prefix from each of two I/O strings, then interleave the remaining fronts to build the longest alternating string that starts and ends with I.Medium7Dynamic programmingTwo pointers+2No attempts yet1s128 MBJudgeable
Night MarketChoose an increasing-index subset of stalls, each with a non-overlapping integer start time before T, so that no play interval strictly contains time S, maximizing total fun.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Airplane ParkingGiven N time intervals (arrival, departure), find the largest subset that can be scheduled in a stack, so planes leave in last-in first-out order.Medium7Dynamic programmingIntervals+2No attempts yet1s128 MBJudgeable
Your WaysCount monotone lattice paths from (0,0) to (W,H) modulo 2552 for K days, where each day blocks up to 100 unit street/avenue segments with no two blocked segments on a common monotone path.Medium7Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Arranging HeapsGiven N heaps at increasing positions with weights, merge them into exactly K heaps where each heap moves only downriver, minimizing total weight times distance moved.Medium7Dynamic programmingDivide and conquer+2No attempts yet2s128 MBJudgeable
String FarmGiven up to 10^4 strings, find the longest chain where each string is a contiguous substring of the next, all photos distinct.Medium7StringDynamic programming+2No attempts yet5s128 MBJudgeable
Hyperactive Boy GangsanCount minimal subsets of intervals that cover [0, M] with no redundant interval, modulo 10^8, over multiple test cases.Medium7Dynamic programmingIntervals+2No attempts yet1s128 MBJudgeable
Almost Shortest PathRemove every edge that lies on any shortest S to D path, then find the shortest remaining path from S to D, or report -1.Medium7Shortest pathGraph+1No attempts yet1s256 MBJudgeable
Candy Picking ContestChoose boxes in an M by N grid so no two chosen boxes touch vertically or horizontally, maximizing the total candies collected.Medium7Dynamic programmingGreedy+2No attempts yet1s256 MBJudgeable
Emoticons :-)Given a set of emoticon strings, replace the fewest characters with spaces across several text lines so that no emoticon appears consecutively in any line.Medium7String matchingDynamic programming+2No attempts yet1s128 MBJudgeable
Turkish RoulettePlace B ordered balls into B non-overlapping pairs of adjacent wheel slots to maximize the dealer's profit, where each ball's value is its number times the sum of its two slots.Medium7Dynamic programmingArray+2No attempts yet3s128 MBJudgeable
P-NetworksGiven a permutation of N wires, decide whether a p-network can realize it, and if so report the minimum number of strokes needed.Medium7Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Land Division TaxSplit a ring of N lots one at a time; each split costs F times the larger resulting piece. Find the minimum total tax.Medium7Dynamic programmingIntervals+2No attempts yet1s128 MBJudgeable
Two-Stacks SolitaireGiven a stock pile dealt in order, decide whether the top card can be moved to intermediate pile 1 or 2 or popped to the foundation so all cards end non-decreasing.Medium7Dynamic programmingStack+2No attempts yet1s128 MBJudgeable
Uncle Tom's Inherited LandGiven a grid where at most 50 squares are usable land and the rest are ponds, find the maximum number of 1x2 dominoes that tile the usable squares.Medium7GraphDynamic programming+2No attempts yet1s128 MBJudgeable
Help-or-elseChoose an ordered subset of people to help; the finish time of each helper accumulates, and unhelped people add a penalty, so find the largest feasible subset under budget K.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Oil SkimmingGiven an N by N grid of oil cells, choose as many non-overlapping horizontal or vertical adjacent pairs of oil cells as possible.Medium7GraphDynamic programming+2No attempts yet1s128 MBJudgeable
Parachute RingsProcess link operations on a growing undirected graph and, after each query, count the vertices whose removal leaves only paths (or nothing).Medium7GraphUnion-find+2No attempts yet3s128 MBJudgeable
The Cow RunCows sit at distinct positions on a line; John starts at 0, moves one unit per minute, and each cow costs one dollar per minute until reached. Minimize the sum of arrival times.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
NecklaceGiven a string and a pattern, delete the fewest characters so the pattern no longer appears as a contiguous substring.Medium7Dynamic programmingString matching+2No attempts yet1s128 MBJudgeable
BookshelfPartition the books, in order, into shelves of total width at most L to minimize the sum of each shelf's max height.Medium7Dynamic programmingSegment tree+1No attempts yet1s128 MBJudgeable
RelocationGiven an undirected weighted graph with up to 5 market towns, pick a non-market town as home and an order to visit all markets and return, minimizing total distance.Medium7Shortest pathGraph+2No attempts yet1s128 MBJudgeable
Threatening LetterGiven a newspaper string and a message, split the message into the fewest contiguous pieces, each of which appears somewhere in the newspaper. Output that minimum count.Medium7StringDynamic programming+2No attempts yet1s128 MBJudgeable
CowlphabetCount valid words over 52 letters with exactly U uppercase and L lowercase letters, given the allowed adjacent letter pairs, modulo 97654321.Medium7Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Generic Cow ProtestsCount the ways to split a sequence into contiguous groups so that every group sum is nonnegative, modulo 1,000,000,009.Medium7Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Tree DecorationPlace a minimum-cost number of ornaments on each node of a rooted tree so every subtree holds at least its required count, given per-node unit costs.Medium7TreeGreedy+2No attempts yet1s128 MBJudgeable
SolderingGiven a tree, cover its edges with paths (wires) that may meet at soldered points, minimizing the sum of squared path lengths.Medium7TreeDynamic programming+1No attempts yet2s128 MBJudgeable
Forgotten PasswordFind the lexicographically smallest length-L string that matches a pattern of known letters and '?' and can be written as a concatenation of given dictionary words.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Job HuntBessie earns at most D per city visit, travels free paths and paid flights, and can repeat cities; find the maximum total profit or -1 if unbounded.Medium7GraphShortest path+2No attempts yet1s128 MBJudgeable
Cheese TowersStack unlimited cheese blocks up to total height T; any block of height at least K crushes everything below it to 4/5 height, maximizing total value.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Toy ShoppingSelect three of N toys maximizing the sum of joy/price ratios, and output the total price plus the three indices sorted by ratio.Medium7SortingGreedy+1No attempts yet1s128 MBJudgeable
Cow PoliticsGiven a tree with each node belonging to one of K parties, find the diameter (greatest distance between any two nodes) of the nodes in each party.Medium7TreeDFS+2No attempts yet2s128 MBJudgeable
The Baric BovineChoose the smallest subset of N pressure readings so the total interpolation-style error stays within E, and report that size plus the least error for it.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Pumps and PipesPlace the fewest pumps along a 20 m per pipe water line so pressure stays within limits, choosing the lexicographically smallest position set.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
The LeprechaunGiven an N x N matrix on a torus, find the contiguous circular run along any row, column, or either diagonal with the largest sum.Medium7ArrayDynamic programming+2No attempts yet1s128 MBJudgeable
RestaurantSplit a sequence of N foods into consecutive groups, where a group costs the square of its number of distinct foods, and minimize the total cost.Medium7Dynamic programmingDivide and conquer+2No attempts yet1s128 MBJudgeable
Ski LessonsGiven ski lessons that overwrite Bessie's skill at fixed start times and slopes with skill and time costs, maximize the number of runs by time T.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Spreading Out the CowsPlace N cows into S stalls so adjacent gaps are D or D+1 with as many D as possible, minimizing total movement from given start positions.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Random WalkParse a small random program with procedures and threshold IF/GOTO or PROC commands, then compute each requested procedure's expected running time to three decimals.Medium7ProbabilityGraph+2No attempts yet1s128 MBJudgeable
Summing SumsEach round every cow replaces her number with the sum of the other cows' numbers mod 98765431; report the values after exactly T rounds.Medium7MathMatrix+2No attempts yet1s128 MBJudgeable
The Bovine Accordion and Banjo OrchestraChoose increasing pairs between two length-N sequences to maximize the sum of A_i*B_j minus the squared sums of each maximal block of unpaired elements on both sides.Medium7Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Cow JoggingGiven a DAG with edges pointing from higher to lower numbered nodes, report the K shortest path lengths from node N to node 1, with duplicates allowed.Medium7GraphDynamic programming+2No attempts yet1s128 MBJudgeable
Corn FieldsCount subsets of fertile cells in an M by N grid, M,N at most 12, with no two chosen cells sharing an edge, modulo 100000000.Medium7Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
The Fewest CoinsGiven coin denominations, bounded supplies that John holds, and unlimited shopkeeper change, find the minimum total number of coins exchanged so John pays at least T with exact change returned.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Problem SolvingGiven a monthly budget M and per-problem advance and completion payments, find the minimum number of months to solve all P problems in order, where each month spends at most the previous month's budget.Medium7Dynamic programmingGreedyNo attempts yet1s128 MBJudgeable
DiningEach cow likes certain foods and drinks, each item can go to one cow; maximize the number of cows that get a liked food and a liked drink.Medium7GraphDynamic programming+2No attempts yet1s128 MBJudgeable
Corrupted BSTGiven a binary tree with distinct integer keys, find the minimum number of node keys to change so the tree satisfies the BST ordering, keeping its shape fixed.Medium7TreeDynamic programming+2No attempts yet1s128 MBJudgeable
Islands and BridgesFind the maximum score of a Hamilton path on a graph where the score adds vertex values, edge products, and triangle products, and count how many paths achieve it.Medium7Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Palindrome-Free NumbersCount integers in [a, b] whose decimal representation has no palindromic substring of length 2 or more.Medium7Dynamic programmingImplementation+2No attempts yet1s128 MBJudgeable
VimGiven a string over a-j, find the minimum Vim keypresses (x, h, and f C) to delete every 'e' without touching other characters, starting with the cursor at index 0.Medium7Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
FamilyCompute the expected percentage of genes shared by pairs of monsters in a given family graph where each child inherits each gene from one parent at random.Medium7GraphDynamic programming+2No attempts yet1s128 MBJudgeable
Water Treatment PlantsFor each given number of cities NC, count the valid strings of V, <, and > that respect the pipe-sharing rules, where NC can reach 100.Medium7Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Fast FoodGiven sorted restaurant positions, choose k of them as depots to minimize the total distance from every restaurant to its nearest depot.Medium7Dynamic programmingDivide and conquer+2No attempts yet1s128 MBJudgeable
Single-Player GamesGiven mutually recursive game-tree definitions, find each identifier's expected score under uniform random play, or report it undefined when the game may never end.Medium7ProbabilityMath+2No attempts yet1s128 MBJudgeable
Number GameGiven the numbers still allowed by previous choices, list every move that leaves the opponent in a losing position, or report that none exists.Medium7Game theoryDynamic programming+2No attempts yet1s128 MBJudgeable
Formatting TextBreak a paragraph into lines of fixed width, choosing line breaks to minimize total badness with a lexicographic tie-break on gap widths.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Unimodal Palindromic DecompositionsCount the number of ways to write N as a sum of a palindromic sequence whose values rise to the middle then fall.Medium7Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
To the MaxFind the contiguous rectangular subregion of an N by N integer matrix with the largest possible sum and print that sum.Medium7Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Cog-WheelsGiven a set of cog sizes where every size is a multiple of the smallest, decide for each ratio a:b whether it can be realized by chaining products of available sizes.Medium7Number theoryMath+2No attempts yet1s128 MBJudgeable
StampsFor each h and k with h+k<=9, find k stamp values whose at-most-h sums cover 1..n consecutively for the longest range, then print the lexicographically smallest such set and n.Medium7Dynamic programmingBrute force+2No attempts yet1s128 MBJudgeable
Making ChangeFor each transaction, find the fewest total coins exchanged when you pay with your limited coins and the shopkeeper returns change using unlimited coins.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Another LotteryEach of n players buys tickets across m rounds; round j pays 2^j to one random ticket. For each player, print the reduced fraction for the probability of winning strictly more money than everyone else.Medium7ProbabilityMath+2No attempts yet1s256 MBJudgeable
Elias Gamma CodeGiven counts of numbers by binary bit length, choose prefix shifts and optional leading zeros to minimize the total encoded length.Medium7Dynamic programmingGreedyNo attempts yet1s128 MBJudgeable
Help BobGiven up to 15 pizzas with prices, areas, and stacked discount coupons unlocked by buying other pizzas, find the minimum total price over total area of any nonempty purchase order.Medium7Dynamic programmingBit manipulation+1No attempts yet1s128 MBJudgeable
All Discs ConsideredGiven a DAG of package dependencies split across exactly two DVDs, find the minimum number of disc changes to install all packages with a single drive.Medium7GraphTopological sort+2No attempts yet1s256 MBJudgeable
Huffman's GreedWe build the optimal binary search tree for weighted key and gap frequencies, minimizing weighted comparison counts.Medium7Dynamic programmingTree+2No attempts yet1s128 MBJudgeable
Phylogenetic Trees InheritedGiven leaf sequences of a complete binary tree, label internal nodes to minimize the sum of Hamming distances along edges, and output the lexicographically smallest optimal root sequence with its cost.Medium7Dynamic programmingTree+2No attempts yet1s128 MBJudgeable
New FruitFor each pair of strings, output the shortest common supersequence, breaking ties by choosing the lexicographically smallest one.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Bus Clock DisplayGiven up to 100 partial 7-segment clock readings with min and max elapsed minutes between consecutive readings, determine the time at each reading or report how many possibilities remain.Medium7Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Hack around the LockStarting from a given K-digit lock setting, find the minimum number of single-wheel rotations needed to visit every other K-digit setting at least once.Medium7GraphMath+2No attempts yet5s256 MBJudgeable
Divisors of a Binomial CoefficientFor each pair n and k, count the distinct divisors of the binomial coefficient C(n, k), where n is at most 431.Medium7Number theoryMath+2No attempts yet1s256 MBJudgeable
IVXLCDMGiven a lowercase inscription line, find the largest value of a valid Roman numeral readable as a subsequence of its letters, or 0 if none.Medium7GreedyString+2No attempts yet1s128 MBJudgeable
Formatting TextGiven words and a target width, break the text into lines to minimize total gap badness, with a penalty of 500 for any line holding one word.Medium7Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
S-NimGiven a move set S, decide for each position whether the S-Nim game is a win or a loss by computing Grundy numbers and XORing them over the heaps.Medium7Game theoryDynamic programming+2No attempts yet1s128 MBJudgeable
Lazy and Strict EvaluationGiven function definitions in a small Lisp-like language, count how many times each arithmetic operation runs under lazy (memoized) versus strict evaluation, skipping non-terminating tests.Medium7ImplementationRecursion+2No attempts yet1s128 MBJudgeable
TouristOn a grid with blocked cells, find two monotone paths (down-right then up-left) maximizing the number of distinct interesting cells visited.Medium7Dynamic programmingMatrix+2No attempts yet1s128 MBJudgeable
The Mailbox Manufacturers ProblemWith k identical mailboxes usable up to m firecrackers, find the minimum worst-case cost in firecrackers to pin down exactly how many each can survive.Medium7Dynamic programmingBinary search+2No attempts yet1s128 MBJudgeable
Bridge PlacementsPlace k horizontal bridges between two skyscrapers of given heights to minimize total stairs over all ordered floor pairs, breaking ties with the lowest placement.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
A Fair JuryPick exactly m candidates from a pool, minimizing |total defense minus total prosecution|, then maximizing the combined total among those juries.Medium7Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Co-workers from HellPlace tricks in chambers so the watchman's walk, where each trick is used once to change dwell time and jump target, maximizes total time before he normally finishes chamber n.Medium7Dynamic programmingGraph+2No attempts yet1s128 MBJudgeable
Factor SolitaireStarting from 1, repeatedly replace c by c + a where a divides c and b = c/a, paying b; find the minimum total cost to reach N.Medium7Dynamic programmingNumber theory+2No attempts yet1s128 MBJudgeable
LHCGiven a tree, find the maximum cycle length obtainable by adding one edge, and count the vertex pairs that achieve it.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
RepetitivityCompute the sum of squared occurrence counts over all distinct subsequences of a string, modulo M.Medium7StringDynamic programming+2No attempts yet2s512 MBJudgeable
Mhocskian LanguagesGiven a context-free grammar in Chomsky normal form and a list of words, decide for each word whether the start variable can derive it.Medium7Dynamic programmingString+2No attempts yet2s512 MBJudgeable
Editor DistanceGiven the character counts of N lines up to 80 wide, find the fewest arrow-key presses to move a cursor from a start position to a finish position, where vertical moves clamp to each line's end.Medium7GraphShortest path+2No attempts yet2s512 MBJudgeable
DinnerGiven a line of G and H programmers, repeatedly remove a run of at least K equal letters; find the minimum number of removals to clear the line, or -1.Medium7Dynamic programmingIntervals+2No attempts yet1s128 MBJudgeable
Bowling for Numbers++Choose at most k windows of length w, possibly overlapping beyond the row ends, so the sum of the covered pins is as large as possible.Medium7Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable