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,732 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Judge's MistakeGroup sorted road triples to maximize disjoint pairs of equal (w, endpoint multiset) triples for the cheapest surviving-road sum.Hard8GreedySorting+1No attempts yet4s512 MBJudgeable
Number Theory and ApplicationsGiven two Gaussian integers up to 10^9 in each coordinate, output every greatest common divisor in lexicographic order.Hard8Number theoryMath+2No attempts yet0.2s16 MBJudgeable
Rangers in the BusGiven each passenger's entry order and taken seat, determine which passengers could have been each of five rangers whose seat choice follows a fixed rule or a free choice.Hard8SimulationGreedy+2No attempts yet2s512 MBJudgeable
ParcelGiven n distinct integers and target w, decide whether four of them sum exactly to w.Hard8Two pointersHash map+1No attempts yet1s512 MBJudgeable
Intergalactic BiddingGiven up to 1000 bidders with huge distinct bids and a huge target s, find every bidder contained in a subset whose sum is exactly s.Hard8GreedySorting+2No attempts yet2s512 MBJudgeable
Tree in TreeFor each vertex subset, count the edges in its minimal connecting subtree using Euler tour order and LCA checks.Hard8TreeDFS+2No attempts yet6s512 MBJudgeable
Cosmetic SurveyGiven n evaluators' ranked preference lists over m cosmetics, build the pairwise strict-preference counts and find every cosmetic X with S(X,Y) >= S(Y,X) for all Y, where S is the widest-path bottleneck strength.Hard8GraphShortest path+2No attempts yet2s512 MBJudgeable
Secret CodeFind the probability of three uniformly timed agents meeting pairwise through their fixed waiting windows, then print the scenario indices sorted by that probability.Hard8CombinatoricsGeometry+2No attempts yet1s512 MBJudgeable
Repeated SubstringsFind the longest substring with at least two overlapping occurrences in a string of up to 10^5 letters, breaking ties by the smallest in lexicographic order.Hard8String matchingString+2No attempts yet2s512 MBJudgeable
RectanglesGiven up to 100,000 axis-aligned rectangles drawn by XOR-flipping pixels on a white field, find the total count of black pixels.Hard8Segment treePrefix sum+2No attempts yet2s512 MBJudgeable
Escape, Polygon!Given an integer convex polygon of up to 100000 vertices, count the triples of its sides whose supporting lines form a triangle containing the polygon. Output that count.Hard8GeometryCombinatorics+2No attempts yet2s512 MBJudgeable
Gathering Red-Black FruitsCount how many distinct rankings of N children can arise from scoring each red fruit r and black fruit b for some positive integers r, b.Hard8GeometrySorting+2No attempts yet2s512 MBJudgeable
Go Make It CompleteGiven a simple graph, find the largest k such that some ordering of the missing edges, adding a pair when its current endpoint degrees sum to at least k, still yields the complete graph.Hard8GraphGreedy+2No attempts yet1s512 MBJudgeable
Hierarchical StructureGiven a rooted tree of employees and queries (a,b,l,r), compute the sum of ages in [l,r] over all vertices on the path from a to b.Hard8TreeBinary search+2No attempts yet3s512 MBJudgeable
Knights and DragonsGiven n distinct points (strength, magic), decide for each whether it lies in the convex hull of the others, since a point is reachable by repeated weighted averaging of the other points exactly when it is not a vertex of the hull.Hard8GeometrySorting+2No attempts yet4s512 MBJudgeable
Three Primary ColorsGiven up to 25,000 colored rectangles painted one at a time without repainting already covered pixels, report the total area of each of the seven resulting color regions.Hard8Divide and conquerSegment tree+2No attempts yet3s256 MBJudgeable
What Goes Up Must Come DownRearrange the cards by adjacent swaps into a bitonic order with the fewest moves, counting inversions by value.Hard8Divide and conquerSorting+2No attempts yet2s512 MBJudgeable
Colorful TreeMaintain vertex colors on a tree under point updates and answer queries giving the number of edges in the minimal subtree spanning all vertices of one color.Hard8TreeDFS+2No attempts yet5s512 MBJudgeable
Sort It OutFind the smallest subset of cow IDs S such that repeatedly yelling at each ID in S in increasing order eventually sorts the permutation, then output the K-th lexicographically smallest such subset.Hard8SortingCombinatorics+2No attempts yet2s512 MBJudgeable
BulldozerChoose two parallel lines and take every weighted point between them, maximizing the sum of gold values minus rock costs.Hard8GeometrySorting+2No attempts yet2s512 MBJudgeable
IlluminationChoose a subset of trees to decorate, maximizing total beauty, so that for each of M given intervals at most one tree inside it is chosen.Hard8Dynamic programmingSegment tree+2No attempts yet2s512 MBJudgeable
Live ProgrammingChoose a subset of songs within total length T and order them to maximize the sum of basic points minus squared feature differences between consecutive songs.Hard8Dynamic programmingSorting+2No attempts yet5s512 MBJudgeable
Librarian's WorkGiven a shuffled permutation with book weights, restore the original order using two adjacent-rotation-like moves and minimize total labor cost.Hard8GreedyDynamic programming+2No attempts yet5s512 MBJudgeable
Santa's GiftFor each family size k from 1 to M, choose a subset of gift kinds so k copies of each fit in capacity C, maximizing total price.Hard8Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Cat DatingIn a rooted tree, each den holds female cats or male cats with a fall limit; count the maximum number of female-male pairs where a male can reach a female downward within the distance limit.Hard8DFSGreedy+2No attempts yet4s1024 MBJudgeable
Card GameTwo players alternately remove a chosen card and every card with a smaller number; decide the winner under optimal play.Hard8Game theoryDynamic programming+2No attempts yet1s512 MBJudgeable
Sum of VectorsChoose two of N vectors, each optionally sign-flipped per coordinate, to minimize the norm of their sum and output the pair with the chosen flips.Hard8SortingGeometry+2No attempts yet0.5s512 MBJudgeable
Distinct Substring Queries 2Process a stream of append-character and count-distinct-substrings queries on a growing string, answering each count query online.Hard8StringString matching+2No attempts yet1s512 MBJudgeable
K-th SubstringGiven a string S, answer queries that ask for the K-th distinct substring of S in lexicographic order, or -1 if it does not exist.Hard8StringTrie+2No attempts yet2s512 MBJudgeable
Intersecting RectanglesGiven n axis-aligned rectangles with all x and y coordinates distinct, decide whether any two boundaries cross or touch. One rectangle fully containing another does not count.Hard8SortingSegment tree+2No attempts yet2s512 MBJudgeable
ShortcutGiven a weighted undirected graph with cows at each node, add one shortcut edge from node 1 to any other node to maximize the total decrease in shortest-path travel time.Hard8GraphShortest path+2No attempts yet2s512 MBJudgeable
KisikChoose K of N distinct buildings, arrange them side by side on the ground, and minimize the area of the enclosing bounding rectangle.Hard8SortingDivide and conquer+2No attempts yet2s512 MBJudgeable
SymphonyAdd one integer X to every element of A, then change at most K elements to any values, minimizing the sum of absolute differences against B.Hard8SortingBinary search+2No attempts yet1s512 MBJudgeable
TouristGiven a weighted graph, for each city 2 through N find a shortest path from city 1, and count the minimum number of edges whose weights are re-photographed across all chosen paths.Hard8GraphShortest path+2No attempts yet1s512 MBJudgeable
Candy BoxesGiven N boxes, each with m candies of sweetness a at cost c, find for every k from 1 to L the minimum price of boxes so that a subset of candies sums exactly to k.Hard8Dynamic programmingGreedy+1No attempts yet1.5s512 MBJudgeable
SEGWAYSimulate N riders over a 300 m track with three speed sections and accelerators granting 1 s/m boost for X mod 20 meters, where X counts riders strictly ahead, and print each finish time.Hard8SimulationImplementation+2No attempts yet1s512 MBJudgeable
Circular DNAGiven a circular sequence of start and end markers for many gene types, choose a cut position that maximizes how many gene types have their markers properly nested in the resulting linear subsequence.Hard8ArrayStack+2No attempts yet3s512 MBJudgeable
Card Factory (Large)Each of N cards shows its front initially; given M queries K that flip every card whose visible number is at most K, report the final visible sum.Hard8SortingBinary search+2No attempts yet3s256 MBJudgeable
NC StringCount the permutations of chosen words (spaced apart) that contain an N before a later C, modulo 1e9+7.Hard8CombinatoricsDynamic programming+2No attempts yet1s512 MBJudgeable
Superb DartGiven a planar straight-line graph, list the areas of its bounded faces in increasing order, rounded to two decimals.Hard8GeometryGraph+2No attempts yet1s512 MBJudgeable
Enchanted ForestChoose a path from node 1 to node n minimizing the sum of the maximum a-value and maximum b-value over its edges.Hard8GraphDivide and conquer+2No attempts yet3s512 MBJudgeable
Modified TreapAssign new distinct priorities to tree nodes so that the Cartesian-tree shape minimizes weighted depth plus K times the number of changed priorities.Hard8Dynamic programmingTree+2No attempts yet1s512 MBJudgeable
Union of BallsAll ball centers lie on the x-axis, so the union is a solid of revolution; compute its volume as p/q times pi and output p times q inverse mod 1e9+7.Hard8GeometrySorting+2No attempts yet2s1024 MBJudgeable
Overflowing Gift CardsGiven each card's days until expiry and the day he plans to use it, find the fewest 30-day extensions so every card is still valid when used, under a rule that he must always use the card closest to expiry.Hard8GreedySorting+2No attempts yet1s512 MBJudgeable
The Little Match GirlChoose for each of N integers to skip it, multiply by its negative for 1 matchstick, or multiply by its positive value for 2 matchsticks, spending at most K, to maximize the product modulo 1e9+7.Hard8GreedySorting+2No attempts yet1s1024 MBJudgeable
MaximizerGiven two permutations A and B of 1..N, find the minimum number of adjacent swaps in A needed to reach a permutation maximizing the sum of |a_i - b_i|.Hard8GreedyCombinatorics+2No attempts yet2s1024 MBJudgeable
Denouncing the MafiaGiven a rooted tree at node 1 and a limit K, choose up to K nodes to seed interrogations so the total number of reachable ancestors is maximized.Hard8TreeGreedy+2No attempts yet1s512 MBJudgeable
Paris by NightGiven N graded points in general position, pick two boundary monuments and split the rest by the line through them to minimize the absolute difference of the two side sums.Hard8GeometrySorting+2No attempts yet15s512 MBJudgeable
Travel GuideGiven a weighted undirected graph with three special nodes, count the vertices that are not dominated in all three distances by another vertex.Hard8Shortest pathGraph+2No attempts yet6s512 MBJudgeable
Shopping MallSimulate customers choosing the counter with the minimum total wait (lowest index on ties), then compute a weighted sum of membership numbers in the order customers leave.Hard8SimulationHeap+2No attempts yet1s512 MBJudgeable
Frog JumpGiven N disjoint horizontal line segments, two logs are connected if a vertical jump between them crosses no other log; answer queries on whether logs are reachable.Hard8GeometryUnion-find+1No attempts yet1s512 MBJudgeable
SeparatorAppend values one at a time to a growing sequence and after each append report how many indices are separators, meaning every earlier element is smaller and every later element is larger.Hard8TreeImplementation+2No attempts yet1.2s512 MBJudgeable
ExamFor each of Q threshold triples, count students with S>=X, T>=Y, and S+T>=Z, where N and Q reach 100000.Hard8SortingPrefix sum+2No attempts yet3s1024 MBJudgeable
Cake 3Choose M of N slices and arrange them in a cycle to maximize total value minus the sum of absolute color-depth differences around the cycle.Hard8Dynamic programmingGreedy+2No attempts yet4s256 MBJudgeable
MatryoshkaFor each query (A, B), take the dolls with R >= A and H <= B and find the minimum number of chains needed to store them all nested, i.e. the size of the largest antichain under the containment partial order.Hard8SortingDynamic programming+2No attempts yet2s512 MBJudgeable
TelegraphEach island's receiver points to one other island; turning it costs C_i. Find the minimum total cost so that every island can reach every other in the resulting functional graph.Hard8GraphGreedy+2No attempts yet1s512 MBJudgeable
InheritanceK children take turns picking the heaviest cycle-free set of edges from the graph, and we must report which child gets each edge or 0 if nobody does.Hard8GraphUnion-find+2No attempts yet1s512 MBJudgeable
BusGiven scheduled one-way buses with fixed departure and arrival times, compute for each query deadline L the latest time to leave stop 1 to reach stop N by L, or -1.Hard8GraphSorting+2No attempts yet1s512 MBJudgeable
Growing Vegetables is FunGiven N plants in a row, find the minimum adjacent swaps to arrange heights so every plant is a prefix maximum or a suffix maximum.Hard8GreedySorting+2No attempts yet2s512 MBJudgeable
ScarecrowsCount pairs of scarecrows that can be the SW and NE corners of an axis-aligned rectangle whose interior contains no other scarecrow.Hard8SortingDivide and conquer+1No attempts yet4s512 MBJudgeable
SpyGiven a subordinate subtree for every leader in two rooted trees of N employees, count for each IOI employee how many of the M spy projects succeed, where spy b succeeds when the matching JOI employee lies in research project b's subtree.Hard8TreeDFS+2No attempts yet2s256 MBJudgeable
Hat StandPlace c-1 spare hats on hooks so the total walking distance over a given sequence of n hats is minimized, then output the best arrangement.Hard8GreedyDynamic programming+2No attempts yet2s512 MBJudgeable
Copy and PasteGiven a string of up to 200,000 lowercase letters, find the length of the longest substring that appears at least twice at disjoint positions, or -1 if none exists.Hard8StringBinary search+2No attempts yet2s512 MBJudgeable
Where Have You Bin?Given a row of bins labeled by company, delete the listed bins, add the requested new bins, and find the minimum total item cost to keep every company's bins contiguous.Hard8Dynamic programmingImplementation+2No attempts yet1s512 MBJudgeable
Circle GardenGiven side lengths of a cyclic polygon, find the circumradius, or report no circle, an outside center, or a radius over 120 inches.Hard8GeometryMath+2No attempts yet1s512 MBJudgeable
Warm Pork GukbapPlace any number of stores on a line of positions 1 to 50000, each store costs M, each delivery costs C times distance to nearest store; find the minimum total cost and the smallest number of stores achieving it.Hard8Dynamic programmingBinary search+2No attempts yet1s256 MBJudgeable
3D Points and QueriesCount points inside axis-aligned 3D boxes, where each query's box coordinates are decoded by XOR with the running sum of previous answers.Hard8Segment treeSorting+2No attempts yet7s1024 MBJudgeable
Strike ZoneGiven weighted point sets P1 (+c1 each) and P2 (-c2 each) with distinct x and y coordinates, find an axis-parallel rectangle maximizing c1*s minus c2*b.Hard8Dynamic programmingSorting+2No attempts yet1s512 MBJudgeable
Interstellar TravelGiven n angular intervals where each star contributes t - s*dist(a,b), find the launch angle b maximizing the sum of contributions.Hard8GeometryMath+2No attempts yet5s512 MBJudgeable
Jumping PathGiven a rooted tree with labels, find the length of the longest ancestor chain with nondecreasing labels, and count how many such chains of that length exist modulo 11092019.Hard8Dynamic programmingDFS+2No attempts yet10s512 MBJudgeable
Glow, Pixel, Glow!Given horizontal and vertical pulses crossing a grid of wires, count the pixels where current passes through both intersecting wires at the same time.Hard8SortingImplementation+2No attempts yet2s512 MBJudgeable
Building the Perfect HouseGiven N points, none at the origin, find the largest square centered at the origin that contains no point strictly inside it, then print its perimeter to four decimals.Hard8GeometryBinary search+2No attempts yet1.5s512 MBJudgeable
Dazzling StarsGiven N stars with coordinates and brightness, decide whether some rotation of the picture makes brighter stars print no later than dimmer ones, where printing goes top to bottom.Hard8GeometrySorting+2No attempts yet0.2s512 MBJudgeable
MeetingsCows on a line swap velocities when they meet, stop at barns, and the question asks how many meetings occur before half the total weight has stopped.Hard8SortingMath+2No attempts yet1s512 MBJudgeable
GrudanjeGiven a word and Q substrings, find the first snowball throw index (in a given order of positions) after which no substring contains two uncovered equal letters.Hard8ArrayBinary search+2No attempts yet2s512 MBJudgeable
Close NumbersGiven a permutation p and q range queries [l, r], find the minimum absolute difference between any two values in the subarray p[l..r].Hard8ArraySorting+2No attempts yet2s512 MBJudgeable
Black DebtContestants get point increases over time; after each update, report the total count of (yellow, black) pairs where the black contestant has strictly more points.Hard8Segment treeBinary search+2No attempts yet1s512 MBJudgeable
Cafebazaar's Chess TournamentGiven n players each with an opening and ending skill, count how many distinct tournament scores a new player with freely chosen distinct skills can achieve.Hard8GeometrySorting+2No attempts yet2s512 MBJudgeable
LogisticsFor each query, decide whether c drivers who can each drive at most their own mileage limit can cover a route of s km in one convoy, given the drivers may swap at stops.Hard8GreedySorting+2No attempts yet2s512 MBJudgeable
Copy Shop SchedulingGiven deadlines and page counts for orders arriving one by one, after each addition report the smallest possible maximum lateness when preemptive scheduling is allowed on one machine.Hard8GreedySorting+2No attempts yet2s512 MBJudgeable
StrawberryStrawberries at positions ripen at given times; starting and ending at 0, move at speed 1 and find the minimum time to harvest all after they ripen.Hard8Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Post Office 1Place P post offices among V villages on a circular road of circumference L to minimize the total distance from every village to its nearest office, and output both the cost and chosen positions.Hard8Dynamic programmingBinary search+2No attempts yet1s1024 MBJudgeable
Farm of MonstersYou and a fixed greedy opponent alternate attacking monsters; you choose targets to maximize the number of monsters you personally kill.Hard8GreedySorting+2No attempts yet1s512 MBJudgeable
Face Recognition AlgorithmGiven a planar straight-line embedding of a connected graph, decide whether every face, including the outer one, is bounded by exactly three edges.Hard8GeometryGraph+2No attempts yet2s512 MBJudgeable
Bad DoctorEach doctor prescribes a set of medicines over a day interval; ignoring one doctor, compute the total cost of distinct medicines needed per day summed over all days.Hard8Segment treeSorting+2No attempts yet3s512 MBJudgeable
ICPC CampGiven n days, p classical and q creative problems with difficulty values, pair one of each per day so every pair sums to at most s, minimizing the largest within-pair difference; output -1 if impossible.Hard8Binary searchGreedy+2No attempts yet4s512 MBJudgeable
Bus StopEach of n bus routes has independent waiting time uniform on [0, di]; find the expected minimum, output as a fraction modulo 998244353.Hard8ProbabilityMath+2No attempts yet2s512 MBJudgeable
Snowy SmileGiven up to 2000 weighted points, find an axis-aligned rectangle maximizing the sum of weights of points inside or on its border, allowing an empty rectangle for zero.Hard8Dynamic programmingSorting+2No attempts yet3s512 MBJudgeable
The Older We Are, The Worse It HurtsRoot the tree anywhere and order each node's children so that the weighted sum of DFS discovery times is minimized; output that minimum.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
Dull ChocolatesCount prefix rectangles of a huge grid whose parity of white cells is odd versus even, given at most 1000 white cells.Hard8Prefix sumSorting+2No attempts yet9s512 MBJudgeable
Invited SpeakersGiven n red and n blue points in the plane with distinct x and y coordinates and no three collinear, draw n disjoint polygonal chains pairing each red point with a blue point.Hard8GeometryGreedy+2No attempts yet2s512 MBJudgeable
Help Yourself (Gold)Sum the number of connected regions in the union of segments over all 2^N subsets, modulo 1e9+7.Hard8CombinatoricsSorting+2No attempts yet2s512 MBJudgeable
O Life of My YouthGiven N pairs of happiness and fatigue with some values missing (0), find the largest K < N such that all young-day pairs can exceed all old-day pairs in happiness and stay below them in fatigue.Hard8SortingGreedy+2No attempts yet2s1024 MBJudgeable
HaircutFor each threshold j from 0 to N-1, clip every value above j down to j and count the resulting inversions.Hard8SortingPrefix sum+2No attempts yet1s512 MBJudgeable
Social DistancingPlace N cows on distinct integer grass points across M disjoint intervals on a line so that the minimum pairwise distance D is as large as possible, and output the largest achievable D.Hard8Binary searchGreedy+2No attempts yet1s512 MBJudgeable
The Moo ParticleGiven N points with distinct coordinates, one of two points may vanish when one dominates the other; find the minimum number of points that can remain.Hard8SortingGreedy+2No attempts yet1s512 MBJudgeable
New Year and ConferenceGiven n lectures, each with one time interval at venue a and another at venue b, decide whether every subset that is conflict-free at one venue is also conflict-free at the other.Hard8IntervalsSorting+2No attempts yet2s1024 MBJudgeable
New Year and Castle ConstructionGiven n points with no three collinear, count over all points p the number of 4-point subsets whose convex quadrilateral strictly contains p, and sum these counts.Hard8GeometryCombinatorics+2No attempts yet3s512 MBJudgeable
PasswordsGiven n rows of m letters, permute the columns so the rows become lexicographically nondecreasing, choosing the smallest such permutation or reporting NIE.Hard8GreedySorting+2No attempts yet1.5s64 MBJudgeable
Cost Of SubtreeGiven a tree with weighted edges, find a non-empty connected edge set maximizing its edge count times the minimum edge weight in it.Hard8TreeUnion-find+2No attempts yet1s512 MBJudgeable