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 results2,743 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Ladder GameGiven a ladder (Amidakuji) whose bars have depths, find every bar that can be removed without changing the permutation it induces.Medium7SimulationGreedy+2No attempts yet1s512 MBJudgeable
Thread KnotsPlace one integer knot on each of n given intervals so that the smallest gap between any two knots is maximized, and print that optimum.Medium7Binary searchGreedy+2No attempts yet1s512 MBJudgeable
ReMorseAssign prefix-free Morse label sequences to letters so the encoded message length (symbols plus gaps) is minimized, and report that minimum.Medium7GreedySorting+2No attempts yet1s512 MBJudgeable
Know your AliensGiven a human/alien label for each even number 2 to 2N, build the lowest-degree monic or anti-monic integer polynomial whose sign at 2i matches the label.Medium7MathDivide and conquer+2No attempts yet2s512 MBJudgeable
AssimilationGiven n planets with populations and k starting ships, an invasion needs ships >= population and a mobilization on a conquered planet yields ships equal to its population; find the minimum mobilizations to conquer all planets, or -1.Medium7GreedySorting+2No attempts yet1s512 MBJudgeable
FrogsGiven n frogs at positions 1..n, each with reach r_i and skill s_i, pick three frogs that share a common reachable stone and maximize the sum of their skills.Medium7GreedySorting+2No attempts yet3s512 MBJudgeable
Deep800080Place a point on a line so that a disk of fixed radius R centered there covers as many of N given points as possible; output the maximum count.Medium7GeometrySorting+2No attempts yet2s512 MBJudgeable
Bogo SortSort a hidden permutation using only calls that randomly shuffle a chosen contiguous segment and report the shuffled result.Medium7SortingProbability+2No attempts yet4s1024 MBJudgeable
Bad Hair Day and Expected ValueGiven N cows with heights, count the expected number of visible pairs over all N! orderings, modulo 1e9+7.Medium7CombinatoricsMath+2No attempts yet2s512 MBJudgeable
Stealing CarrotsEach carrot appears on a fixed cycle and gains taste by a fixed increment while present; the rabbit eats at most one carrot per day and wants the maximum total taste.Medium7GreedySorting+2No attempts yet1s512 MBJudgeable
Allergic AronGiven a weighted tree, choose a connected set of edges maximizing (number of edges) times (minimum edge weight in the set).Medium7TreeUnion-find+2No attempts yet1s512 MBJudgeable
SpringboardsGiven up-and-right springboards that teleport Bessie from (x1,y1) to (x2,y2), find the minimum walking distance from (0,0) to (N,N).Medium7Dynamic programmingSorting+2No attempts yet2s512 MBJudgeable
Wormhole SortPermutation of cows at locations with weighted wormholes; maximize the minimum wormhole width used to place every cow at its own location.Medium7Union-findGraph+2No attempts yet2s512 MBJudgeable
HoldingYou may swap any two positions at cost equal to their distance; with budget K, minimize the sum of values in the fixed segment [L, R].Medium7GreedySorting+2No attempts yet2s256 MBJudgeable
Fountain SpotsPlace K houses at distinct integer positions on a line so that the total distance from each house to its nearest fountain spot is minimized, given N fountain positions.Medium7GreedySorting+2No attempts yet1s256 MBJudgeable
JeopardyPlayers alternately delete one row then one column from an n by n grid until one cell remains; the first player maximizes and the second minimizes that cell's value.Medium7Game theoryGreedy+2No attempts yet2s512 MBJudgeable
Jumping JunipersMove each tree to a distinct positive integer position within its allowed interval so that the total distance from the house is minimized.Medium7GreedySorting+2No attempts yet4s512 MBJudgeable
BingoPlace one token in each column of an N x M matrix, minimizing first the spread of token counts across rows, then the largest token value.Medium7GreedyBinary search+2No attempts yet1s512 MBJudgeable
Japanese FoodSimulate a restaurant where the cook batches identical dishes across pending orders under per-dish limits, and report each order's completion time.Medium7SimulationImplementation+2No attempts yet1s512 MBJudgeable
Twin BuildingsGiven N rectangular lands, find the maximum area A×B of two identical rectangles placed either on separate lands or both on one land, printed with one decimal.Medium7SortingGreedy+1No attempts yet2s512 MBJudgeable
Pirates and TreasureTwo players alternately take chests, each valuing them differently; find the final difference when both play optimally.Medium7GreedySorting+2No attempts yet1s256 MBJudgeable
TributeGiven all 2^n - 1 non-empty subset sums, recover the n positive values they came from, or report that the answer is missing or not unique.Medium7SortingGreedy+2No attempts yet15s512 MBJudgeable
Connect the ForestGiven a weighted forest, add disjoint vertex pairs (each vertex used at most once) so the graph becomes connected, minimizing the sum of the paired values, or report Impossible.Medium7GreedySorting+2No attempts yet2s256 MBJudgeable
Longest Increasing SubsequenceGiven target LIS-ending lengths f_i, construct a permutation of 1..n whose longest increasing subsequence ending at position i has length exactly f_i.Medium7GreedySorting+2No attempts yet1s256 MBJudgeable
Dreamoon and NightMarketGiven N food prices, find the total cost of the K-th cheapest non-empty subset, where subsets are ordered by the sum of their prices.Medium7SortingHeap+2No attempts yet1s512 MBJudgeable
We Need MasksEach citizen accepts mask prices in a range [L, R], each store sells X masks at price P, and we must match as many citizens to masks as possible.Medium7GreedySorting+2No attempts yet3s1024 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
ArcadeEach hand moves one button per second between presses; find the minimum number of hands that can cover all M presses.Medium7GreedySorting+2No attempts yet1s1024 MBJudgeable
Fuel StationFind the minimum starting fuel F so Pengu reaches distance D, where each station i adds Ai litres if the starting F is at most Bi.Medium7Binary searchGreedy+2No attempts yet3s512 MBJudgeable
PilotFor each of Q altitude limits, count subarrays of heights whose maximum is at most that limit.Medium7StackSorting+2No attempts yet1s512 MBJudgeable
Dividing the KingdomGiven n distinct integer-half points in the plane, output at most n-1 axis-parallel lines at integer coordinates so that no two points share a region.Medium7Divide and conquerGeometry+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
Company MergingGiven n companies with employee salaries, repeatedly merge two companies whose maximum salaries are equal, raising every salary in a company by one uniform amount, and minimize the total raise.Medium7GreedySorting+2No attempts yet1s512 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
Magic SwordsGiven n ages, build a forest where each node has at most two children and every child is at least k years younger than its parent, or report that none exists.Medium7GreedySorting+2No attempts yet2s512 MBJudgeable
Broken Line 03Find an axis-aligned broken line from the origin that visits every dot, minimizing the number of segments; output-only with partial scoring.Medium7GeometryGreedy+2No attempts yet0.1s512 MBJudgeable
Broken Line 07Construct a rectilinear broken line from the origin that passes through all given dots, minimizing the number of segments; this is an output-only optimization task.Medium7SortingGreedy+1No attempts yet0.1s512 MBJudgeable
Cyclic Shift Dot ProductRotate two length-N sequences by any amounts to maximize their dot product, and print that maximum.Hard8CombinatoricsMath+1No attempts yet1s512 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
GlovesGiven per-color counts of left and right gloves, find the pair (x, y) with minimum x+y (smallest x on ties) so that any draw of x left and y right gloves always yields a matching color pair.Hard8Bit manipulationGreedy+2No attempts yet2s128 MBJudgeable
Fastest Grid RouteFind the minimum travel time between two grid intersections when rectangular districts change the per-block cost of roads inside them.Hard8Shortest pathGraph+2No attempts yet3s512 MBJudgeable
Closest PointsGiven up to 150,000 3D points, find the minimum squared distance between distinct points and count how many pairs achieve it, treating duplicate coordinates as one point.Hard8Divide and conquerGeometry+2No attempts yet1s128 MBJudgeable
Floor PlanGiven an outer rectangle and inner rectangles drawn inside it, count the number of enclosed office regions and find the area of the largest one.Hard8Union-findGeometry+2No attempts yet2s128 MBJudgeable
Kruskal's BallGiven a graph with unique edge weights, build a Kruskal reconstruction tree to answer queries about the minimum temperature needed to connect two vertices and the size of the reachable component at that temperature.Hard8Minimum spanning treeUnion-find+2No attempts yet2s128 MBJudgeable
Fugitive MonkeyGiven a graph with edge travel times and per-city delay values, answer many queries for the minimum path cost from S to T where cost equals edge sum plus the maximum node delay on the path.Hard8Union-findShortest path+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
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
Freight TrainGiven two trains as unions of intervals of occupied cars, find the smallest forward shift of one train that maximizes the count of aligned occupied cars.Hard8IntervalsMath+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
Right TrianglesGiven up to 1500 distinct 2D points, count how many of the triangles formed by choosing three points are right triangles.Hard8GeometryMath+2No attempts yet5s256 MBJudgeable
Kangho the Part-Time WorkerGiven N customers each with a planned tip, choose the serving order to maximize the total tip after subtracting (position-1) from each tip and clipping negative values to zero.Hard8GreedyHeap+2No attempts yet2s256 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
DistancesGiven up to 100,000 planar points, compute the farthest and closest pair distances under Euclidean (squared), Manhattan, and Chebyshev metrics.Hard8GeometryDivide and conquer+2No attempts yet1s256 MBJudgeable
Maximum Volume from Orthogonal ProjectionsGiven two convex polygon projections of a 3D solid onto the xz and yz planes, compute the maximum possible volume of a convex solid consistent with both.Hard8GeometryMath+2No attempts yet2s128 MBJudgeable
Two Points with the Greatest SlopeGiven N points with distinct x and y coordinates, find the pair whose line has the largest absolute slope, breaking ties by smallest indices.Hard8Divide and conquerGeometry+2No attempts yet2s128 MBJudgeable
GradeGiven N exam score/total pairs, find every count D of excluded exams for which some other exclusion beats removing the D lowest-percentage exams.Hard8Binary searchGreedy+2No attempts yet2s128 MBJudgeable
Task OrderGiven a tournament-like directed graph on N tasks where every pair has at least one direction, partition all tasks into the minimum number of directed paths covering each node once.Hard8GraphGreedy+1No attempts yet2s128 MBJudgeable
Visible Mountain RangeCompute the total visible area of overlapping isosceles triangular mountains that share a common baseline, given up to 100,000 triangles.Hard8GeometrySorting+1No attempts yet2s128 MBJudgeable
Surveillance RobotDetermine every x-axis interval where a robot could stand so that the angular sweep order of chimneys matches a given observed shape sequence.Hard8GeometrySorting+1No attempts yet2s128 MBJudgeable
Perimeter of a Rectangle UnionCompute the total outer perimeter of the union of up to 5000 axis-aligned rectangles using a sweep-line approach.Hard8SortingGeometry+1No attempts yet2s128 MBJudgeable
Dividing Election DistrictsPartition 3K cities into three groups of K cities each so that at least two groups have total supporters exceeding 500K, given a guaranteed feasible instance.Hard8GreedySorting+1No attempts yet2s128 MBJudgeable
Building Prison WallsGiven a prison point and N surrounding posts, determine the maximum number of nested, non-touching polygon layers (each vertex a post, minimum size 3) fully enclosing the prison that can be formed.Hard8GeometryGreedy+1No attempts yet2s128 MBJudgeable
RaceGiven starting positions and speeds of N spaceships, count all future overtakes and list the first 10000 in chronological (and positional) order.Hard8Divide and conquerSorting+2No attempts yet2s128 MBJudgeable
Building Profit PlanGiven points with profits, select a subset maximizing total profit such that every chosen point sees other chosen points only in diagonal quadrant pairs (1,3) or (2,4) relative to itself.Hard8Dynamic programmingSorting+1No attempts yet2s128 MBJudgeable
Union Area of Right Isosceles TrianglesCompute the total area covered by the union of up to 2000 axis-aligned right isosceles triangles with integer coordinates.Hard8GeometrySorting+1No attempts yet2s128 MBJudgeable
Wedding ProcessionArrange all guests in a line minimizing the sum of adjacent height differences while keeping the given lion subsequence order fixed.Hard8Dynamic programmingGreedy+1No attempts yet2s128 MBJudgeable
Binary Sequence RotationGiven the last column of a sorted matrix of all circular rotations of an unknown binary string, reconstruct the lexicographically smallest rotation (first row) or report impossibility.Hard8String matchingSorting+2No attempts yet2s128 MBJudgeable
Visible SquaresGiven up to 1000 non-overlapping axis-aligned integer squares, count how many are visible from the origin by angular occlusion reasoning.Hard8GeometrySorting+1No attempts yet2s128 MBJudgeable
Total Length of Grid Segments in a PolygonGiven a simple polygon with integer vertices, compute the total length of grid line segments strictly inside the polygon.Hard8GeometrySorting+1No attempts yet1s128 MBJudgeable
Simple RectanglesGiven the vertex sequence of a rectilinear polygon path with crossing segments, count how many resulting regions are empty rectangles.Hard8GeometrySorting+1No attempts yet1s128 MBJudgeable
Largest Region in a Rectilinear PolygonGiven a self-intersecting rectilinear polygon, find the maximum area among the simple polygonal regions its edges partition the plane into.Hard8GeometrySimulation+1No attempts yet1s128 MBJudgeable
Planet TunnelsGiven N 3D points with edge cost equal to the minimum coordinate-axis distance between two points, find the minimum spanning tree cost connecting all of them efficiently.Hard8Minimum spanning treeSorting+1No attempts yet1s128 MBJudgeable
Wall and NailsRepeatedly compute the convex hull area of a shrinking nail set as extreme points (leftmost, rightmost, highest, lowest) are removed one by one.Hard8GeometryDivide and conquer+1No attempts yet1s128 MBJudgeable
GrasshopperGiven an N×N grid and a special knight-like move rule requiring strictly increasing petal counts, find the longest such path starting from a given cell.Hard8Dynamic programmingMatrix+1No attempts yet4s128 MBJudgeable
Frog PrincessSimulate a frog jumping to the nearest plant along diagonal directions, removing the departed plant each time, over up to 100,000 moves and plants.Hard8Segment treeSimulation+2No attempts yet1s128 MBJudgeable
HighwayGiven entry and exit points of N trucks, reassign entry tickets to exit interchanges (no truck keeping its own ticket) to minimize total absolute-difference toll.Hard8GreedySorting+1No attempts yet1s128 MBJudgeable
Wangnuni the FrogFind the path from leaf 1 to leaf N using only rightward or upward axis-aligned jumps costing K power each, that maximizes leftover power after eating flies along the way.Hard8Dynamic programmingSorting+1No attempts yet1s128 MBJudgeable
Number of Right TrianglesGiven up to 1500 planar points, count triples forming a right triangle, requiring an approach faster than brute force O(N^3).Hard8MathGeometry+1No attempts yet1s128 MBJudgeable
Rectangles in Three DimensionsGiven N axis-aligned rectangles in 3D each parallel to one coordinate plane, count pairs of rectangles that intersect in at least one point.Hard8GeometrySorting+2No attempts yet1s128 MBJudgeable
Study Leader HongjunMaintain a dynamic set of (A,B) student pairs supporting insertion and queries for the student with minimal B difference (tie-broken by minimal A difference) among those with B >= B_i and A > A_i or (B=B_i and A>A_i).Hard8Segment treeBinary search+1No attempts yet3s128 MBJudgeable
FlowersFor each flower, find the rectangle formed by nearest boundary hits in four directions and count strictly interior flowers, using offline sweeps and range structures.Hard8SortingSegment tree+1No attempts yet1s128 MBJudgeable
Red Points and Blue PointsGiven red and blue points on a plane, find two parallel lines (avoiding all points, excluding all blue points from the strip) that maximize red points strictly between them.Hard8GeometryBinary search+1No attempts yet1s128 MBJudgeable
ElephantGiven N distinct 2D points, find the length of the longest strictly increasing chain in both coordinates and count how many such maximum chains exist modulo 1e9+7.Hard8Dynamic programmingSorting+1No attempts yet3s128 MBJudgeable
Very Visible Point PairsAfter each incremental point insertion, count pairs of points whose axis-aligned bounding rectangle contains no other current point, distinct x and y coordinates guaranteed.Hard8Divide and conquerGeometry+2No attempts yet1s128 MBJudgeable
Wedding TrainArrange N guests in a line minimizing total adjacent height difference while keeping K given family members in a fixed relative order.Hard8Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Printed Circuit BoardGiven a simple polygon and an external origin point, find all polygon vertices that can be connected to the origin by a segment not crossing any polygon edge.Hard8GeometrySorting+1No attempts yet0.1s32 MBJudgeable
Logo MatchingGiven a permutation pattern of length n and a sequence of m distinct heights, find all starting positions where a length-n window matches the relative order pattern.Hard8String matchingArray+1No attempts yet2s128 MBJudgeable
HotelGiven rooms with capacity and upkeep costs and requests with offered rent and minimum capacity, choose at most o request-room assignments maximizing total rent minus upkeep.Hard8GreedyHeap+1No attempts yet4s128 MBJudgeable
Insertion Sort vs Quicksort ComparisonsCount permutations of 1..N where insertion sort's comparison count exceeds quicksort's by between 1 and X, modulo 1234567.Hard8Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
TrianglesGiven K points and M triangles each having the origin as one vertex, decide for each triangle whether any point lies strictly inside it, using geometric queries efficient for up to 100000 points and triangles.Hard8GeometrySorting+1No attempts yet1s128 MBJudgeable
DominanceGiven up to 3000 colored squares each with a Manhattan-distance attack range on a huge grid, count how many grid cells are dominated by white versus black using a diamond-shaped coverage counting technique.Hard8GeometryPrefix sum+1No attempts yet2s128 MBJudgeable
WalkCompute the shortest grid path length from (0,0) to (X,Y) avoiding up to 100,000 non-overlapping rectangular buildings that only occupy positive x squares.Hard8GeometryShortest path+2No attempts yet2s64 MBJudgeable
PeaksGiven an elevation grid, find every peak flat-region and for each compute the maximum possible minimum elevation on a path leading to some strictly higher peak, using union-find over sorted elevations.Hard8Union-findSorting+1No attempts yet1s128 MBJudgeable
ShortcutGiven a self-avoiding grid walk of unit segments, find the shortest horizontal or vertical connector between two visited break points that is not already part of the path, with tie-breaking rules.Hard8GeometryHash map+2No attempts yet1s128 MBJudgeable
November RainGiven non-intersecting sloped roof segments, compute for each segment how much rainwater (falling vertically, then sliding down slopes and shielded by segments above) drains off its lower end.Hard8GeometrySorting+1No attempts yet1s128 MBJudgeable
Horizontally Visible SegmentsGiven disjoint vertical segments, count triangles formed by triples that are pairwise horizontally visible using a sweep and visibility structure.Hard8SortingGeometry+1No attempts yet1s128 MBJudgeable
Dividing the GemsSimulate an alternating gem-picking game where one player greedily picks by fixed rules while the other plays optimally to maximize his own total, tie-breaking for the opponent's total, and output final scores.Hard8GreedyGame theory+1No attempts yet1s128 MBJudgeable
Final RankingsGiven last year's ranking and the set of team pairs whose relative order flipped, reconstruct this year's unique ranking or report ambiguity or contradiction.Hard8GraphTopological sort+1No attempts yet1s256 MBJudgeable
PeaksCount grid cells that stay locally maximal when reachability is restricted to cells within height d of the starting cell, for many test cases up to 500x500.Hard8Union-findSorting+1No attempts yet2s256 MBJudgeable
Cyber Donut Crime InvestigationFor each query point find the database point minimizing the L1 distance, over many test cases with up to 100000 points and 50000 queries.Hard8Divide and conquerBinary search+2No attempts yet5s128 MBJudgeable