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,701 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Flipping El-fetieraEach of K operations picks a uniformly random rectangular submatrix and flips every cell in it; compute the expected number of cells holding 1 at the end.Medium7ProbabilityDynamic programming+2No attempts yet10s512 MBJudgeable
Fixing Open Source BugsGiven bugs with fun values and prerequisite dependencies, choose a set of bugs to fix (each with all its prerequisites) that maximizes total fun.Medium7GraphDynamic programming+2No attempts yet4s256 MBJudgeable
TimelineGiven lower bounds on each of N session dates and C constraints that one session is at least x days after another, find the earliest feasible date for every session.Medium7GraphShortest path+2No attempts yet2s512 MBJudgeable
New Year and PermutationCount over all n! permutations the total number of segments whose max minus min equals length minus one, modulo a prime m.Medium7CombinatoricsMath+2No attempts yet1s1024 MBJudgeable
Number Card Removal GameFor each N, cards 1..N are played by removing a card x together with x-1 and x+1; find who wins under perfect play.Medium7Game theoryDynamic programming+2No attempts yet1s256 MBJudgeable
Equal DigitsCount the ways to delete disjoint substrings of length over 1 whose first and last digits match, so the remaining non-empty string has all distinct digits.Medium7Dynamic programmingCombinatorics+2No attempts yet3s256 MBJudgeable
BalanceGiven an N x N matrix A, find the entrywise-minimal balanced matrix B (satisfying the additive rectangle condition) with B[i][j] >= A[i][j], and report its sum.Medium7Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
Cube SummationFor each N, sum k^3 over all partitions of N with k parts, modulo 998244353, with up to 1e5 queries.Medium7Dynamic programmingCombinatorics+2No attempts yet4s512 MBJudgeable
Two PathsGiven a weighted undirected graph, find the shortest walk from node 1 to node n that differs from Alice's chosen shortest path.Medium7GraphShortest path+2No attempts yet1s512 MBJudgeable
DenominationsCount the number of ways to make change for n SmurfCoins using denominations 1, 5, 10, 25, modulo 10^9+7, where n can be as large as 10^18.Medium7MathCombinatorics+1No attempts yet0.5s512 MBJudgeable
Shortest Accepted WordParse a regular expression over a, b, c and $ into a tree, then compute the shortest lexicographically smallest string each node accepts.Medium7Dynamic programmingString+2No attempts yet1s256 MBJudgeable
DotA QualsGiven 2^n players and Idned ranked k-th, compute the expected number of rounds he survives when opponents are randomly paired each round and the higher rating always wins.Medium7ProbabilityCombinatorics+2No attempts yet1s256 MBJudgeable
Bin PackingGiven up to 24 item weights and a bin capacity S, find the minimum number of bins that hold all items with each bin's total weight at most S.Medium7Dynamic programmingBit manipulation+2No attempts yet4s256 MBJudgeable
Tree GameGiven a tree with all edges white, repeatedly pick a simple path whose endpoints are leaves and whose edges are all white, and paint those edges black; find the fewest paths needed to cover every edge.Medium7TreeDFS+2No attempts yet1s512 MBJudgeable
EquationCount integers n in [a,b] with k times the sum of squared digits of n equal to n, where a and b go up to 10^18.Medium7Dynamic programmingMath+2No attempts yet1s256 MBJudgeable
Geese vs. HawksMatch games of two teams so that every paired game's win/loss outcome agrees, maximizing the total points scored by both teams in the matched games.Medium7Dynamic programmingString+2No attempts yet1s512 MBJudgeable
RouteGiven trains with fixed departure and arrival times, find a route from station 1 to station n minimizing a quadratic cost on total waiting plus the final arrival time.Medium7GraphShortest path+2No attempts yet1s512 MBJudgeable
SafetyGiven N stack heights and a bound H, find the minimum number of unit additions/removals so that every adjacent pair differs by at most H.Medium7Dynamic programmingSliding window+1No attempts yet1s512 MBJudgeable
KnapsackBounded knapsack: given N item types with value, weight, and a large copy count, pick items within weight S to maximize total value.Medium7Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
Cows DriveFor each city, find the minimum travel time from city 1 minus the taste value of one rest stop chosen on the path.Medium7GraphShortest path+2No attempts yet0.5s1024 MBJudgeable
Downloading EpisodesChoose one fixed sequence of byte requests so that all n episodes download with minimum total packet size, where each packet adds a fixed header k.Medium7Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
DivisionChange the fewest digits of n so the resulting number has no leading zeros and is divisible by m, or report -1.Medium7Dynamic programmingMath+2No attempts yet2s512 MBJudgeable
Autumn ParkOn a grid with obstacles, count paths from entrance to exit whose length is exactly two more than the shortest path, modulo 1e9+9.Medium7GraphBFS+2No attempts yet2s512 MBJudgeable
Bridge ReinforcementGiven a graph with maximum degree 2, count the minimum-size edge subsets whose connectivity components match the original graph, modulo 1e9+7.Medium7GraphCombinatorics+2No attempts yet2s512 MBJudgeable
Hungry Frog BillyGiven sorted positions of midges on one side of a rock, eating a midge at distance d costs d energy and pushes all other midges one unit away from d, toward 0 or further out; find the minimum total energy to eat them all.Medium7GreedyDynamic programming+1No attempts yet2s512 MBJudgeable
Array InitializationCount ordered sequences of M interval marks on an array of length N whose union covers every position, modulo 1e9+7.Medium7Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
School OlympiadAssign n students at given coordinates to three locations with capacity limits so the total walking distance is minimized.Medium7GreedySorting+2No attempts yet1s512 MBJudgeable
PrintingGiven n cartridge types with cost c_i and page yield p_i (both at most 200), find the minimum total cost to reach exactly k pages, or -1 if impossible.Medium7Dynamic programmingNumber theory+2No attempts yet2s512 MBJudgeable
School DemocracyPartition the classes into consecutive groups of size between l and r, and maximize the total difference between elected boys and girls, where each group elects the side with more votes or both on a tie.Medium7Dynamic programmingPrefix sum+2No attempts yet2s512 MBJudgeable
Interval TrainingCount sequences of positive integers starting at k, summing to n, whose adjacent comparisons strictly alternate up and down, modulo 1e9+7.Medium7Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Jedi AcademyGiven a DAG of skill prerequisites and two buildings, find the shortest total time to learn all skills, counting travel and learning time.Medium7GraphDynamic programming+2No attempts yet2s512 MBJudgeable
Diamond MineGiven an R by C grid of 0s and 1s, find the largest size of a diamond shape (a 45-degree rotated square outline) formed entirely of 1s.Hard8Dynamic programmingBinary search+2No attempts yet0.75s128 MBJudgeable
UnicornCount the number of paths on an N by M letter grid where a chess unicorn piece spells out a given word, modulo 1e9+7.Hard8Dynamic programmingPrefix sum+2No attempts yet2s128 MBJudgeable
Palindrome SentencesGiven up to 13 distinct words, count ordered arrangements of a subset of them whose concatenation without spaces forms a palindrome.Hard8Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
A-HansuCount N-digit numbers with nondecreasing digits whose minimum partition into consecutive arithmetic-progression blocks is exactly A, modulo 1e9+7.Hard8CombinatoricsDynamic programming+2No attempts yet2s128 MBJudgeable
Jimin Kim's InvasionBlock every boundary-to-capital path on a grid using the fewest terrain cells, breaking ties by minimum total obstacle size.Hard8GraphShortest path+2No attempts yet2s128 MBJudgeable
Sticker CollectionGiven N stickers with prices and values, some already owned, find the minimum starting money so that after selling and buying, the total value owned reaches at least K.Hard8Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
Paper FoldingGiven an N by M grid of integers, repeatedly fold it along row or column lines so overlapping cells sum, and find the maximum value obtainable in any cell.Hard8Dynamic programmingIntervals+2No attempts yet2s128 MBJudgeable
ShuffleCount song sequences (repeatable, with genre transition rules and per-song lengths 1 to 9) whose total play time lies in [A, B], modulo a prime.Hard8Dynamic programmingMatrix+2No attempts yet2s128 MBJudgeable
Same TowersGiven up to 50 block heights summing to at most 500,000, find the maximum equal height achievable by two disjoint nonempty stacks, or report -1 if impossible.Hard8Dynamic programmingArray+1No attempts yet2s512 MBJudgeable
TteokgukPlace additional guards, subject to company office limits, so that the number of cooperation edges with exactly one guarded endpoint is minimized.Hard8GraphMinimum spanning tree+2No attempts yet2s128 MBJudgeable
Fibonacci KnapsackPick items whose weights are Fibonacci numbers into a bag of capacity C to maximize total value, where N is at most 50 and all numbers fit in 64 bits.Hard8Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Robot RaceGiven a grid with two robots and a shared command string, find the smallest starting position where robot Y is guaranteed to reach the target before robot F.Hard8BFSGraph+2No attempts yet2s128 MBJudgeable
Minimum Cost Connected CellsGiven an N by M grid of integers with N, M at most 9, find the minimum total cost over all connected sets of cells (empty set allowed).Hard8Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
Toy SterilizationGiven daily toy demands over D days and two sterilization services with different delays and costs, decide which used toys to sterilize or discard versus buying new ones to minimize total cost.Hard8GreedyGraph+2No attempts yet2s128 MBJudgeable
Increasing ListReplace every '?' in a string with a digit or comma to form the lexicographically smallest strictly increasing list of positive integers with no leading zeros, or print -1 if impossible.Hard8BacktrackingGreedy+2No attempts yet2s128 MBJudgeable
CoveringTile every X cell of a grid using unrotated 6-cell A pieces and 2-cell horizontal B pieces without overlap, printing the lexicographically smallest covering or -1 if impossible.Hard8Dynamic programmingBacktracking+2No attempts yet2s128 MBJudgeable
Misheard BinaryCount distinct binary strings obtainable by shifting each bit of an N-bit number at most D positions, then output the K-th smallest such string.Hard8Dynamic programmingCombinatorics+2No attempts yet2s128 MBJudgeable
Weather ForecastingChoose r horizontal and s vertical cut lines on an N x M grid to minimize the maximum sum of cell values inside any resulting rectangular section.Hard8Binary searchDynamic programming+2No attempts yet2s128 MBJudgeable
Coin Passing GameGiven biased left/right passing probabilities on a circle of N students starting at student K, compute the probability that student N is the last student to first receive the coin.Hard8ProbabilityDynamic programming+2No attempts yet2s128 MBJudgeable
Count Palindromic Word SequencesCount ordered sequences of given words, space-joined, whose concatenation (ignoring spaces) is a palindrome of length at most K, modulo a prime.Hard8Dynamic programmingString matching+2No attempts yet2s128 MBJudgeable
Make a Monotone SequenceGiven N nonnegative integers, build a monotone (non-decreasing or non-increasing) sequence minimizing the total absolute difference from the original.Hard8Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Boyle's LawCount positive integers N up to 10^18 whose self-product, N times the product of its digits, falls within a given range [A, B].Hard8MathDynamic programming+2No attempts yet2s128 MBJudgeable
Magic StoneGiven n, k, and i, find the i-th lexicographically smallest length-n I/X string with at most k differing adjacent pairs, treating a string and its reverse as identical.Hard8CombinatoricsDynamic programming+2No attempts yet2s128 MBJudgeable
Rich Person's Coin ExchangeGiven a huge target amount M (up to 10^18) and up to 1000 coin denominations each at most 10000, find the minimum number of coins summing exactly to M.Hard8Shortest pathGraph+2No attempts yet2s128 MBJudgeable
P-SequencesCount permutations of a set of distinct integers where no two adjacent elements have a difference divisible by P, for two test cases, modulo 1234567891.Hard8CombinatoricsDynamic programming+1No attempts yet2s256 MBJudgeable
Cave ExplorationFind the minimum total time to move all explorers across a bridge to the exit side, given one shared map, a weight-limited bridge, and trust rules for group crossings.Hard8Shortest pathBit manipulation+2No attempts yet2s128 MBJudgeable
Increasing SequenceSplit a digit string into pieces forming a strictly increasing sequence of numbers, minimizing the last value with tie-breaks favoring larger earlier numbers.Hard8Dynamic programmingString+2No attempts yet2s128 MBJudgeable
Merge WordsGiven up to 12 uppercase words, find the shortest string containing all of them as substrings, breaking ties by lexicographic order.Hard8Dynamic programmingBit manipulation+2No attempts yet5s128 MBJudgeable
Increasing SequenceSplit a huge digit string into pieces forming a strictly increasing sequence of numbers, breaking ties by minimizing the last piece then maximizing earlier pieces, and output the product mod 1,000,000,003.Hard8Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Protective TentsGiven non-overlapping horizontal tents, add horizontal segments above them so that every point of the interval between the leftmost and rightmost endpoints receives downward water.Hard8GreedyIntervals+2No attempts yet2s128 MBJudgeable
Quiz ShowFor N ordered quiz questions, choose right or wrong answers to maximize score: correct answers earn coins and points, hitting M coins gives a bonus, wrong answers reset coins and cost points.Hard8Dynamic programmingArray+2No attempts yet5s128 MBJudgeable
NetworkCount non-isomorphic trees on N+1 nodes where one fixed hub node has any degree but every other node must have odd degree.Hard8CombinatoricsTree+2No attempts yet2s128 MBJudgeable
Choosing GuitarsN guitars sit in a circle, and each turn the mover must take one guitar from every remaining contiguous group; find the max total value the first player can secure with optimal play.Hard8Dynamic programmingGame theory+2No attempts yet2s128 MBJudgeable
Increasing Arcade PathsCount monotone grid paths from (1,1) to (N,M) grouped by how many arcades they visit, valid only if visited arcade numbers strictly increase.Hard8Dynamic programmingCombinatorics+2No attempts yet2s128 MBJudgeable
Number ConcatenationGiven a subsequence left after deleting digits from the concatenation of 1,2,...,N, find the smallest N that could produce it.Hard8String matchingBinary search+2No attempts yet2s128 MBJudgeable
Random SortCompute the expected number of random inversion swaps needed to sort a permutation of size at most 8 into increasing order.Hard8ProbabilityDynamic programming+2No attempts yet2s128 MBJudgeable
Terminal CitiesGiven a connected graph with up to 15 cities, find a spanning tree that maximizes the number of vertices with degree exactly one.Hard8Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
Lucky-number SumGiven N, express it as a sum of numbers made only of digits 4 and 7, using the fewest terms and, among ties, the lexicographically smallest sequence.Hard8Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Polygon Dissection CountGiven a convex N-gon, count the number of ways to cut it with non-crossing diagonals into exactly K polygons, modulo 1000000000, or report impossibility.Hard8CombinatoricsDynamic programming+1No attempts yet2s128 MBJudgeable
Expected Repaints for BallsGiven N colored balls, compute the expected number of random repaint operations needed until all balls share one color.Hard8ProbabilityDynamic programming+2No attempts yet2s128 MBJudgeable
Chess PracticeGiven N queens on a board, players alternately shift a queen toward (0,0) using Wythoff-move rules, and the winner is decided by XOR-ing Grundy values via Sprague-Grundy theory.Hard8Game theoryDynamic programming+1No attempts yet2s128 MBJudgeable
Amazing MazeFind the minimum time to collect all treasures and reach the exit in a grid maze whose per-cell open door direction rotates clockwise every minute.Hard8BFSBit manipulation+2No attempts yet5s512 MBJudgeable
Monkey TowerCompute the minimum number of moves to solve a 4-peg Tower of Hanoi with up to one million disks, using the Frame-Stewart recurrence modulo 9901.Hard8Dynamic programmingMath+2No attempts yet2s128 MBJudgeable
DuelTwo players alternately mark empty cells on a strip, winning instantly by forming three consecutive marks, and the task is to decide if the first player can force a win and list all winning first moves.Hard8Game theoryCombinatorics+2No attempts yet2s128 MBJudgeable
Minimum Pairing Cost for Two SetsGiven two sorted sets S and T, choose pairs (one element from each) so every element in both sets appears in some pair, minimizing the total sum of |a-b| over chosen pairs.Hard8Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Complete Binary TreeGiven two same-height complete binary trees whose leaves carry a permutation of labels, find the largest label subset whose pairwise leaf distances match in both trees.Hard8Dynamic programmingTree+2No attempts yet5s128 MBJudgeable
Lattice Convex PolygonGiven a rectangle of size M by N, find the maximum number of vertices a convex lattice polygon can have while staying inside it.Hard8GeometryDynamic programming+2No attempts yet2s128 MBJudgeable
TaxiCount directed paths from intersection A to B in a one-way road DAG that pass through a given set of required intermediate intersections in any order.Hard8GraphDynamic programming+2No attempts yet2s256 MBJudgeable
Jang Hongjun the Tofu SellerGiven a grid of letter grades, tile it with non-overlapping 2x1 dominoes to maximize the sum of pairwise grade prices, leaving uncovered cells worth zero.Hard8GraphShortest path+2No attempts yet2s128 MBJudgeable
Minimum-Cost Number Matching (Hard)Given sorted sets S and T, choose pairs (s,t) with cost |s-t| so every element of both sets appears in at least one pair, minimizing total cost, for sizes up to 500000.Hard8Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Fence Escape Season IVGiven N horizontal fence segments Jimin must dodge by sidestepping to their endpoints, compute the minimum total horizontal movement to reach the exit below.Hard8Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Feeding the PandaFind the longest sequence of bamboo groves with strictly increasing tastiness where consecutive Manhattan distance stays within the destination's bamboo count.Hard8Dynamic programmingGeometry+2No attempts yet2s128 MBJudgeable
Marble SlabsFind the minimum wasted area when guillotine-cutting a rectangular slab into a set of allowed non-rotatable rectangle sizes.Hard8Dynamic programmingDivide and conquer+2No attempts yet2s128 MBJudgeable
Card FlippingGiven an R by 16 grid of target flip states, find the minimum number of contiguous row or column flip operations to turn all cards from face up to the required pattern.Hard8Dynamic programmingBit manipulation+2No attempts yet5s128 MBJudgeable
HighwayGiven an undirected graph where each road has a toll and a travel time, count the distinct Pareto-optimal (toll, time) pairs achievable by routes between two given cities.Hard8Shortest pathGraph+2No attempts yet2s128 MBJudgeable
AlleywaysFind the maximum-value path from node 1 to node n in a directed weighted graph, or report -1 if the value can grow without bound due to a positive cycle on a valid path.Hard8Shortest pathGraph+2No attempts yet2s128 MBJudgeable
Surprise Gift DeliveryGiven N delivery points on a line from a warehouse, find the minimum cost combining limited-capacity truck trips, per-stop parking fees, and one-at-a-time walking deliveries to drop a gift at every point.Hard8Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Palindrome EncodingGiven a binary string, repeatedly delete the second half of any even-length palindromic substring and find the minimum length achievable.Hard8Dynamic programmingString+2No attempts yet2s128 MBJudgeable
Banknotes for a New GameChoose K denominations starting at 1 won where each next one is 2, 3, 4, or 5 times the previous, to minimize the number of banknotes summing to N won.Hard8Dynamic programmingMath+2No attempts yet2s128 MBJudgeable
Food Wrap AreaGiven N food items on a 2-row by B-column grid, cover every food cell using at most K axis-aligned rectangular wraps while minimizing the total wrap area.Hard8Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Log TransportGiven a tree of villages flowing into a kingdom, choose k extra sawmill locations to minimize the total weight times distance cost of routing each village's logs to its nearest downstream mill.Hard8Dynamic programmingTree+2No attempts yet2s128 MBJudgeable
Tree Height ReductionGiven a rooted tree and target height H, find the minimum total cost of repeatedly reattaching vertices to ancestors (cost based on level gap) to bring the tree height down to at most H.Hard8TreeDynamic programming+2No attempts yet2s128 MBJudgeable
Broadcast NetworkPick which edges of a rooted tree to install so that total user fees minus installation cost stays non-negative while maximizing the number of served users, solved with tree knapsack DP.Hard8Dynamic programmingTree+2No attempts yet2s128 MBJudgeable
Building a Tree ModelGiven a tree, find the minimum number of non-branching path segments (strings) needed to cover every edge exactly once, then minimize the length of the longest such string.Hard8TreeDynamic programming+2No attempts yet2s128 MBJudgeable
Cave ExplorationFind the minimum-time simple cycle through room 1 in a directed graph built from asymmetric tunnel costs, using no room or tunnel twice.Hard8GraphShortest path+1No attempts yet1s256 MBJudgeable
SpiderwebGiven a convex polygon's vertices and circular puddles, find the maximum number of non-crossing diagonals that avoid all puddles.Hard8Dynamic programmingGeometry+2No attempts yet2s128 MBJudgeable
Roof ConstructionGiven N points and a limit K, find the minimum vertical offset needed so a concave polyline with at most K segments lies on or above every point.Hard8GeometryBinary search+2No attempts yet2s128 MBJudgeable
Clone RobotGiven a maze with a start and up to 250 keys, minimize the total moves of self-cloning robots (splitting only at start/key cells) needed to collect every key.Hard8Shortest pathMinimum spanning tree+2No attempts yet2s128 MBJudgeable
Hotel ReservationAssign men, women, and married couples to rooms with capacity/cost constraints under strict cohabitation rules, minimizing total rental cost or reporting impossibility.Hard8GreedyDynamic programming+1No attempts yet2s128 MBJudgeable