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 results1,178 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Authentication LevelTwo grids each have a starting cell; pick a threshold per grid so the reachable cells sum to at least R, minimizing the sum of thresholds.Hard8GraphBFS+2No attempts yet2s128 MBJudgeable
Bingo GameCount N x N grids with distinct values from 1 to M, columns increasing downward, each column larger than all columns to its left, and total sum S, modulo 100000.Hard8Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Area and Perimeter of a Union of RectanglesGiven up to 10000 axis-parallel rectangles on an integer grid, compute the area of their union (and its perimeter when r=2), counting overlaps once.Hard8Segment treeSorting+2No attempts yet1s128 MBJudgeable
Boxes and StonesCount the initial distributions of S indistinguishable stones among the first B-1 boxes from which Carole, moving second each round, can force a win against Paul.Hard8Game theoryCombinatorics+2No attempts yet1s128 MBJudgeable
Joining CouplesEach city has one directed outbound flight, forming a functional graph; for each query find the minimum combined distance from two starting cities to any common reachable city, or -1.Hard8GraphTree+2No attempts yet1s128 MBJudgeable
Sanghak LanguageCount the distinct strings formed by concatenating any nonempty prefix of a Namgyu word with any nonempty suffix of a Jaehyeok word, summing over several test cases.Hard8TrieString+2No attempts yet1s128 MBJudgeable
GrapevineGiven a monotone matrix of heights and height-interval queries, find for each query the largest square submatrix whose heights all fall in the interval.Hard8Binary searchDynamic programming+2No attempts yet1s128 MBJudgeable
DNA SubsequenceFind the longest common subsequence of two words where every maximal matched run must be a contiguous block of at least K characters in both words.Hard8Dynamic programmingString+1No attempts yet1s128 MBJudgeable
PhotoGiven intervals each containing exactly one marked point, find the maximum number of marked points, or -1 if no assignment is consistent.Hard8Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Figure EightFind two axis-aligned rectangles sharing one horizontal edge row, outlines all flawless, maximizing the product of the two interior areas.Hard8Prefix sumImplementation+2No attempts yet1s128 MBJudgeable
Partitioning the FarmPlace at most K full-width horizontal or vertical fences on an N x N grid to minimize the largest connected group of cows.Hard8Brute forceBinary search+2No attempts yet1s128 MBJudgeable
Farm ManagementA tree of N farms gets path updates that add 1 to every edge on a path, plus path queries that sum edge values on a path; process M operations online.Hard8TreeSegment tree+2No attempts yet1s128 MBJudgeable
The TriangleGiven a triangular grid of values, find the sub-triangle (either orientation, side at least K) whose truncated average is largest.Hard8Binary searchPrefix sum+2No attempts yet2s128 MBJudgeable
Coin GameTwo players alternately take coins from the top of a pile, where each move may take between 1 and twice the previous move's count; find the maximum total value the first player can guarantee with optimal play from both sides.Hard8Dynamic programmingGame theory+2No attempts yet1s32 MBJudgeable
PaybackFriends stand at positions 1 to N with signed debts; Bessie starts at 0 holding nothing, must never go negative, and finishes at N. Find the minimum walking distance to settle all accounts.Hard8GreedyArray+1No attempts yet1s128 MBJudgeable
IntervalsGiven n integer intervals each needing at least c_i chosen points inside it, find the smallest set of integers satisfying all requirements.Hard8GreedySorting+2No attempts yet1s128 MBJudgeable
Connected GheevesGiven two convex funnel-shaped containers joined at the bottom, find the water level reached after pouring a given area of water, capped at the lower rim.Hard8GeometryBinary search+2No attempts yet1s128 MBJudgeable
GerrymanderingMerge adjacent ridings into blocks so Party 1 strictly wins a majority of the remaining ridings, minimizing the number of merges.Hard8Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
SweetsCount the ways to take up to m_i candies from each of n jars so the total is between a and b, modulo 2004.Hard8Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
FootballSplit a row of N player skills into K consecutive segments of at least M each so that the minimum segment average is maximized, and print that value as a reduced fraction.Hard8Binary searchDynamic programming+2No attempts yet1s1024 MBJudgeable
UnterA connected graph with N houses and exactly N edges (one cycle) must answer up to 1e6 shortest distance queries.Hard8GraphDFS+2No attempts yet1s1024 MBJudgeable
Fortune at El DoradoGiven up to 1000 points on a 1000x1000 grid and a maximum area A, find an axis-parallel rectangle with positive integer area at most A containing the most points.Hard8Two pointersBinary search+2No attempts yet1s128 MBJudgeable
HypertransmissionGiven N points in 3D each labeled 0 or 1, choose a squared radius R^2 to maximize the number of points where opposite-label neighbors outnumber same-label ones, then report that maximum and the smallest R^2 achieving it.Hard8SortingPrefix sum+2No attempts yet1s128 MBJudgeable
Box ArtGiven a bounding box and up to 2000 axis-aligned boxes, compute the volume of their union clipped to the bounding box.Hard8GeometrySorting+2No attempts yet1s128 MBJudgeable
RectanglesGiven N axis-aligned rectangles, compute the area of their union.Hard8Segment treeSorting+1No attempts yet3s128 MBJudgeable
Painting PatternsCount grid cells painted black by up to N rectangle operations, each applying one of three periodic patterns under OR overlap.Hard8GeometryPrefix sum+2No attempts yet2s64 MBJudgeable
GarlandsSplit a weighted sequence of n pieces into m segments of even length, each half-segment at most d pieces, minimizing the maximum half-segment weight.Hard8Binary searchDynamic programming+2No attempts yet2s512 MBJudgeable
Knowledge for the MassesEach row's racks keep their order and can shift left or right at cost 1 per rack; find the cheapest passage position and all positions attaining it.Hard8GreedyPrefix sum+2No attempts yet1s512 MBJudgeable
YAPTCHAFor each query n, compute the sum of floor(((3k+6)!+1)/(3k+7) - floor((3k+6)!/(3k+7))) over k from 1 to n. The sum equals the count of primes among 3k+7 for k=1..n, so precompute primes up to 3n+7 and prefix counts.Hard8Number theoryMath+2No attempts yet1s128 MBJudgeable
AntsGiven a tree tour as a 2n-bit sequence, compute the exact time when the two ants walking in opposite directions turn around for the second time, as a reduced fraction.Hard8MathSimulation+2No attempts yet3s8 MBJudgeable
Hallucinogenic CarnationsFor each of up to 10000 polygons, sum the carnations in grid parcels whose area at least half lies inside the polygon.Hard8GeometryPrefix sum+1No attempts yet1s128 MBJudgeable
The InvasionGiven a convex polygon with n vertices and m weighted points, find three polygon vertices forming a triangle with the maximum total weight of points inside or on it.Hard8GeometryTwo pointers+2No attempts yet3s64 MBJudgeable
PloughingGiven an m by n grid of tile difficulties, repeatedly remove a full strip of width 1 from any edge as long as the strip sum is at most k, and minimize the number of strips that remove every tile.Hard8Dynamic programmingTwo pointers+2No attempts yet1s128 MBJudgeable
Plot purchaseGiven an n by n grid of non-negative prices, decide whether some axis-aligned subrectangle has a sum between k and 2k inclusive.Hard8Prefix sumGreedy+2No attempts yet1s128 MBJudgeable
Ice SkatesAfter each of m membership events, decide whether every current member can be assigned skates, given k pairs of each size and foot sizes with tolerance d.Hard8Segment treeGreedy+1No attempts yet1s128 MBJudgeable
SheepCount triangulations of a convex n-gon by non-crossing diagonals such that no diagonal passes through a sheep's spot and every triangle holds an even number of spots, modulo m.Hard8Dynamic programmingGeometry+2No attempts yet3s512 MBJudgeable
MeteorsEach of N states owns sectors on a circle; given Q meteor showers that add a value to a sector range, find the earliest day each state's total reaches its target, or report it never does.Hard8Binary searchPrefix sum+2No attempts yet5s256 MBJudgeable
SalariesGiven a rooted tree with salaries a permutation of 1 to n increasing toward the root and some values revealed, print each value forced by the revealed ones or 0 otherwise.Hard8TreeGreedy+2No attempts yet1s128 MBJudgeable
Warehouse StoreGiven daily deliveries a_i and daily orders b_i, choose which orders to accept so that the warehouse never runs out of stock, maximizing accepted orders.Hard8GreedyHeap+2No attempts yet1s128 MBJudgeable
PrefixuffixGiven a string t, find the maximum length L, at most n/2, such that the length-L prefix and the length-L suffix of t are cyclic rotations of each other.Hard8StringString matching+2No attempts yet3s512 MBJudgeable
Painting the WallGiven n axis-aligned rectangles, find the total area of the plane covered by at least n-1 of them.Hard8SortingSegment tree+2No attempts yet1s128 MBJudgeable
Cheap AirlinesChoose at most k non-overlapping contiguous segments of the array to maximize the total sum of their elements.Hard8Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Coprime NumbersGiven up to a million integers, count pairs whose greatest common divisor is 1.Hard8Number theoryCombinatorics+2No attempts yet5s128 MBJudgeable
Map 2Count integer starting points (a,b) such that each of the four diagonal quadrants around (a,b) contains at least one of n marked points.Hard8SortingPrefix sum+2No attempts yet1s128 MBJudgeable
TurnsFor each starting position, find how many turns must be observed before the position on the map becomes uniquely determined.Hard8StringString matching+2No attempts yet1s128 MBJudgeable
Power of the ArrayGiven an array and t range queries, compute for each subarray the sum over values s of s times the square of s's frequency in the range.Hard8ArrayPrefix sum+2No attempts yet3s128 MBJudgeable
Creative AccountingGiven daily balances, pick a contiguous period whose sum modulo m (with nonnegative remainder) is as large as possible, and report that maximum remainder.Hard8Prefix sumMath+2No attempts yet2s128 MBJudgeable
ExcursionSplit a path of n weighted roads into contiguous segments of total length at most D, minimizing the sum of squared segment impression sums.Hard8Dynamic programmingSliding window+2No attempts yet1s128 MBJudgeable
CiągBajtek needs the shortest string over the given alphabet that is not a subsequence of the word, and the lexicographically smallest among shortest such strings.Hard8Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Settling SalariesWorkers on a ring compare contract pay to cash received and settle every balance with the fewest transfers between neighbors.Hard8GreedyPrefix sum+1No attempts yet1s512 MBJudgeable
Punch CardsChoose the largest a by b stamp whose repeated presses punch exactly the marked cells without ever punching an intact cell.Hard8Prefix sumMatrix+2No attempts yet1s256 MBJudgeable
SlidesCount the non-empty slide subsets that keep slide-number order and rise in both rankings, modulo 1000000007.Hard8Dynamic programmingDivide and conquer+1No attempts yet10s128 MBJudgeable
Fine Dining RestaurantFor each banned serial number, count the digit comparisons the described naive left-to-right substring search performs against the concatenated string A.Hard8String matchingTrie+1No attempts yet3s128 MBJudgeable
Beautiful LandscapeMove blocks between neighboring stacks at unit cost so occupied positions sit at pairwise prime distances using the fewest moves.Hard8Dynamic programmingPrefix sum+1No attempts yet20s128 MBJudgeable
The CarpenterCut two non-overlapping diagonal triangles from an n by m black-and-white board and glue them into the largest square with alternating colors.Hard8Dynamic programmingMatrix+1No attempts yet2s128 MBJudgeable
HistogramsGiven histogram H and point set S, build a valid histogram from S points that minimizes diffcount or abserror against H.Hard8Dynamic programmingPrefix sumNo attempts yet1s256 MBJudgeable
CriminalsFind every house where two given color sequences appear as subsequences on the left and right with both walkers sharing one home color outside.Hard8String matchingGreedy+1No attempts yet2s256 MBJudgeable
SupercomputerGiven a rooted tree of unit-time tasks and many processor counts, compute the fastest finishing time for each count.Hard8TreePrefix sum+2No attempts yet2s256 MBJudgeable
Test Data AnalysisCount bounded arrays of length N whose maximum contiguous subarray sum equals D, modulo 1,000,000,007.Hard8Dynamic programmingPrefix sum+1No attempts yet2s256 MBJudgeable
MarblesPlace three pairwise disjoint axis-aligned rectangles to maximize red marbles in the first plus blue in the second plus green in the third.Hard8GeometryPrefix sum+1No attempts yet1s256 MBJudgeable
Line SweepFind the tallest vertical broom that still reaches every empty cell by sliding sideways, then the fewest sideways sweeps that clean them all.Hard8GreedyIntervals+2No attempts yet10s256 MBJudgeable
NucleariaAdd up the linearly decaying king-move radiation from every plant in each grid cell, then answer each rectangle query with its rounded average.Hard8Prefix sumMathNo attempts yet1s1024 MBJudgeable
Marble MadnessMove marbles between adjacent bins to maximize the total absolute difference of neighbor counts, and report that maximum plus the fewest moves achieving it.Hard8Dynamic programmingMath+1No attempts yet1s256 MBJudgeable
Call a CabPartition the ordered points into the fewest rides where each ride meets one type's minimum total distance and heading range limit.Hard8Dynamic programmingSegment tree+2No attempts yet5s256 MBJudgeable
Book BordersFor each width m from a to b, wrap the words greedily into lines of at most m characters and report the length of the sentence made of each line's first word.Hard8Divide and conquerPrefix sum+1No attempts yet2s512 MBJudgeable
Balanced PathsCount ordered node pairs whose labels along the tree path form a balanced parenthesis string.Hard8Divide and conquerHash map+2No attempts yet3s256 MBJudgeable
Find the missing rankCount score assignments within given ranges where no person receives rank R under tied ranking.Hard8Dynamic programmingCombinatorics+1No attempts yet2s32 MBJudgeable
Swapping the StonesMove stones along empty arcs of a circular shore so black and white stones exchange position sets with minimum total carry distance, or report impossibility.Hard8GreedyString matching+1No attempts yet2s32 MBJudgeable
Ticket SwappingPassengers riding one direction on a line pay a decreasing per-stop fare and may swap entry cards where trips overlap, so compute the maximum total fare loss.Hard8GreedySorting+2No attempts yet5s512 MBJudgeable
BoatCount subsets of schools with an assigned boat count in [a_i, b_i], strictly increasing in school order, excluding the empty setup, modulo 1e9+7.Hard8Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Spiral Rectangle SumsIn a counterclockwise spiral of numbers on a (2n+1)x(2n+1) grid centered at 1, answer q queries for the sum inside an axis-aligned rectangle modulo 1e9+7.Hard8MathImplementation+2No attempts yet1.5s256 MBJudgeable
Balanced DietGiven proportional target fractions and a balanced eating history, find how many more candies can be added with every prefix staying balanced, or report forever.Hard8GreedyMath+2No attempts yet2s512 MBJudgeable
Longest RiversGiven a river network tree and source names, find for each name the best rank it can achieve over all valid downstream naming choices.Hard8TreePrefix sum+2No attempts yet10s512 MBJudgeable
Bridge testingGiven a weighted tree and two timed walkers on their respective paths, decide for each query whether both occupy some bridge simultaneously over a positive-length interval.Hard8TreeDynamic programming+2No attempts yet4s256 MBJudgeable
Hongjun Likes StringsFor each of up to 100000 queries, find the shortest substring of a fixed string S that contains both given short patterns A and B, allowing overlap.Hard8StringString matching+2No attempts yet2s512 MBJudgeable
Favorite Arrays 2Count length-N arrays with entries in 1..K where no adjacent pair has A > B with A divisible by B, modulo 1e9+7.Hard8Dynamic programmingNumber theory+2No attempts yet2s512 MBJudgeable
Hongjun's IntersectionSum the lengths of the intersections of all k-subsets of given segments, modulo 1e9+7.Hard8SortingCombinatorics+1No attempts yet2s512 MBJudgeable
Minho's WishFor each of Q range queries on an array, count how many distinct values occur at least three times within the queried index range.Hard8Segment treePrefix sum+2No attempts yet2s512 MBJudgeable
Hongjun and the TreeProcess subtree updates that add a distance-dependent value to each vertex, answering point-weight queries modulo 1e9+7.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
New Adventure of Marty and DocPlace a recycling plant on one grid cell so a robot carries every part to it with the fewest moves, picking up and dropping one part at a time.Hard8MathPrefix sum+2No attempts yet2s512 MBJudgeable
WhiteboardGiven a path on a grid and a target pattern, find the smallest and largest drying timestep T so the final board matches the target.Hard8SimulationImplementation+2No attempts yet5s512 MBJudgeable
BillboardGiven a 0/1 matrix, find the largest all-1 sub-rectangle after flipping at most s zeros and clearing at most r rows entirely.Hard8Sliding windowTwo pointers+2No attempts yet2s512 MBJudgeable
Counting Bow TiesCount 4-cycles in a bipartite graph defined by M rectangles over vertex ranges, with N up to 1e9.Hard8GeometryCombinatorics+2No attempts yet2s256 MBJudgeable
Gambling and rectanglesCompute the expected score over all equally likely rectangles, where the score squares the count of each value 1 to 5, and print it as a reduced fraction.Hard8CombinatoricsMath+1No attempts yet1s256 MBJudgeable
PopealaPartition T weighted test cases into exactly K consecutive subtasks to minimize total scored points, for each K up to S.Hard8Dynamic programmingPrefix sum+1No attempts yet2s512 MBJudgeable
Counting rectangles by distinct numbersCount rectangles of every size by how many distinct numbers they contain, then output a product of those counts modulo 1e9+7.Hard8ImplementationBit manipulation+2No attempts yet3s256 MBJudgeable
JailbreakPartition L cells into at most G consecutive blocks, minimizing the sum over each cell of its escape power times its block length.Hard8Dynamic programmingDivide and conquer+1No attempts yet2s512 MBJudgeable
Blue vertex distance sums on a treeProcess paint and distance-sum queries on a weighted tree, reporting for each query 2 the total distance from x to all blue vertices.Hard8TreePrefix sum+2No attempts yet5s512 MBJudgeable
K-th smallest weight on a tree pathFor each query, print the k-th smallest vertex weight on the unique tree path between two vertices.Hard8TreeBinary search+2No attempts yet2s512 MBJudgeable
Weighted sum queries on a mutable sequenceMaintain a sequence under insert, delete, and replace, and answer weighted-sum range queries where each element is multiplied by its offset to the power k (k up to 10).Hard8TreeBinary search+2No attempts yet2s512 MBJudgeable
Sequence and Queries 7For each query range, find the longest subarray whose sum is divisible by K.Hard8Prefix sumDivide and conquer+1No attempts yet4s512 MBJudgeable
Counting close pairs in a rangeGiven a sequence and K, each query asks how many index pairs inside a subarray have value difference at most K.Hard8Divide and conquerPrefix sum+2No attempts yet3s512 MBJudgeable
Sequence and Queries 10For each query with ranges [x1,y1] and [x2,y2], find the maximum subarray sum A_i+...+A_j where i is in the first range and j is in the second.Hard8Segment treePrefix sum+1No attempts yet2s512 MBJudgeable
Largest Increasing SubmatrixGiven a matrix, find the largest rectangular submatrix whose row-by-row linearization is strictly increasing.Hard8Dynamic programmingMatrix+1No attempts yet2s512 MBJudgeable
Sequence and Queries 11Given an array and integer K, answer queries counting subarrays within [l, r] whose XOR equals K.Hard8Prefix sumHash map+2No attempts yet2s512 MBJudgeable
Water TankGiven a daily repeating schedule of water usage, find the minimum constant pump rate that keeps the tank from ever running dry.Hard8Binary searchSimulation+2No attempts yet8s512 MBJudgeable
Internet TroublePlace 1 to N stations on a line of towns to minimize station cost plus weighted cable cost, where each house connects to the nearest station.Hard8Dynamic programmingDivide and conquer+2No attempts yet2s512 MBJudgeable
ACM TaxFor each query path in a weighted tree, output the median edge length, rounded to one decimal.Hard8TreeBinary search+2No attempts yet5s512 MBJudgeable
Sky TaxOn a tree with a moving capital, each vertex answers for all vertices whose path to the capital passes through it; move the capital or query a vertex's count.Hard8TreeDFS+2No attempts yet1s512 MBJudgeable
Sequence and Queries 14For each query on a subarray, take the distinct values, sort them, and report the k-th smallest, with each query depending on the previous answer.Hard8ArraySorting+2No attempts yet5s1536 MBJudgeable