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,688 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Turning Off the LampsGiven lamp positions and power rates on a line and a starting point, find the walking order that minimizes total energy spent before all lamps are switched off.Medium6Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Moore MachineParse a series-parallel Moore machine expression and determine the unique erased output symbol that matches an observed string, or report ambiguity or impossibility.Medium6Dynamic programmingString+2No attempts yet1s128 MBJudgeable
FATBOYFind the longest common subsequence of three given strings, breaking ties by lexicographically smallest result.Medium6Dynamic programmingStringNo attempts yet1s128 MBJudgeable
A Huge TowerCount the number of orderings of N distinct blocks into a tower, respecting a size-tolerance stacking rule, modulo 1e9+9.Medium6SortingCombinatorics+1No attempts yet1s128 MBJudgeable
MessengersGiven a tree with per-city messenger costs, compute for every city the minimum time to relay a message to the root via edge lengths and messenger switching costs.Medium6TreeDynamic programming+1No attempts yet1s128 MBJudgeable
BracketsCount, modulo 1e9+9, the ways to turn some matching '(' '(' pairs back into '[' ']' so the bracket string becomes valid with at least one square pair.Medium6Dynamic programmingStack+1No attempts yet1s128 MBJudgeable
MelodyGiven N notes with S-digit codes and a target tune of length L, choose a sequence of notes with adjacent Hamming distance at most G that minimizes total mismatch with the written tune, then output the smallest such sequence lexicographically.Medium6Dynamic programmingString+1No attempts yet1s128 MBJudgeable
CandiesGiven N bags of candies, choose which bag's count to replace with a new positive value so the number of distinct subset sums is maximized, breaking ties by smallest P then smallest Q.Medium6Dynamic programmingBrute force+1No attempts yet1s128 MBJudgeable
RectanglesChoose an orientation (width/height swap) for each rectangle placed side by side to maximize the sum of top and internal vertical edges excluding outer sides and bottoms.Medium6Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Speed LimitsFind the fastest path in a directed road network where roads without a posted speed limit inherit the previously used speed limit, requiring state-dependent shortest path search.Medium6Shortest pathGraph+1No attempts yet1s128 MBJudgeable
ExpressionsCount balanced parenthesis strings of a given total length that have exactly a given maximum nesting depth.Medium6Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Justice for AllGiven a k x k 0/1 trust matrix (k up to 20), count the number of perfect matchings between knights and horses, i.e. the permanent of the matrix.Medium6Dynamic programmingBit manipulation+1No attempts yet1s128 MBJudgeable
Evacuation PlanGiven n team positions and m shelter positions on a line, find the minimum total distance assignment where every shelter gets at least one team.Medium6Dynamic programmingSorting+1No attempts yet1s128 MBJudgeable
Choosing a PubSimulate probabilistic vote-following among n pubs (Pólya urn style) to compute exact final probability each pub wins, handling ties uniformly.Medium6Dynamic programmingProbability+1No attempts yet1s128 MBJudgeable
TichuGiven a 13-card Tichu hand, compute the minimum number of legal combinations (singles, pairs, triples, quads, full houses, straights) that partition the hand.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Kim KangsanGiven fixed first and last pile heights, find the minimum total bricks added or removed to any middle pile so adjacent height differences stay within d.Medium6Dynamic programmingArray+1No attempts yet3s128 MBJudgeable
Row and Column Deletion GameGiven an n x n matrix where players alternately remove the last row or column if its sum is even, determine which player wins with optimal play across possibly many test cases up to n=1000.Medium6Game theoryDynamic programming+1No attempts yet1s128 MBJudgeable
The RobberyGiven N item types where type k has exactly k identical copies, pick copies within a weight budget M to maximize total value (bounded knapsack with huge M and small N).Medium6Dynamic programmingCombinatorics+1No attempts yet3s128 MBJudgeable
Computer TransformationGiven n up to 1000, compute the count of adjacent Medium6MathString+1No attempts yet1s128 MBJudgeable
City GameGiven several grid maps of free and reserved cells, find the largest all-free rectangle in each grid and print its area times three.Medium6StackDynamic programming+1No attempts yet1s128 MBJudgeable
FirefightersDetermine if question-mark operators in an arithmetic expression with brackets can be replaced by +,-,*,/ to reach a given target value under integer truncating division.Medium6Brute forceRecursion+1No attempts yet1s128 MBJudgeable
BOATGiven clients in fixed order, each with rental durations and deadline-based payment options, schedule non-overlapping rentals to maximize total earned money.Medium6Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Winning the MatchCompute the probability that team A wins a best-of-K volleyball match given per-serve win probabilities and a serve-switching rule between rounds and games.Medium6Dynamic programmingProbability+1No attempts yet1s128 MBJudgeable
Reseller's EyeGiven a budget and multiple sellers each offering a fixed bundle of items (buy all or none), choose a subset of sellers within budget to maximize resale profit, a bundled knapsack problem.Medium6Dynamic programmingGreedy+1No attempts yet2s128 MBJudgeable
Production ProcessGiven a matrix chain-like joining table for pieces, find the minimum-time parenthesization to assemble a given string, breaking ties by piece order.Medium6Dynamic programmingString+1No attempts yet5s128 MBJudgeable
Atomic Car RaceGiven checkpoints and a per-kilometer speed model that depends on distance since last tire change, find the tire-change strategy at checkpoints that minimizes total race time.Medium6Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
Confusing Login NamesCompute an extended edit distance (insert, delete, replace, adjacent swap) between all pairs of given login names and output pairs within a given threshold, sorted alphabetically.Medium6Dynamic programmingString+1No attempts yet3s128 MBJudgeable
Random WalkGiven n steps with probabilities of moving left, right, or staying, compute the expected value of the maximum position reached.Medium6Dynamic programmingProbability+1No attempts yet10s128 MBJudgeable
Hongjun's Royal GuardCount permutations of N distinct elements where every interior element is a local extremum (both neighbors larger or both smaller); N is at most 20.Medium6Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
SightseeingChoose a direction for each track on a circular tour so the total hiking plus transfer time is minimized, and check it against a limit T.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Cover UpGiven per-digit candidate lists with known-candidate probabilities, compute the win probability when the contestant plays optimally.Medium6ProbabilityDynamic programming+2No attempts yet1s128 MBJudgeable
Pizza Delivery Minimum TimeGiven directed travel times between a pizzeria and up to 10 stops, find the shortest round trip from the pizzeria visiting every stop.Medium6Shortest pathDynamic programming+2No attempts yet1s128 MBJudgeable
Two EndsFor each even-length row of cards, find the best score margin the first player can get when the second player always takes the larger end.Medium6Dynamic programmingGame theory+1No attempts yet1s128 MBJudgeable
Sunday DriveGiven a sequence of straight and 90-degree curved highway sections with M lanes, find the shortest path including lane changes, which take 100 feet per lane.Medium6Dynamic programmingGeometryNo attempts yet1s128 MBJudgeable
Roller CoasterEach section of a roller coaster either adds fun and dizziness or reduces dizziness by K; find the maximum fun keeping dizziness at or below L at all times.Medium6Dynamic programmingNo attempts yet1s128 MBJudgeable
The Ninja WayGiven trees in fixed left-to-right order with distinct heights, place them on integer positions so each jump to the next taller tree spans at most D, maximizing the span from shortest to tallest.Medium6Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
Robot ChallengeThe robot starts at (0,0), must visit targets in order, and may skip any target by paying its penalty. Find the minimum total time plus penalties to reach (100,100).Medium6Dynamic programmingGeometry+2No attempts yet1s128 MBJudgeable
MosaicCount the tilings of an N x M grid with 2 x 2 squares and L-trominoes, modulo 1,000,000.Medium6Dynamic programmingBit manipulationNo attempts yet1s128 MBJudgeable
Class ScheduleChoose one class per category to minimize class costs plus total travel from position 0 through the chosen rooms to position L.Medium6Dynamic programmingSortingNo attempts yet1s128 MBJudgeable
Train SortingCars arrive in a fixed order; each can be attached to the front, the back, or skipped, keeping weights strictly decreasing front to back. Find the longest train.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
TournamentGiven k knights with abilities, choose 2^e - k of them to sit out the first round and pair the rest to minimize the sum of squared ability differences.Medium6Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
Exchange RatesWith a daily CAD/USD rate and a 3% commission per conversion, find the maximum final amount of Canadian dollars you can hold after the last day.Medium6Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Security CompanyPoints lie on a line with travel times between neighbors; starting from point a and visiting every point, minimize the total first-arrival time over all points.Medium6Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
One Person “The Price is Right”Given G guesses and L lifelines, find the largest N such that a strategy guarantees a win for any price from 1 to N.Medium6Dynamic programmingGame theoryNo attempts yet1s128 MBJudgeable
WFF 'N PROOFGiven counts of logic symbols, find the maximum length of a well-formed formula that can be built from a subset of them.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
A Walk Through the ForestCount the number of routes from intersection 1 to 2 in an undirected weighted graph where each step strictly decreases the shortest distance to intersection 2.Medium6GraphShortest path+2No attempts yet1s128 MBJudgeable
Up the AnteGiven per-round win probabilities, find the chance a capped martingale strategy shows a positive balance at some round from k through m.Medium6ProbabilityDynamic programming+2No attempts yet1s128 MBJudgeable
Work ReductionFor each agency with per-unit cost A and halving cost B, find the minimum cost to cut N units of paperwork down to exactly M.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Marbles on a TreeGiven a rooted tree where each vertex has a box and the total marbles equal the number of vertices, find the minimum number of moves (along edges) so every box holds exactly one marble.Medium6TreeDFS+2No attempts yet1s128 MBJudgeable
Adventures in Moving - Part IVGiven a route with up to 100 gas stations, each with a price per litre, find the cheapest way to fuel a truck with a 200-litre tank that starts and ends half full.Medium6GreedyDynamic programming+2No attempts yet1s128 MBJudgeable
No TippingCount the orders in which n packages can be removed from a lever on two fulcrums so the board never tips.Medium6BacktrackingBit manipulation+1No attempts yet1s128 MBJudgeable
Bridge CrossingGiven n people's crossing times and one flashlight, find the minimum total time to move everyone across when at most two cross together.Medium6GreedySorting+2No attempts yet1s128 MBJudgeable
The Brick Stops HereGiven N brick types with copper content and price, answer C queries: pick exactly M distinct types whose copper sum lies in [M*Cmin, M*Cmax] at minimum total price.Medium6Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
Sang-geun's LockCount the number of height-balanced binary trees with N nodes, print the last 9 digits padded to width 9.Medium6Dynamic programmingRecursion+1No attempts yet1s128 MBJudgeable
PebblesPlace pebbles on an N by N board so no two touch even diagonally, maximizing the sum of covered cell values.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Words and the Periodic TableSplit each word into element symbols, case-insensitively, choosing the split with the fewest parts, then the lowest atomic-number sum.Medium6Dynamic programmingString+1No attempts yet1s128 MBJudgeable
I'm Attacking the Darkness!Parse a dice expression with up to six dice and integer modifiers, then compute the reduced fraction of outcomes whose total meets or beats a target value.Medium6Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
Time to GraduateGiven up to 12 courses with prerequisites, fall or spring offerings, and a per-semester course cap, find the minimum number of semesters to finish all courses.Medium6GraphDynamic programming+2No attempts yet1s128 MBJudgeable
RobotsGiven garbage cells in a grid, robots walk from the northwest corner to the southeast corner moving only east or south; find the fewest robots that collect all garbage.Medium6Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
Raggedy, RaggedyGiven word widths and a max line length, split the words into lines and minimize the sum of squared unused space on every line except the last.Medium6Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Not One Bit MoreCount integers in [LO, HI] whose repeated popcount chain reaches 1 at exactly step X, with LO up to 1e18 and X up to 10.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Roller CoasterChoose open or closed eyes for each roller coaster section to maximize total fun while keeping dizziness within limit L, where closing decreases dizziness by K.Medium6Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
WordStackOrder the given words and pad each with leading spaces to maximize the total number of columns where a letter matches the letter directly above it.Medium6Dynamic programmingBit manipulationNo attempts yet1s128 MBJudgeable
The Candy StoreWith unlimited copies of each candy, find the maximum total calories obtainable with a given budget, where prices and the budget carry two decimal places.Medium6Dynamic programmingImplementation+2No attempts yet3s512 MBJudgeable
PillsCount how many distinct sequences of W and H can appear as a bottle of N pills is emptied, two halves per pill.Medium6Dynamic programmingCombinatoricsNo attempts yet1s256 MBJudgeable
Vacation RentalsGiven a table of which units are free on each day, schedule a new guest's stay over [a,d) using the fewest unit changes, breaking ties by smallest unit label each night.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Toothpick ArithmeticFor each N up to 5000, find the fewest toothpicks needed to write an expression equal to N using unary operands and + or x as operators.Medium6Dynamic programmingMathNo attempts yet1s128 MBJudgeable
KnotsFor each even N up to 100, find the probability that two random perfect matchings on N points form a single cycle.Medium6CombinatoricsMath+1No attempts yet1s128 MBJudgeable
Mix and BuildFind the longest sequence of given distinct words where each word is formed by adding one letter and rearranging.Medium6Hash mapDynamic programming+2No attempts yet1s128 MBJudgeable
Chop Ahoy! Revisited!Count the ways to split a digit string into consecutive groups whose digit sums are non-decreasing across groups.Medium6Dynamic programmingPrefix sumNo attempts yet1s128 MBJudgeable
Twirling RobotFind the cheapest sequence of override commands to steer a robot from the top-left cell to the bottom-right goal, where each cell forces a default move.Medium6Shortest pathGraph+2No attempts yet1s128 MBJudgeable
DoormanGiven a queue of men and women and a limit X, repeatedly admit the front or second person so the running gender difference never exceeds X, and maximize the number admitted.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
JuiceGiven a rooted tree with cord capacities and house demands, choose which houses to power so that flow through each cord stays within capacity and the count is maximized.Medium6TreeDFS+2No attempts yet2s128 MBJudgeable
Odd, Even, and ChangyeongThree players move in fixed order, each adding 1 or dividing by a prime, and each tries to minimize the smallest number they personally produce.Medium6Dynamic programmingGame theory+2No attempts yet1s128 MBJudgeable
Sanggeun Trapped in a MazeCount closed walks of length n on an infinite hexagonal lattice starting and ending at one room.Medium6CombinatoricsDynamic programming+1No attempts yet1s128 MBJudgeable
Chemical AnalysisGiven up to 12 element bitmasks and a target bitmask, find the fewest elements whose bitwise OR equals the target, or report that none does.Medium6Bit manipulationBrute force+2No attempts yet1s128 MBJudgeable
Monkeys at TypewritersGiven per-letter and space probabilities, find the probability that a random key sequence terminates at its first space in one of the given words.Medium6ProbabilityTrie+2No attempts yet1s128 MBJudgeable
Zebra HerdAssign each of z zebras one of two colors at each of t times, minimizing same-color distance costs, opposite-color bonuses, and color-change penalties.Medium6Dynamic programmingBit manipulation+2No attempts yet7s128 MBJudgeable
Arsenic and Old LaceGiven up to 20 base products as bitmasks over s substances, find the fewest products whose union exactly equals the poison mask, or report impossible.Medium6Bit manipulationBrute force+2No attempts yet1s128 MBJudgeable
Swimming with SharksOn a w by h grid starting and ending at (1,1), plan t moves (or stays) to maximize the minimum Euclidean distance to any shark present at each time step.Medium6Dynamic programmingBinary search+2No attempts yet1s128 MBJudgeable
Orange BowlGiven plays with a yard gain and success probability, choose a sequence whose total gain reaches n yards while maximizing the product of probabilities.Medium6Dynamic programmingMath+2No attempts yet1s128 MBJudgeable
Course LoadPick a set of classes with pairwise disjoint meeting slots and total workload at most C, maximizing total utility.Medium6Dynamic programmingBit manipulation+1No attempts yet1s128 MBJudgeable
Shut the Box IIGiven open cards and a rolled total, pick the set summing to the total that maximizes the probability of shutting every card under optimal play, and report that probability.Medium6Dynamic programmingBacktracking+2No attempts yet1s128 MBJudgeable
Buying NotebooksEach store has a fixed shipping fee, a per-notebook price, and limited stock; buy exactly N notebooks across stores at minimum total cost.Medium6Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
Digit Sum of a RangeFor each query [a,b] with b up to 10^15, output the sum of all decimal digits of every integer in the range.Medium6MathDynamic programming+2No attempts yet1s128 MBJudgeable
Stifling the MutinyDistribute k pirates over n ships, each with at least one loyal pirate, so that no ship's loyal count is below the disloyal pirates on it and its neighbors, maximizing disloyal pirates.Medium6Dynamic programmingBrute force+1No attempts yet1s128 MBJudgeable
My Cousin ObamaGiven a forest of parent links, find the ancestor path from A0 to B0 that passes through as few mothers as possible.Medium6GraphDFS+2No attempts yet1s128 MBJudgeable
RaisinsSplit an N by M chocolate bar into unit cells by straight cuts; each cut costs the raisins in the piece, and the goal is to minimize the total payment.Medium6Dynamic programmingPrefix sum+2No attempts yet3s128 MBJudgeable
Average Value SequenceGiven a non-decreasing average sequence m of length n, count the integer sequences s of length n+1 whose adjacent averages equal m.Medium6MathCombinatorics+2No attempts yet5s256 MBJudgeable
Batch SchedulingSplit the ordered jobs into consecutive batches, each paying a setup time, and minimize the sum of weighted completion times.Medium6Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
PalindromeGiven a string, find the minimum number of characters to insert anywhere so the string becomes a palindrome.Medium6Dynamic programmingString+2No attempts yet1s256 MBJudgeable
Car ParkingGiven a row of cars and W workers, find the minimum number of cars that must change places so the types are sorted ascending.Medium6GreedyDynamic programming+1No attempts yet1s128 MBJudgeable
Card Game is FunAnna may delete arbitrary cards from her sequence and Bruno may trim cards from the top and bottom of his; find the longest common subarray obtainable.Medium6Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
The Used BookstoreChoose exactly K of N books to sell, maxing the total where selling t books of one genre adds t(t-1) extra to that genre's group.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
First GradeCount the ways to place + or - between the first N-1 digits and = before the last digit so that left-to-right evaluation never leaves the range 0 to 20 and the total equals the last digit.Medium6Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
Splitting the SnackChoose which of the N-1 cut points to cut so that both people get exactly N/2 pieces, minimizing the total force of the chosen cuts.Medium6Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Hop-Hop River CrossingStarting from the near bank, hop across stones in n rows using normal jumps or at most m row-skipping jumps, minimizing total jump danger.Medium6Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Sea JourneyProcess a stream of queries where each query asks for the shortest path between two islands after a sequence of edge insertions.Medium6Shortest pathGraph+2No attempts yet1s128 MBJudgeable
Warp Speed IIFor each hop sequence, pick a warp-drive state per hop minimizing switch plus hop energy, and return the lexicographically smallest optimal state sequence.Medium6Dynamic programmingGreedy+2No attempts yet5s128 MBJudgeable
Nowhere MoneyRepresent each amount as a sum of T(s) values (T(n) = Fibonacci-like count) with the fewest slots whose sizes differ by at least 2, and print the sizes and values.Medium6GreedyDynamic programming+2No attempts yet1s128 MBJudgeable