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,683 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Lights OutFind the shortest walk from room 1 to room 0 whose switches span exactly the set of reachable lamp states, counting repeated visits.Hard8GraphBit manipulation+2No attempts yet2s512 MBJudgeable
Boom!Count the ways to fold a strip of N segments so that no two chemically coated faces touch.Hard8Dynamic programmingCombinatorics+1No attempts yet2s512 MBJudgeable
Building BridgesPick a subset containing the first and last pillars, pay (h_i-h_j)^2 for each bridge section and w_i for each skipped pillar, and minimize the total.Hard8Dynamic programmingGreedy+1No attempts yet3s128 MBJudgeable
ChaseJerry walks a simple path in a tree, dropping up to v breadcrumbs that zero out neighbor pigeon counts; maximize the pigeons Tom later meets minus the pigeons Jerry met.Hard8TreeDynamic programming+1No attempts yet4s512 MBJudgeable
Embedding EnumerationCount the ways to place a labeled tree's nodes into a 2 by n grid so node 1 sits at the top-left, edges touch, and no cell repeats, modulo 1e9+7.Hard8TreeDFS+2No attempts yet4s512 MBJudgeable
Kitchen KnobsGiven n seven-digit knobs, find the fewest range rotations (each turning a contiguous block by the same amount) so every knob reads its maximum-power digit.Hard8GreedyImplementation+2No attempts yet3s512 MBJudgeable
The Great WallEach design picks two length-r intervals whose overlap height adds extra cost; find the k-th smallest total wall height over all interval pairs.Hard8Binary searchPrefix sum+2No attempts yet3s512 MBJudgeable
Fence InvasionCount how many distinct convex polygons can be formed as the convex hull of some subset of at least 3 of the given points, modulo 1e9+7.Hard8GeometryCombinatorics+2No attempts yet5s512 MBJudgeable
Mindol TourCount Hamiltonian cycles starting and ending at trampoline 0 in a graph where node 0 connects to all and node i reaches nodes within distance A_i, with A_i at least i.Hard8Dynamic programmingCombinatorics+2No attempts yet1s512 MBJudgeable
The Infosci Pirate CrewGiven N islands with coordinates, treasure values, and safe hardness, choose a monotone northeast path and a hardness interval to maximize collected value minus interval length.Hard8Dynamic programmingSorting+2No attempts yet1s512 MBJudgeable
Directing the TreeCount the orientations of a tree's edges such that every given vertex pair has a directed path one way or the other, modulo 1e9+7.Hard8TreeDFS+2No attempts yet2s256 MBJudgeable
Parallel LinesGiven up to 16 distinct points, pair them up to maximize the number of parallel pairs among the drawn segments.Hard8Bit manipulationDynamic programming+2No attempts yet10s512 MBJudgeable
Pizza DeliveryGiven a directed weighted graph with source 1 and target 2, each day flips the direction of one distinct edge; report whether the shortest path distance shrinks, stays equal, or grows (or becomes unreachable).Hard8GraphShortest path+1No attempts yet2s512 MBJudgeable
HomeworkGiven n assignments split into two courses with release days and deadlines, simulate fixed tie-break rules over adaptive coin choices and find the maximum and minimum number he can finish.Hard8Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
MarsFor each query substring, find the minimum number of bit flips that make it match no substring of the DNA, or report Impossible.Hard8String matchingDynamic programming+1No attempts yet2s512 MBJudgeable
RetroGiven a grid where the player moves horizontally while objects fall one row per turn, collect brackets to form the longest valid expression and output the lexicographically smallest one of that length.Hard8Dynamic programmingGreedy+2No attempts yet0.5s512 MBJudgeable
CesteFor each city, find the route from city 1 that minimizes the product of total travel time and total cost, or report -1 if unreachable.Hard8GraphShortest path+2No attempts yet2.5s128 MBJudgeable
Guardians of the LunaticsSplit a row of L cells into at most G contiguous nonempty blocks, where a block of length k multiplies each member's craziness by k, to minimize the total cost.Hard8Dynamic programmingDivide and conquer+2No attempts yet7s512 MBJudgeable
Off the RailsGiven n cities sorted by x, cover them with straight non-vertical segments so that the sum of squared vertical distances plus C per segment is minimized.Hard8Dynamic programmingGeometry+2No attempts yet5s512 MBJudgeable
Concert Attendance SchedulesCount the ways to pick increasing day positions matching a target band sequence, where each pick must wait h_b+1 days after that band's previous pick.Hard8Dynamic programmingStringNo attempts yet0.3s128 MBJudgeable
Binary TransformationsGiven starting bits, target bits, and per-bit costs, flipping a bit i costs the sum of costs of all bits equal to 1 after the flip; find the minimum total price to reach the target.Hard8Dynamic programmingGreedy+2No attempts yet1s256 MBJudgeable
TetrisOn a 3-wide, 10-tall Tetris board, pieces from a repeating shape sequence arrive forever; maximize how many land before the top fills, or output -1 if play can continue indefinitely.Hard8Dynamic programmingSimulation+2No attempts yet2.5s512 MBJudgeable
Canonical Coin SystemsGiven a sorted coin system, decide whether the greedy algorithm always makes change with the fewest coins, or whether some amount is a counterexample.Hard8Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Cat and MiceFind the smallest initial speed v so the cat can visit all points in some order, each arrival at or before its deadline, with speed multiplied by m after every meal.Hard8Binary searchDynamic programming+2No attempts yet2s512 MBJudgeable
Vera and Canada DayAfter each laser is added, choose one of four L-shaped firing orientations per laser so that the total awe from lasers hit by beams is maximized.Hard8Dynamic programmingGraph+2No attempts yet2s512 MBJudgeable
Vera and the Engineering BuildingsGiven a tree of N nodes with distinct hidden values and inspection costs, find the minimum total cost of an adaptive strategy that is guaranteed to locate a local maximum.Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
A Simple FunctionDefine f via a Pascal-like recurrence that resets to 0 whenever the sum is divisible by prime M, and answer up to 10^4 queries f(a, b, M) modulo 10^9+7.Hard8Number theoryCombinatorics+2No attempts yet1s512 MBJudgeable
DeforestationCut trees in a grid so the top-left and bottom-right cells become connected, minimizing the total walking time to cut each tree and haul it back to the mill.Hard8GraphShortest path+2No attempts yet2s512 MBJudgeable
Picking Numbers on a CirclePick exactly K numbers from a circle of N values so that no two chosen are adjacent, maximizing the sum.Hard8Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
K-Uniform StringCount binary strings of length N where, for each of M given intervals, every length-K substring inside it contains the same number of ones, modulo 1e9+7.Hard8Dynamic programmingCombinatorics+2No attempts yet1s256 MBJudgeable
Programming Duel TournamentChoose a duel schedule for N contestants, where the higher skill always wins and each contestant duels at most L_i times, to maximize total duel XOR interest minus fatigue.Hard8GreedyTree+2No attempts yet2s256 MBJudgeable
Making a Beautiful PuzzleFill each square of an N by M board with one of four colors so that orthogonal neighbors differ, maximizing total beauty and counting optimal placements modulo 1e9+7.Hard8Dynamic programmingBacktracking+2No attempts yet3s128 MBJudgeable
Tree SeparatorGiven a tree, delete all vertices on some simple path between two chosen vertices; maximize the number of remaining components of size at least K.Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
Coin SliderChoose the largest subset of at most 16 coins and an order of moves so no moving coin ever collides with a stationary or already-moved coin.Hard8GeometryBit manipulation+2No attempts yet2s512 MBJudgeable
MultisectGiven a hidden failing revision among n candidates and up to K simultaneous tests per round, find the strategy that minimizes expected total cost when a round with i failures costs T_i.Hard8Dynamic programmingBinary search+2No attempts yet2s512 MBJudgeable
Non-redundant DriveIn a tree where each node gives g fuel and each edge costs d, find the longest simple path from any start such that the running fuel never drops below zero, refueling once per node.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
Dango MakerChoose disjoint horizontal or vertical runs of three cells reading R, G, W in order on an N by M grid, maximizing how many such sticks fit.Hard8Dynamic programmingMatrix+2No attempts yet2s256 MBJudgeable
Commuter PassPick a shortest S-T path to make free, then find the minimum U-V travel cost, where edges on that path cost 0 and others cost their fare.Hard8GraphShortest path+1No attempts yet2s256 MBJudgeable
Maximum Interval Sum 2For a sequence with point updates, answer range queries for the maximum of U times a subarray sum plus V times its length minus one.Hard8Segment treeDivide and conquer+2No attempts yet1s256 MBJudgeable
Blocks 4Count the tilings of an N by M rectangle using blocks of size k by N (rotatable) for k from 1 to N, modulo 1999, where M can be as large as 1e10.Hard8Dynamic programmingMath+2No attempts yet1s256 MBJudgeable
Lifeguards (Platinum)Fire exactly K of N lifeguard shifts to maximize the total time covered by at least one remaining shift.Hard8Dynamic programmingSorting+2No attempts yet2s512 MBJudgeable
Cow at Large (Platinum)In a tree, for each barn find the minimum number of farmers placed at exits needed to catch Bessie, who starts there and runs for the nearest exit at equal speed.Hard8TreeDFS+2No attempts yet4s512 MBJudgeable
Ascending PhotoGiven a sequence of n heights, find the minimum number of cuts so the pieces can be reordered into a nondecreasing sequence.Hard8GreedySorting+2No attempts yet3s512 MBJudgeable
Hit of the SeasonFind the shortest print matrix over R, G, B that can reproduce a wallpaper string, where specified stripes must never be overprinted and at most 19 stripes are unspecified.Hard8StringBrute force+2No attempts yet2s512 MBJudgeable
The StagingGiven n gangsters each aiming at a distinct target, count survivors after each of q updates to the shooting time of one gangster.Hard8GraphDynamic programming+2No attempts yet2s512 MBJudgeable
The CaptainFind the minimum total north-south distance the Captain must steer on a route from island 1 to island n, where he handles one axis per leg.Hard8GraphShortest path+1No attempts yet2s512 MBJudgeable
Two tetrominoesPlace two non-overlapping tetrominoes anywhere on an N by M grid so the total of the covered cells is maximized.Hard8Brute forceDynamic programming+1No attempts yet2s512 MBJudgeable
Catch the PlaneChoose an adaptive strategy of buses to maximize the probability of reaching station 1 by time k, where each bus runs independently with a known probability.Hard8Dynamic programmingProbability+2No attempts yet10s1024 MBJudgeable
Gem IslandAt each of d steps a uniformly random gem splits in two; find the expected total held by the r largest holders after d splits.Hard8ProbabilityDynamic programming+2No attempts yet3s1024 MBJudgeable
xor gameCount sequences of n xor masks (each below 2^31) that carry a to b, modulo 1e9+7.Hard8MathCombinatorics+2No attempts yet0.5s128 MBJudgeable
New BarnsProcess online queries that add a leaf to a growing forest or ask for the eccentricity (distance to the farthest node) of a given node.Hard8TreeGraph+2No attempts yet2s512 MBJudgeable
DuathlonCount ordered triples (s, c, f) of distinct vertices such that some simple path visits s, then c, then f, in an undirected graph with n up to 1e5.Hard8GraphBFS+2No attempts yet1s1024 MBJudgeable
RecipeBuy ingredients on some days, hold each in the fridge until a later day, cook it there if freshness stays at least L_i, and maximize the total of F_i minus elapsed days times C_j; print Impossible if day N can't be a cooking day.Hard8Dynamic programmingGreedy+2No attempts yet1s1024 MBJudgeable
SixN has at most six distinct prime divisors; count the sequences of divisors greater than 1 where each new divisor shares a factor with at most one earlier entry, modulo 1e9+7.Hard8CombinatoricsMath+2No attempts yet2s512 MBJudgeable
ExperienceGiven a rooted tree with values on nodes, partition nodes into vertex-disjoint downward paths to maximize the sum over paths of (max value minus min value).Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
Namje AdventureN people hang at depths 1 to N and must reach the bottom depths D-N+1 to D; only the highest person can move down 1 to L steps, find the least total energy.Hard8Dynamic programmingGreedy+1No attempts yet3s512 MBJudgeable
Random Number GeneratorGiven how many values from 1 to N have been seen zero or one time, find the expected number of draws until every value appears at least twice.Hard8ProbabilityDynamic programming+2No attempts yet2s512 MBJudgeable
Sacred ScarecrowsCount subsets of empty cells in an R x C grid, modulo 1e9+7, such that every row has a scarecrow and every pair of consecutive columns has one.Hard8Dynamic programmingBit manipulation+2No attempts yet2s512 MBJudgeable
PathsCount simple paths in a vertex-colored graph where every vertex on the path has a distinct color, counting both directions separately.Hard8GraphDFS+2No attempts yet3s1024 MBJudgeable
Nordic CampingGiven a grid with rocky cells blocked, answer queries each asking for the area of the largest all-usable square subgrid that contains a specified water source cell.Hard8Dynamic programmingBinary search+2No attempts yet2s512 MBJudgeable
Split and MergeGiven two tilings of a 1xL board by 1x1 and 1x2 pieces, find the minimum number of split/merge operations to transform one into the other and count the ways.Hard8Dynamic programmingCombinatorics+2No attempts yet1s512 MBJudgeable
Global warmingChoose one contiguous interval and a shift d with |d| <= x, then find the maximum possible length of a strictly increasing subsequence of the modified sequence.Hard8Dynamic programmingBinary search+2No attempts yet2s512 MBJudgeable
ToysFor a given n, find every total toy count m whose partitions into type-quantities number exactly n.Hard8Number theoryCombinatorics+2No attempts yet4s512 MBJudgeable
Монгол ардын үлгэрChoose a subset whose size is at most the total weight of the remaining stones, maximizing the value of that chosen subset.Hard8Dynamic programmingSorting+2No attempts yet2s512 MBJudgeable
Willy Feels GuiltyBuy, throw, or swap products so the delivered sequence realizes a fixed menu at minimum total cost.Hard8String matchingGreedy+1No attempts yet2s512 MBJudgeable
Amateur Radio NetworkSplit at least 4 points into two groups of size at least 2 minimizing the largest same-group pairwise distance, and output that diameter rounded up to 0.01.Hard8GeometryBinary search+2No attempts yet2s512 MBJudgeable
Hiding MerlinDecompose a digit string into concatenated perfect squares, each at most 10 digits and starting with 1 to 9, and report the smallest possible total sum.Hard8String matchingDynamic programming+2No attempts yet4s512 MBJudgeable
Office RelocationGiven a weighted tree with marked query and leaf-coloured vertices, compute for every marked vertex the sum of squared weighted distances to coloured leaves (mod a prime).Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
Club Room ExpansionGiven each cell's count of walled directions (0 to 4), decide whether the grid can be fully partitioned into connected rooms of one to three cells fitting that wall count.Hard8Dynamic programmingBacktracking+2No attempts yet1s512 MBJudgeable
Racial DiscriminationWith up to 10 categories and 200 people, each with a selected flag, choose at most c categories and a rule on their bit patterns that misclassifies as few people as possible, and output that minimum.Hard8Bit manipulationBrute force+2No attempts yet2s512 MBJudgeable
Liar GameFor N cards (one Joker) and R rounds, compute the probability of scoring K points, times (2*N)^R, modulo 1000003.Hard8CombinatoricsDynamic programming+2No attempts yet2s512 MBJudgeable
UtilitarianismPick k tree edges with no shared endpoints to maximize total value; the answer is a matching-style DP with a slope-trick lambda search over edge weights.Hard8TreeDynamic programming+2No attempts yet5s1024 MBJudgeable
Balcony RepairsGiven a huge R by C grid with at most 1000 blocked cells, place horizontal dominoes on free cells to maximize the count, then report that maximum and the number of ways modulo 1e9+7.Hard8Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Finding Tricky NumbersGiven A and K up to 10^18, find the K-th positive integer whose adjacent digits differ by at least A, and print it modulo 10^9+7.Hard8Dynamic programmingBinary search+2No attempts yet1s512 MBJudgeable
ClustersPartition companies 1..N into contiguous clusters, each led by its first or last company whose limit L_i caps the size, minimizing the sum of C_i*S + T_i over leaders.Hard8Dynamic programmingPrefix sum+2No attempts yet3s1024 MBJudgeable
Memory ManagerMove k pointers among blocks to cover each query's set, paying s_i unless already covered; minimize total cost, with initial position free.Hard8GreedyDynamic programming+2No attempts yet3s512 MBJudgeable
Similar WordsGiven a set of distinct words, choose as many prefixes as possible so that no two chosen words differ by deleting one leading letter.Hard8TrieTree+2No attempts yet4s512 MBJudgeable
Eleventh BirthdayCount permutations of cards whose concatenation is divisible by 11, where cards count as distinct and equal numbers still give separate permutations.Hard8Dynamic programmingCombinatorics+1No attempts yet4s512 MBJudgeable
Masha and CactusChoose a maximum-weight subset of extra edges whose tree paths keep each vertex in at most one cycle, by a subtree DP with lazy updates on the path to the root.Hard8TreeDynamic programming+2No attempts yet4s512 MBJudgeable
Eating Everything EfficientlyFollow a directed path from stall 0 and choose stalls to eat with halves 1, 1/2, 1/4, ..., maximizing the weighted satisfaction.Hard8Dynamic programmingGraph+1No attempts yet3s512 MBJudgeable
KALLAX ConstructionGiven a chain of companies that each combine previous pack sizes to reach target sizes, find the smallest advertised pack guaranteeing at least B bolts.Hard8Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
Harry the HamsterOn a directed weighted graph, Max and Min alternately choose the outgoing edge, Max moving first; compute the total travel time from s to t under optimal play.Hard8Game theoryDynamic programming+2No attempts yet3s512 MBJudgeable
King's ColorsCount proper colorings of a rooted tree with n nodes using exactly k labeled colors, modulo 1000000007, where every color must appear at least once.Hard8TreeDynamic programming+2No attempts yet1s512 MBJudgeable
HorsemeetTwo knights move randomly to legal knight-move squares on an 8x8 board; find which knight has the higher probability of being the first to land on the other's square.Hard8ProbabilityGraph+2No attempts yet2s512 MBJudgeable
LightingCount N-bit b such that standard addition a+b yields exactly K set bits, using digit DP over the carries of the binary addition.Hard8Dynamic programmingBit manipulation+1No attempts yet2s512 MBJudgeable
Numbers GeneratorGiven up to ten H/T patterns of the same length, compute the expected number of fair coin flips until one pattern first appears contiguous.Hard8String matchingHash map+2No attempts yet2s512 MBJudgeable
TV Show GameAssign each of k lamps red or blue so that every one of n triples of color guesses has at least two matches, or report impossible.Hard8Dynamic programmingBrute force+2No attempts yet1s512 MBJudgeable
Count the BitsGiven k and b, count the total number of 1-bits in all multiples of k from 0 to 2^b-1, and print the sum modulo 10^9+9.Hard8Dynamic programmingBit manipulation+1No attempts yet2s512 MBJudgeable
KnockoutGiven remaining digits 1-9 and a dice total, choose a subset summing to that total that minimizes or maximizes the expected final number read from the leftover digits under optimal play.Hard8Dynamic programmingBit manipulation+2No attempts yet2s512 MBJudgeable
Joining CapitalsConnect all capitals with degree exactly one through Steiner points (non-capitals) at minimum Euclidean total cost.Hard8GraphMinimum spanning tree+2No attempts yet2s512 MBJudgeable
Modified SATGiven a CNF formula whose clauses each have at most 3 literals, decide whether there is an assignment with exactly 1 or exactly 3 true literals per clause, and print the lexicographically largest such assignment.Hard8Dynamic programmingGreedy+1No attempts yet2s512 MBJudgeable
Decorating a Christmas TreeCount binary trees with exactly L levels and N distinct nodes, ordered by level and by a preorder placement rule, modulo 100030001.Hard8Dynamic programmingTree+2No attempts yet1s512 MBJudgeable
k-Maximum SubarraysPick k disjoint contiguous subarrays of an array with maximum total sum; output only that sum.Hard8Dynamic programmingDivide and conquer+2No attempts yet2s512 MBJudgeable
Travel the SkiesGiven flights with capacities between airports over a window of days, and customers starting at each airport-day, decide whether every flight can be filled to capacity when each customer flies at most once per day and may depart on or after their start day.Hard8GraphDynamic programming+1No attempts yet2s512 MBJudgeable
Tima goes to XentopiaFind the cheapest S-to-T walk using exactly k1 red and k2 blue edges, any number of white edges, with edges reusable.Hard8Shortest pathGraph+2No attempts yet2s512 MBJudgeable
KhansFind the maximum food the khans can eat in K years walking on an N by M grid over growing cell values, never revisiting a cell before it returns to its maximum.Hard8Dynamic programmingHash map+2No attempts yet2s64 MBJudgeable
DiscsAssign nested discs to N given lattice centers and choose radii so every pair of discs is nested, minimizing the total radius sum.Hard8GeometryDynamic programming+2No attempts yet1s512 MBJudgeable
Fair TournamentArrange 2^N players in a knockout bracket so player 1 wins every match, minimizing the sum of the efforts paid along the way; print -1 if impossible.Hard8Dynamic programmingBit manipulation+2No attempts yet2s512 MBJudgeable
Access PointsPlace n teams so both coordinates are nondecreasing along IDs, minimizing the sum of squared distances to fixed access points.Hard8Dynamic programmingDivide and conquer+2No attempts yet1s512 MBJudgeable
Adding ParenthesesParenthesize a single-digit expression with non-nested single-operator parentheses to maximize its left-to-right value.Hard8Dynamic programmingRecursion+2No attempts yet0.5s512 MBJudgeable