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,682 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Maximum Subarray 2147483647Given a sequence of n integers, find the maximum possible sum of a contiguous subarray, choosing at least one element.Medium4Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Range Digit SumSum the decimal digits of every integer from L to U, inclusive, where U can reach two billion.Medium5MathDynamic programming+1No attempts yet2s128 MBJudgeable
Unknown SentencePartition a sentence into segments that are anagrams of given words, minimizing total letters moved from their original word positions.Medium5Dynamic programmingString+1No attempts yet2s128 MBJudgeable
HotelGiven advertising costs and customer gains for up to 20 cities with unlimited repeats, find the minimum total cost to gain at least C new customers.Medium5Dynamic programmingMathNo attempts yet2s128 MBJudgeable
PrefixGiven up to 50 words, find the largest subset where no word is a prefix of another, using a trie and tree DP.Medium5TrieDynamic programming+2No attempts yet2s128 MBJudgeable
Solving ProblemsGiven N interest values and a rule to move forward by 1 or 2 steps starting at problem 1, find the minimum number of problems solved before the range of solved values reaches at least V.Medium5Dynamic programmingGraph+2No attempts yet2s128 MBJudgeable
Tangled Electric WiresGiven a matching between left and right poles, find the minimum number of wires to cut so no two remaining wires cross, which reduces to computing N minus the longest increasing subsequence.Medium5Dynamic programmingBinary search+1No attempts yet1s128 MBJudgeable
Array ValueFind a path from top-left to bottom-right of an N by N grid, avoiding zero cells, that minimizes the trailing zeros in the product of visited values.Medium5Dynamic programmingMath+2No attempts yet2s128 MBJudgeable
Substring Picking GamePlayers alternately subtract a value formed by a proper substring of the current number's digits, and you must find the smallest first move that forces a win, or -1 if none exists.Medium5Game theoryDynamic programming+2No attempts yet2s256 MBJudgeable
New Year PartyPick a maximum-score guest list from a company tree so no employee and their direct manager both attend, computed with and without the root.Medium5Dynamic programmingTree+1No attempts yet2s128 MBJudgeable
Making the Best TeamChoose 15 players for white and 15 for black from a list of up to 1000 players to maximize the total ability sum.Medium5Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Captain DasomGiven N cannonballs, find the minimum number of tetrahedral-number piles whose sizes sum exactly to N using unbounded coin-change style DP.Medium5Dynamic programmingMath+1No attempts yet2s128 MBJudgeable
Summit Handshakes 2Given N seats around a round table, count the ways N representatives can pair up with non-crossing handshake segments, modulo 987654321.Medium5Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Number GameGiven a set of numbers including 1 and a limit K, find the first integer that cannot be formed using at most K chosen numbers, then decide the game winner by turn parity.Medium5Dynamic programmingMath+1No attempts yet2s128 MBJudgeable
Making a PalindromeFind the minimum number of integers to insert into a sequence so it becomes a palindrome, using interval or LCS-based dynamic programming.Medium5Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
TilingCount the number of ways to tile a 2×n rectangle using 2×1 and 2×2 tiles for multiple values of n up to 250.Medium5Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
Sorting the BookshelfFind the minimum number of single-book relocations needed to sort a permutation of N books into increasing order.Medium5Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
HighwayGiven a directed graph with edge lengths and tolls, find the minimum length path from city 1 to city N whose total toll does not exceed a budget K.Medium5Dynamic programmingGraph+1No attempts yet2s128 MBJudgeable
Word ExtensionGiven a dictionary and a starting 3-letter word, find the longest word reachable by repeatedly inserting one letter such that each intermediate word exists in the dictionary.Medium5Dynamic programmingString+1No attempts yet2s128 MBJudgeable
Coin DistributionGiven several coin denominations with counts, decide for three test cases whether the coins can be split into two subsets of equal total value.Medium5Dynamic programmingArrayNo attempts yet2s128 MBJudgeable
CheersGiven N people around a circle each drinking a cola brand, find the maximum number of non-crossing pairs connecting people with the same brand.Medium5Dynamic programmingIntervalsNo attempts yet2s128 MBJudgeable
Jump Jump ChampionshipGiven an array, find the longest strictly increasing subsequence and output its length plus the indices of one such subsequence.Medium5Dynamic programmingBinary search+1No attempts yet2s128 MBJudgeable
Relay RaceGiven N runners in fixed order each running 1 to 3 consecutive days, find the day-count assignment summing to exactly D that maximizes total distance, or -1 if invalid.Medium5Dynamic programmingNo attempts yet2s128 MBJudgeable
Traveling Salesperson TourFind the minimum cost Hamiltonian cycle in a directed graph with up to 16 cities using bitmask dynamic programming.Medium5Dynamic programmingBit manipulation+1No attempts yet1s128 MBJudgeable
Bug on a TreeGiven a tree with fruit values on vertices, find the maximum sum path (simple path) and its smallest-numbered starting endpoint.Medium5TreeDynamic programming+1No attempts yet2s128 MBJudgeable
Wine TastingPick numbers from a sequence maximizing sum while never selecting three consecutive elements.Medium5Dynamic programmingNo attempts yet2s128 MBJudgeable
In-Flight Meal TripFind the maximum-score path from city 1 to city N using at most M cities, moving only to strictly increasing city numbers along available flights.Medium5Dynamic programmingGraphNo attempts yet2s128 MBJudgeable
Mountain BikeFind the minimum travel time from top-left to bottom-right of a grid where each move's duration depends on cumulative speed changes from height differences, solvable via Dijkstra with speed encoded as exponent sums.Medium5Shortest pathGraph+1No attempts yet2s128 MBJudgeable
Letter BoardCount the number of paths on an N by M letter grid that spell a given word, moving 1 to K cells in one straight direction per step.Medium5Dynamic programmingMatrix+1No attempts yet2s128 MBJudgeable
String CopyFind the minimum number of substring-copy operations from S needed to reconstruct P using greedy/DP over matching positions.Medium5Dynamic programmingString+1No attempts yet2s128 MBJudgeable
Marbles in BoxesGiven two marble sequences and a pairwise score table, choose a sequence of pop/pop/pop-both operations to maximize total matched-pair score, using LCS-like DP with reconstruction.Medium5Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
Team FormationPartition an age-ordered score sequence into contiguous groups to maximize the sum of each group's max-minus-min score.Medium5Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
Sequence ReductionDecide if repeatedly merging adjacent elements as A[i]-A[i+1] can reduce the sequence to a single target value T.Medium5Dynamic programmingRecursionNo attempts yet2s128 MBJudgeable
Plum TreeGiven a sequence of falling trees over T seconds, find the max plums caught starting at tree 1 with at most W moves between trees.Medium5Dynamic programmingNo attempts yet2s128 MBJudgeable
JumpFind the minimum number of jumps from stone 1 to stone N where jump lengths change by at most 1 each step and some stones are blocked.Medium5Dynamic programmingBFS+1No attempts yet2s128 MBJudgeable
Theater SeatsCount permutations where each ticket holder sits in their own or adjacent seat, with VIP seats fixed and splitting the row into independent segments counted by a Fibonacci-like recurrence.Medium5Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Buying JewelsFor each of n rows pick a contiguous non-empty subarray maximizing summed total value, breaking ties by fewest jewels then lexicographically smallest index sequence.Medium5Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
Tree CuttingGiven a tree with n vertices, find the minimum number of edges to cut so some resulting piece has exactly m vertices, or report impossibility.Medium5TreeDynamic programming+1No attempts yet2s128 MBJudgeable
Fax CompressionChoose a quantization of a sequence into 4 levels with run-length style bit encoding to minimize error plus weighted code length.Medium5Dynamic programmingString+1No attempts yet2s128 MBJudgeable
Dance Pad Minimum EnergyGiven a sequence of dance pad moves, compute the minimum total energy to press each in order by choosing which of two feet to move each time.Medium5Dynamic programmingSimulationNo attempts yet2s128 MBJudgeable
Polygon PartitionsCount noncrossing dissections of a regular N-gon into all triangles or all quadrilaterals, modulo 1e9, using Catalan-like combinatorics.Medium5CombinatoricsDynamic programming+1No attempts yet2s128 MBJudgeable
Number of PermutationsGiven a permutation's up-down pattern, count permutations of size n sharing the same pattern, modulo 1,000,000,000.Medium5Dynamic programmingCombinatoricsNo attempts yet2s128 MBJudgeable
Sum of Powers of TwoCount the ways to write N as an unordered sum of powers of two, modulo one billion.Medium5Dynamic programmingMath+1No attempts yet2s128 MBJudgeable
Brotherly Field DivisionChoose a non-decreasing staircase cut across N columns of an N x N grid to minimize the harvest difference between the two regions, and output one such cut.Medium5Dynamic programmingBrute force+1No attempts yet1s256 MBJudgeable
ParameciaSimulate a population where each individual matures, reproduces daily within an age window, dies at a fixed age, and count survivors on day N modulo 1000.Medium5Dynamic programmingSimulation+1No attempts yet1s128 MBJudgeable
Electric WiresGiven wires connecting positions on two poles, find the minimum removals so remaining wires never cross, equivalent to n minus the longest increasing subsequence.Medium5Dynamic programmingBinary search+1No attempts yet1s128 MBJudgeable
Crossing the Stone BridgesCount ways to match a scroll string to positions across two parallel bridge strings, alternating bridges and strictly increasing positions.Medium5Dynamic programmingStringNo attempts yet1s128 MBJudgeable
Corporate InvestmentAllocate exactly N integer units of money across M companies using given profit tables to maximize total profit, then output an allocation, a classic knapsack-style DP task.Medium5Dynamic programmingArray+1No attempts yet1s128 MBJudgeable
Submarine IdentificationDecide whether a binary string can be split into pieces of '01' or '1' followed by at least two 0s and at least one 1, using pattern matching or DP.Medium5Dynamic programmingString matching+1No attempts yet1s128 MBJudgeable
Glass BallsGiven B balls and M floors, compute the minimum number of drops needed to guarantee finding the critical breaking floor in the worst case.Medium5Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
Adjacent Bit Pair CountCount binary strings of length n whose number of adjacent 11-pairs equals a given k, for up to 1000 queries.Medium5Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
KnightSimulate a knight's moves on an N x N board for T steps (T up to a million), where each square can only be entered at time-multiples of its written value, and output all possible final squares.Medium5BFSSimulation+1No attempts yet1s128 MBJudgeable
Dongjun's GameGiven N level scores, find the minimum total decrease needed to make the sequence strictly increasing while all scores stay positive.Medium5GreedyArray+1No attempts yet1s128 MBJudgeable
Pleasant WordCount ways to fill blanks in a word with uppercase letters so it avoids three consecutive vowels or consonants and contains at least one 'L'.Medium5Dynamic programmingString+1No attempts yet1s128 MBJudgeable
DebugGiven a binary R by C grid, find the largest square submatrix (side at least 2) that is invariant under 180-degree rotation, or output -1.Medium5Dynamic programmingMatrix+1No attempts yet5s128 MBJudgeable
FootnotesGiven text lines and footnotes attached to specific lines, compute the minimum number of pages so that each page holds consecutive text lines plus their footnotes within a line limit K.Medium5Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Foot TypingGiven two words and their interleaving, output the lexicographically smallest sequence of 1s and 2s marking which word produced each character.Medium5Dynamic programmingString+1No attempts yet1s128 MBJudgeable
ExchangeGiven daily buy and sell exchange rates between marks and dollars, compute the maximum marks obtainable after N days starting from 100 marks, output as a reduced fraction.Medium5Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
Friends Calling PlanGiven call minutes between up to 16 employees, pair them all up to minimize total billing cost using bitmask DP over perfect matchings.Medium5Dynamic programmingBit manipulation+1No attempts yet1s128 MBJudgeable
Hop, HopCount, modulo 1000000, the number of ways to write n as a non-increasing sequence of jumps of length 1, 2, or 3, for n up to 1e9.Medium5MathDynamic programming+1No attempts yet1s128 MBJudgeable
Ancient ManuscriptCount ways to fill '*' letters in a word so runs of vowels/consonants respect maximum length and maximum equal-letter-repeat limits, using DP over letter classes and previous letter identity.Medium5Dynamic programmingString+1No attempts yet1s128 MBJudgeable
Decoding Morse SequencesCount the number of ways to split a given Morse code string into a sequence of dictionary words, using dynamic programming with Morse-to-word conversion.Medium5Dynamic programmingString+1No attempts yet1s128 MBJudgeable
Sangkeun TowerFor each elevator, find the minimum floor above 0 reachable using exactly n button presses (up/down moves), never going below 0, then take the overall minimum across elevators.Medium5Dynamic programmingBrute force+1No attempts yet1s128 MBJudgeable
Graph MatchingCount the number of matchings (independent edge sets) of the cycle graph C_n for each given n, likely requiring big-integer arithmetic via a Lucas-sequence style recurrence.Medium5Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
ComputersGiven a fixed replacement cost and arbitrary maintenance costs for owning a computer over any year range, find the minimum total cost to cover n years using dynamic programming.Medium5Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
Game, Set and MatchGiven the per-point win probability p, compute the probabilities of winning a tennis game, set, and match using the standard scoring rules.Medium5Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
Minimal BackgammonSimulate turn by turn probability mass over board positions (with lose-a-turn and go-to-start squares, and bounce-back overshoot rule) to find probability of reaching the goal within T turns.Medium5Dynamic programmingSimulation+1No attempts yet1s128 MBJudgeable
Sum of Distinct PrimesCount subsets of k distinct primes summing to n, using dynamic programming over sieve-generated primes up to 1120.Medium5Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
Maximum SumGiven n boxes of numbered balls, pick at most one ball per box in order to form a non-decreasing sequence with maximum possible sum.Medium5Dynamic programmingSortingNo attempts yet1s128 MBJudgeable
Faulhaber's TriangleBuild Faulhaber's triangle row by row using the recurrence F(i,j)=i/j*F(i-1,j-1) plus the normalization that each row sums to 1, then answer queries for F(m,k) as reduced fractions.Medium5Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
CounterattackTwo strikers advance in lockstep through n points, each step either dribbling or passing to the partner; find the cheapest route from a long pass at point 1 to a shot at point n.Medium5Dynamic programmingArray+1No attempts yet1s256 MBJudgeable
Pro-Test VotingGiven a budget and precincts whose vote gain follows a concave spending curve, allocate dollars to maximize rounded total votes, breaking ties toward lower-numbered precincts.Medium5Dynamic programmingGreedyNo attempts yet1s128 MBJudgeable
Largest SquareGiven a 0/1 matrix, find the side length of the largest all-ones square submatrix.Medium5Dynamic programmingMatrixNo attempts yet5s256 MBJudgeable
SkylineCount permutations of 1..N with no increasing subsequence of length 3, modulo 1,000,000, for each N up to 1,000.Medium5Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Ferry Loading VGiven distinct vehicle weights, split them between two lanes so the totals differ as little as possible. Output the minimum difference.Medium5Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
Scrolling SignGiven k-wide words, find the minimum total letters scrolled in so that each word appears in order, allowing overlap between consecutive words.Medium5Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Catamaran BallastSplit the given rock weights between two hulls so the difference of the two sums is as small as possible.Medium5Dynamic programmingBrute forceNo attempts yet1s128 MBJudgeable
Multiplication GameAlice and Bob multiply a running product by 2 to 9 in turn; find who forces the product to reach n first with optimal play.Medium5Game theoryDynamic programming+1No attempts yet1s128 MBJudgeable
Tight WordsCount words of length n over digits 0..k where adjacent digits differ by at most 1, then print that count as a percentage rounded to five decimals.Medium5Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Splitting Teams FairlySplit N people into two teams differing in size by at most one so their total weight difference is minimized, then print both totals in increasing order.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Old Wine Into New BottlesGiven a wine volume and bottle sizes with min and max capacities, maximize the bottled amount and print the leftover in millilitres.Medium5Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Ferry LoadingLoad the longest prefix of cars onto two lanes of bounded total length, choosing lanes to maximize cars loaded and break ties lexicographically.Medium5Dynamic programmingGreedyNo attempts yet1s128 MBJudgeable
Hippity HopscotchOn an n by n grid of penny stacks, starting at (0,0) and jumping up to k cells in a row or column to a strictly larger stack, find the maximum total collected.Medium5Dynamic programmingSorting+1No attempts yet1s128 MBJudgeable
PlinkoGiven rigged Plinko boards with per-peg right-move probabilities, compute for each start and end column the number of distinct paths and the truncated percentage chance.Medium5Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
RIPOFFA token moves 1 to S squares per turn and must exit a board of N labeled squares within T turns; maximize the total of the squares landed on.Medium5Dynamic programmingSliding windowNo attempts yet1s128 MBJudgeable
Signal StrengthFind the maximum signal strength reaching switch N-1 from switch 0 through a switch network with gain or loss multipliers on nodes and edges.Medium5GraphDFS+2No attempts yet1s128 MBJudgeable
RailroadGiven two sequences, decide whether a target sequence can be formed by repeatedly taking the front car of either train; once one train empties, the rest follow in order.Medium5Dynamic programmingTwo pointers+2No attempts yet1s128 MBJudgeable
PERMSFor each query (n, k), count permutations of 1..n having exactly k inversions, with n up to 18 and k up to 200.Medium5Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Sequence WalkingGiven two ascending integer sequences, find the maximum sum of a forward walk that may switch sequences at shared values.Medium5Dynamic programmingTwo pointersNo attempts yet1s128 MBJudgeable
Robots on a GridCount monotone right/down paths from the top-left to the bottom-right of an n by n grid with blocked cells, modulo 2^31-1, and report whether the goal is reachable at all, or reachable only with up and left moves allowed.Medium5Dynamic programmingDFS+2No attempts yet1s128 MBJudgeable
lsGiven a wildcard pattern where * matches any run of characters, print the input file names that match it, keeping input order.Medium5Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Rig PlacementGiven n oil fields, a per-field investment cap m, and a total budget B, pick an investment amount for each field so total oil is maximized.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Study DaysDistribute H study hours among n courses, each with 10 grade thresholds, to maximize the average grade point, rounded to two decimals.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Yes or No?Pick between l and r questions to answer Yes, maximizing the sum of per-question expected correct probabilities, and report the maximum expectation to two decimals.Medium5Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
Biomedical EngineeringGiven a target string and a set of reusable component strings, find the minimum number of components whose concatenation equals the target, or report that it is impossible.Medium5Dynamic programmingString+2No attempts yet1s128 MBJudgeable
GerrymanderingSplit n precincts, each with P and Q vote counts, into two nonempty districts; find how many districts P can win (0, 1, or 2).Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
SoccerCompute probability distribution of final scores after up to T seconds of a stochastic soccer simulation with passing, stealing, shooting, and absorbing states.Medium5ProbabilityDynamic programming+2No attempts yet2s128 MBJudgeable
Battleground PreservationGiven past battle results with costs, find the cheapest chain of victories between two fighters and decide the winner, or output FIGHT! if neither dominates.Medium5GraphShortest path+2No attempts yet1s128 MBJudgeable
Life ConnectionsGiven an undirected friendship graph, count the distinct shortest paths between each queried pair of nodes, where path length counts nodes.Medium5GraphBFS+2No attempts yet1s128 MBJudgeable
MessageGiven error and succession probabilities for a Martian alphabet, find the most likely original word for each intercepted message using maximum likelihood.Medium5Dynamic programmingProbabilityNo attempts yet1s128 MBJudgeable