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
The Great Spamway StrikeChoose a rooted tree over zombies with allowed bidirectional links, minimizing the round-trip time for a gather broadcast that includes each node's per-message read lag.Medium7TreeDynamic programming+2No attempts yet1s128 MBJudgeable
SegmentsOn each row of an n by n grid you must walk the whole interval [L(i), R(i)], moving only left, right, or down; find the shortest path from (1,1) to (n,n).Medium7Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Hockey ScoresGiven unordered score pairs x-y, find the fewest monotone lattice paths from (0,0) that pass through all of them, since each hockey game is such a path.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Cheap GasOn an m by n grid with a fuel tank of capacity f, find the cheapest way to buy gas at priced stations while driving from (1,1) to (m,n), or report that the trip is impossible.Medium7GraphShortest path+2No attempts yet1s128 MBJudgeable
Pit Stop StrategyGiven lap and fuel burn formulas plus pit-stop costs, find the minimum race time for L laps without running out of fuel.Medium7Dynamic programmingMathNo attempts yet1s128 MBJudgeable
Snowball FightGiven fixed alternating throwing order and hit probabilities, players choose targets to maximize their team's win chance; compute win and draw probabilities under optimal play.Medium7Game theoryProbability+2No attempts yet1s128 MBJudgeable
Patisserie ACMGiven a hole-free connected polyomino of # cells, find the minimum number of axis-aligned rectangles whose union is exactly the shape, cutting only along grid lines.Medium7Dynamic programmingMatrix+2No attempts yet1s128 MBJudgeable
Shopping OffersGiven regular item prices and bundle offers, find the minimum cost to buy exactly the listed quantities without buying extras.Medium7Dynamic programmingArray+2No attempts yet1s512 MBJudgeable
Hidden CodesGiven code words and a long text, choose non-overlapping covering sequences, each at most 1000 long, maximizing the total length of the code words used.Medium7Dynamic programmingString matching+2No attempts yet1s128 MBJudgeable
Walk the TalkCount the number of distinct monotone paths (only right and/or up hops) through an H by W letter grid whose visited letters spell one of N given words.Medium7Dynamic programmingTrie+2No attempts yet1s128 MBJudgeable
Two SawmillsPlace two extra sawmills along a road so that every tree's downhill haul to the first mill at or below it is minimized.Medium7Dynamic programmingDivide and conquer+2No attempts yet1s128 MBJudgeable
TripGiven two strings, print all longest common subsequences in lexicographic order without duplicates.Medium7Dynamic programmingBacktracking+2No attempts yet1s128 MBJudgeable
Air RaidGiven a DAG, find the minimum number of vertex-disjoint paths that together cover every vertex.Medium7GraphDynamic programming+2No attempts yet1s128 MBJudgeable
ReadingCount non-empty lowercase words whose total adjacent-letter difference is at most N, modulo 1e9+7.Medium7Dynamic programmingCombinatoricsNo attempts yet5s128 MBJudgeable
RequestsGiven a cache of capacity K and N timed requests with expiration times, compute the minimum number of fetches over all offline replacement strategies.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Sailing RaceGiven sign positions on a line, find the visiting order minimizing the sum of cumulative distances, where each next sign adds the distance from the previous sign.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Task ExecutionGiven a DAG of N unit-time tasks, find the minimum completion time with unlimited processors, then the fewest processors that still achieve it.Medium7GraphTopological sort+2No attempts yet1s128 MBJudgeable
Restore the Expense IndentationGiven pre-order amounts where each parent equals the sum of its immediate children, recover the lexicographically smallest 0-based indentation depth for every line.Medium7Dynamic programmingGreedy+2No attempts yet1s1024 MBJudgeable
Multi-Element Binary Search TreeGiven sorted search probabilities and level-dependent node capacities, find the minimum expected number of comparisons for a multi-element BST.Medium7Dynamic programmingTree+1No attempts yet1s1024 MBJudgeable
RallyChoose a subset of at most 25 stations and fuel amounts to minimize total driving time plus refueling stops.Medium7Dynamic programmingImplementation+1No attempts yet6s128 MBJudgeable
Changing DigitsFind the largest number reachable from N by changing one digit at a time so that each new value's remainder modulo M strictly increases.Medium7Dynamic programmingGreedy+1No attempts yet1s1024 MBJudgeable
Swimming CompetitionGroup N swimmer times into consecutive sorted blocks of size between A and B, minimizing the largest within-group time difference.Medium7SortingDynamic programming+1No attempts yet1s1024 MBJudgeable
IOI PhotosEach order lists photo ranges on named rolls; choose for every roll to print individually, print the whole roll, or buy all rolls, minimizing total cost.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
An Old Stone GameFor each of up to 10 general trees, compute the minimum number of stones needed so that starting from the bucket you can place a stone on the root by combining stones at fully occupied siblings.Medium7TreeGreedy+2No attempts yet1s128 MBJudgeable
PipesGiven a grid of modules with costs on interior walls, find the minimum-cost cycle that visits every module exactly once, starting and ending at the service module.Medium7Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Minimax TriangulationFind the triangulation of a simple polygon minimizing the largest triangle's area, and report that area.Medium7Dynamic programmingGeometry+1No attempts yet1s128 MBJudgeable
Team Them UpSplit N people into two teams where teammates must mutually know each other, minimizing the size difference, and report the two team sizes.Medium7GraphDFS+2No attempts yet1s128 MBJudgeable
Shortest Regular Brackets SequenceGiven a string of brackets, find the length of the shortest regular bracket sequence that contains it as a subsequence.Medium7Dynamic programmingIntervals+2No attempts yet1s128 MBJudgeable
GangstersChoose a door state over time that changes by at most 1 per unit, starting at 0, to maximize the prosperity of gangsters whose stoutness matches the state at their arrival time.Medium7Dynamic programmingSorting+1No attempts yet1s128 MBJudgeable
Collecting BugsFind the expected number of days until a stream of random (category, subsystem) pairs has covered all n categories and all s subsystems.Medium7Dynamic programmingProbability+2No attempts yet2s64 MBJudgeable
Drawing WindowsGiven the boundary of a hole-free rectilinear polygon, compute the minimum number of non-overlapping axis-aligned rectangles that exactly partition it.Medium7GeometryDynamic programming+1No attempts yet1s128 MBJudgeable
Banal TicketsGiven a length-2N ticket pattern with unreadable digits, count how many fillings make the first half product equal the second half product, and how many do not.Medium7CombinatoricsDynamic programming+1No attempts yet1s512 MBJudgeable
Longest Common Increasing SubsequenceGiven two integer sequences, find the length of the longest common increasing subsequence of both.Medium7Dynamic programmingArray+2No attempts yet1s256 MBJudgeable
The Very Greatest Common DivisorEach input value is the determinant of a tridiagonal n by n matrix with 1 on the diagonal, 1 above, -1 below; find the gcd of two such determinants.Medium7Number theoryMath+2No attempts yet2s128 MBJudgeable
Dictionary of Obscene WordsGiven dictionary words and a text, find the length of the shortest prefix of the text containing some word as a subsequence.Medium7Dynamic programmingString+1No attempts yet1s128 MBJudgeable
EscapeFind the earliest time in the window [t, t+d) that James can reach the pickup cell, moving one cell per second with no U-turns and no waiting.Medium7BFSGraph+2No attempts yet2s128 MBJudgeable
Bargain or No BargainGiven prize values and a budget M, decide whether optimal play maximizing expected log utility yields expected prize money above M.Medium7Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
Boy ScoutGiven N points in general position, find the longest closed route that always turns strictly left at every step, counting distinct points visited.Medium7GeometryDynamic programming+1No attempts yet1s128 MBJudgeable
Edit DistanceGiven strings A and B up to length 17000, find the minimum number of insert, delete, and substitute operations to turn A into B.Medium7Dynamic programmingStringNo attempts yet8s128 MBJudgeable
Ball PaintingCount paint orders on a 2 by N grid where each new ball must touch an already painted ball, modulo 1e9+7.Medium7Dynamic programmingCombinatoricsNo attempts yet2s512 MBJudgeable
Matryoshka Dolls, AgainGiven N dolls each with three dimensions, nest them so every inner doll is strictly smaller on all three axes; minimize the number of outermost dolls.Medium7Dynamic programmingGraph+2No attempts yet1s128 MBJudgeable
G-Avoiding SequenceCount permutations of a set where consecutive elements never differ by a multiple of G, modulo a prime.Medium7Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
RectanglesFind the longest chain of rectangles where each rectangle's upper-right corner is strictly below and left of the next rectangle's lower-left corner.Medium7Dynamic programmingSortingNo attempts yet1s128 MBJudgeable
Making ChangeChoose the fewest coins whose subsets can form every amount from 1 to C given bounded supplies of each denomination.Medium7GreedyDynamic programming+1No attempts yet1s128 MBJudgeable
RobotFind the shortest travel time for a robot that moves at speed 1 and turns 1 degree per second, hopping between points within distance R.Medium7GraphShortest path+2No attempts yet1s128 MBJudgeable
Maximum Sum of K Non-Overlapping SubmatricesPick exactly K pairwise non-overlapping rectangular submatrices from an N x M matrix to maximize the sum of their elements.Medium7Dynamic programmingPrefix sum+2No attempts yet2s32 MBJudgeable
Tree GameOn a tree, players alternately move a token to an unchosen neighbor from Manco's start vertex; find all start vertices where Manco wins with optimal play.Medium7TreeGame theory+2No attempts yet1s64 MBJudgeable
Book-casePartition the books in alphabetical order across shelves of fixed width, allowing vertical books or horizontal stacks, to minimize total height.Medium7Dynamic programmingImplementation+1No attempts yet1s64 MBJudgeable
TriangulationGiven n and m, compute the sum of triangulation counts T_3 + ... + T_n of convex polygons, reduced modulo m.Medium7CombinatoricsMath+2No attempts yet1s32 MBJudgeable
Coloured LeavesGiven an unrooted tree whose leaves have fixed colors, choose an internal vertex as root and place the fewest labels so each leaf's color matches its last labeled vertex.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Map GeneratorGiven N planets each edge appears independently with probability P, find the probability that the resulting random graph is connected.Medium7Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Map Generator Returns (MG-II)Given N places and independent edge probability P, find the probability that the random graph on N vertices is connected.Medium7ProbabilityDynamic programming+2No attempts yet1s128 MBJudgeable
B-MatrixFind two non-overlapping all-zero rectangles in a binary grid maximizing the total number of cells they cover.Medium7Dynamic programmingMatrix+2No attempts yet1s128 MBJudgeable
Superstitious Skylab TowerGiven a valid floor label with no digit 4 and no substring 13, count how many forbidden numbers precede it, then multiply by the floor height.Medium7MathDynamic programmingNo attempts yet1s128 MBJudgeable
Central TreeFor each weighted tree, find the vertex minimizing the sum of weighted distances to all other vertices and output that minimum sum.Medium7TreeDFS+2No attempts yet3s128 MBJudgeable
Serial NumbersGiven up to 10 forbidden digit substrings, find the b-th smallest positive integer whose decimal form contains none of them as a substring.Medium7Dynamic programmingString matching+2No attempts yet1s128 MBJudgeable
Texture TileGiven an N x N image, find the largest square subimage whose top row equals its bottom row and left column equals its right column.Medium7Dynamic programmingHash map+1No attempts yet2s256 MBJudgeable
Bank NotesWith bounded supplies of each note denomination, find the fewest notes that sum exactly to k.Medium7Dynamic programmingGreedyNo attempts yet3s128 MBJudgeable
The BusFind a path from (1,1) to (n,m) moving only east and north that collects the maximum total of passenger weights at visited intersections.Medium7Dynamic programmingSorting+1No attempts yet3s512 MBJudgeable
SpiesGiven a functional graph where spy k shadows a_k, choose the largest subset S such that every member of S is shadowed by at least one spy outside S.Medium7GraphGreedy+1No attempts yet3s512 MBJudgeable
Printed-Circuit BoardsGiven a series-parallel circuit described recursively, find the minimum number of connections that must be routed on the top side so every unit is reached from the top.Medium7TreeDynamic programming+2No attempts yet3s128 MBJudgeable
ParcelGiven an n by n grid of 0 (arable) and 1 (waste), find the largest all-zero rectangle and print its area. n can be up to 2000.Medium7StackDynamic programming+2No attempts yet3s512 MBJudgeable
MinusesGiven a signed sum of distinct variables, find the fewest bracket pairs needed to turn the all-minus chain into an equivalent expression.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
BracketsCount the ways to fully bracket a minus chain so that the result equals a target expression with given signs, modulo 1e9.Medium7Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
ChainGiven which rings of a bytish chain are on a bar, find the minimum number of legal put-on/take-off moves to remove all rings.Medium7Dynamic programmingRecursion+2No attempts yet3s512 MBJudgeable
StripesGiven stripe lengths c, z, n, decide for each board length p whether the first player wins the impartial placement game.Medium7Game theoryDynamic programmingNo attempts yet3s512 MBJudgeable
MusketeersGiven a tournament matrix on n people in a circle, determine everyone who can be the last survivor when adjacent duels are scheduled in any order.Medium7Dynamic programmingGame theory+2No attempts yet1s128 MBJudgeable
MapPartition n populations into m groups to minimize the sum over each group of |value - group median|, where the median can be any value meeting the half-half condition.Medium7Dynamic programmingSorting+2No attempts yet3s128 MBJudgeable
PrimitivusGiven a set of ordered pairs, find the shortest sequence in which every pair appears consecutively at least once.Medium7GraphShortest path+2No attempts yet3s128 MBJudgeable
The Number of Symmetrical ChoicesGiven two word sequences of length n, count how many of the 2^n ways of picking one word per index produce a palindrome when concatenated.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
GenotypesGiven budding rules A1 -> A2 A3, decide for each target word whether it can be derived from some number of supergenes S, and report the minimum count.Medium7Dynamic programmingIntervals+2No attempts yet1s128 MBJudgeable
Even Palindrome DecompositionDecide whether a string can be split entirely into even-length palindromes, and if so report the minimum and maximum number of parts.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Professor SzuCount walks in a directed multigraph from each cottage to the main building, cap at 36500, and report which cottages have the most routes (or are unbounded).Medium7GraphDynamic programming+2No attempts yet3s128 MBJudgeable
Aesthetic TextSplit a sequence of words into lines of length at most m, minimizing the total absolute difference between consecutive line lengths.Medium7Dynamic programmingPrefix sumNo attempts yet1s128 MBJudgeable
Railway NetworkGiven a connected edge-weighted graph and at most 8 terminals, find the minimum cost edge set that keeps all terminals mutually connected.Medium7GraphShortest path+2No attempts yet1s128 MBJudgeable
The Great EscapeCount escape routes on an n by m grid where the driver enters at the bottom-left corner heading north, only goes straight or turns right, and never revisits an intersection.Medium7Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Ticket InspectorChoose k of the n-1 travel segments so that the total number of passengers present on at least one chosen segment is maximized.Medium7Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
HexerFind the shortest walk from town 1 to town n where each road can be used only after collecting swords for all monster kinds on it.Medium7Shortest pathGraph+2No attempts yet1s128 MBJudgeable
GuildsSplit the towns into two sets so that each set is a dominating set and the sets are disjoint, or decide it is impossible.Medium7GraphDFS+2No attempts yet1s128 MBJudgeable
MonotonicityFind the longest subsequence of a sequence whose adjacent comparison symbols repeat a given pattern of <, >, = of length k.Medium7Dynamic programmingBinary search+2No attempts yet3s512 MBJudgeable
The Minima GameTwo players alternately take any positive number of cards and score the minimum value in the taken set; find the optimal final score difference for the first player.Medium7GreedySorting+1No attempts yet3s512 MBJudgeable
Letter Frequency DifferencePick any contiguous fragment of a lowercase word to maximize the gap between its most and least frequent letters.Medium7Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
Tree RotationsGiven a binary tree with distinct leaf labels, find the minimum number of inversions in the left-to-right leaf sequence reachable by swapping children at branchings.Medium7Divide and conquerDynamic programming+2No attempts yet1s128 MBJudgeable
CloakroomFor each query (m, k, s), decide whether some items with a_i <= m and b_i > m+s have values summing to exactly k.Medium7Dynamic programmingSorting+2No attempts yet2s128 MBJudgeable
Around the WorldFind the cheapest closed walk from city 1 whose total eastward longitude differs from its westward longitude.Medium7GraphShortest path+1No attempts yet1s128 MBJudgeable
Winter Snow PlowingOn a tree, each edge must be traversed at least d_i times by one continuous walk; find the minimum total traversal count.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Alien InvasionFind the maximum total residents the aliens can abduct, given that a warning from an attacked city reaches city k one day later per unit distance.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
OrchardGiven an n by n grid of trees and empty cells, decide whether the whole grid can be split into exactly k axis-aligned rectangles, each containing at least one tree.Medium7Divide and conquerDynamic programming+2No attempts yet1s128 MBJudgeable
ClimbingEach of n pairs of climbers sits on adjacent routes with two positions a and b; maximize the number of adjacent climbers (across neighboring routes) that can share the same height under the rope constraints.Medium7Dynamic programmingGreedyNo attempts yet1s128 MBJudgeable
Squared WordsGiven a lowercase string, delete the fewest letters so the remaining letters, in order, form a squared word xx.Medium7Dynamic programmingStringNo attempts yet1s128 MBJudgeable
Bytie's DisplayReorder the digits of a seven-segment display and flip at most n segments so the result reads as the lexicographically largest l-digit number.Medium7GreedyDynamic programming+1No attempts yet1s128 MBJudgeable
Variable SubsequencesCount distinct nonempty subsequences, identified by position sets, in which every two consecutive terms differ.Medium7Dynamic programmingCombinatorics+1No attempts yet2s512 MBJudgeable
DiceGiven n and k, find the number of ways n fair dice can sum to k, then output the integer part of 100 times that probability.Medium7Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Type Two de Bruijn SequencesGiven a binary string, append the fewest digits so that every length-n binary word appears as a subsequence.Medium7GreedyString+1No attempts yet2s512 MBJudgeable
StudiesGiven a directed graph with edge weights, find every vertex that lies on a closed walk of positive total weight.Medium7GraphShortest path+1No attempts yet1s128 MBJudgeable
PotatoA convex polygon loses one piece per straight cut; maximize the remaining area after at most k cuts while removing every original rind point.Medium7GeometryDynamic programming+2No attempts yet1s128 MBJudgeable
BarricadesOn a tree, for each size k find the minimum number of edges to cut so that some connected component has exactly k vertices and no edges leave it.Medium7TreeDynamic programming+2No attempts yet1s128 MBJudgeable
SunsetsFor each cell of an n x n grid, output the tallest height among all cells within Manhattan distance k.Medium7Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
WordsGiven a word of length n, find the smallest number of blocks in a word that differs from it in at most k positions.Medium7Dynamic programmingStringNo attempts yet1s128 MBJudgeable
AntCount walks of exactly k edges from one cube vertex to another, never reusing the edge just used, modulo p.Medium7MatrixDynamic programming+2No attempts yet1s128 MBJudgeable