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
Non-Decreasing SubsequencesGiven an array of values from 1 to K, answer queries counting non-decreasing subsequences within a subarray, including the empty one, modulo 1e9+7.Hard8Dynamic programmingDivide and conquer+2No attempts yet2s512 MBJudgeable
Farmer John Solves 3SUMCount, for each of Q queries, the number of unordered index triples in the subarray A[a..b] whose values sum to zero.Hard8Dynamic programmingPrefix sum+2No attempts yet2s512 MBJudgeable
Movie-goerChoose a contiguous block of days maximizing the sum of weights of movies that appear exactly once in the block.Hard8ArrayTwo pointers+2No attempts yet5s512 MBJudgeable
SealGiven a binary document grid and a binary seal stamp, decide whether the document is exactly the union of non-overlapping (and non-rotated) placements of the stamp.Hard8ImplementationSimulation+2No attempts yet2s512 MBJudgeable
VisitsGiven a tree, a visiting order, fuel prices, and tank capacities, compute the refueling cost of each trip in the order.Hard8TreePrefix sum+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
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
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
Awesome ShawarmaGiven a tree, count the unordered pairs of nodes whose added edge leaves the number of bridges in [L, R].Hard8TreeDFS+2No attempts yet14s512 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
KhoshafCount arrays of length N with entries in [L, R] that have exactly K contiguous subarrays whose sum is divisible by 3, modulo 1e9+7.Hard8Dynamic programmingCombinatorics+2No attempts yet12s512 MBJudgeable
ExpEach of n independent monsters grants i experience (0 to k) with probability p_i, totals are capped at x, and the expected capped total must be computed modulo 998244353.Hard8ProbabilityDynamic programming+2No attempts yet5s512 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
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
Tree HullMaintain a set of tree vertices under insertions and deletions, and after each query report the total edge weight of the minimal subtree spanning the current set.Hard8TreeDFS+2No attempts yet3s256 MBJudgeable
Wavel SequenceCount pairs of increasing index sequences from two arrays whose selected values are equal and form a strictly alternating up-down wave, modulo 998244353.Hard8Dynamic programmingCombinatorics+2No attempts yet1s512 MBJudgeable
Anna and Lucky TicketsCount n-digit palindromes that are lucky under neither the alternating-position sum test nor the first-half-versus-second-half sum test, modulo 1e9+7.Hard8CombinatoricsDynamic programming+2No attempts yet2s256 MBJudgeable
FaintSum the absolute differences between consecutive rows of a fixed column in the lexicographically ordered list of k-subsets of {1,...,n}, modulo 1e9+7.Hard8CombinatoricsMath+2No attempts yet1s512 MBJudgeable
PrimesAnswer online queries that ask for the sum of shared distinct prime counts over all pairs in a range [a, b] up to 10^6.Hard8Number theoryPrefix sum+2No attempts yet8s256 MBJudgeable
Master Zhu and Math ProblemCount quadruples (a,b,c,d) within given bounds that satisfy two linear inequalities, modulo 1e9+7, with bounds up to 1e18.Hard8MathCombinatorics+2No attempts yet3s512 MBJudgeable
Game of ChairsChoose a starting chair to minimize the expected distance to the nearest chair of a uniformly random color, and output the expectation as a reduced fraction.Hard8MathPrefix sum+2No attempts yet2s512 MBJudgeable
Donut-shaped EnclosurePlace a Chebyshev-distance donut with inner radius L and outer radius R at a lattice center to maximize the total weight of covered points.Hard8GeometryPrefix sum+2No attempts yet3s1024 MBJudgeable
Value of the ArrayFor each k from 1 to n, sum over all non-empty subsequences the sum of their min(size, k) largest elements, modulo 998244353.Hard8CombinatoricsSorting+2No attempts yet1s512 MBJudgeable
Best DivisionGiven a pseudorandom array, find the largest K such that A can be split into K nonempty intervals of length at most L, each with XOR sum at most X.Hard8Dynamic programmingPrefix sum+2No attempts yet1s256 MBJudgeable
Intersection is Not Allowed!Count the ways to route K non-crossing monotone paths from fixed top squares to fixed bottom squares on an N by N board, modulo 1e9+7.Hard8Dynamic programmingCombinatorics+2No attempts yet1s256 MBJudgeable
Voucher PreparationGiven members with distinct skills and names, answer many queries: remove the b highest-skilled members, then partition the best M*a remaining into a teams to maximize the summed product of skills, and output the XOR of the names of all chosen members.Hard8GreedySorting+2No attempts yet2s1024 MBJudgeable
A Game with GrundyFor each i from 0 to N, count integer x positions with L <= x <= R that lie strictly inside at most i of N triangular visibility wedges.Hard8GeometrySorting+2No attempts yet1s512 MBJudgeable
FeastChoose at most K disjoint non-empty subarrays of A so that the total sum of their elements is as large as possible.Hard8Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
LinearizationFor each query substring whose length is a power of two, find the minimum number of contiguous flips that make it a parity-of-AND pattern; the answer reduces to half the number of adjacent differing pairs after an XOR derivative.Hard8Bit manipulationPrefix sum+2No attempts yet2s512 MBJudgeable
SpeedingGiven n road segments with speed limits and lengths, plus m speeding ranges with fines, find for each car the maximum fine guaranteed from its entry and exit times.Hard8Binary searchGreedy+2No attempts yet2s512 MBJudgeable
District PartitioningPick X horizontal and Y vertical dividing roads from an (n+1)x(m+1) population grid so the maximum population of any resulting block is minimized.Hard9Binary searchGreedy+2No attempts yet2s128 MBJudgeable
Hard MatchingGiven a text sequence and two number patterns, count positions where consecutive-sum grouping matches each pattern, then find the smallest glue value x maximizing matches of the concatenated pattern with x inserted between them and report that match count.Hard9String matchingPrefix sum+2No attempts yet30s1536 MBJudgeable
DNA SequencesGiven a DNA pattern with wildcards and a rank R, find the R-th lexicographic matching string that decomposes into at most K non-decreasing runs.Hard9Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Planning Rolling BlackoutsPartition an h by w grid by recursive guillotine cuts so that the heaviest set of groups left powered stays within capacity, maximizing the group count and then the reserve.Hard9Dynamic programmingPrefix sum+2No attempts yet3s512 MBJudgeable
Yin and YangOn a tree with each edge colored black or white, count paths that split at an internal vertex into two legs each having equal numbers of black and white edges.Hard9TreeDivide and conquer+2No attempts yet2s128 MBJudgeable
BottleneckGiven a tree of one-way paths toward field 1, each with a per-time-unit cow capacity, answer K queries for the most cows that can reach field 1 by time T.Hard9TreeGreedy+2No attempts yet1s128 MBJudgeable
A Romantic Movie OutingMaintain a dynamic set of occupied seats across a huge theatre, answer queries for the combined field-of-vision inconvenience of two seats, and at the end find the minimum over far unoccupied seat pairs.Hard9Segment treeDynamic programming+2No attempts yet2s512 MBJudgeable
PeriodicityFor each name, find the lexicographically smallest bit string of the same length whose set of periods equals the name's set of periods, or XXX if none exists.Hard9StringPrefix sum+2No attempts yet1s128 MBJudgeable
Army TrainingGiven n points with no three collinear, answer m queries, each a simple clockwise polygon on those points, counting the points strictly inside it.Hard9GeometryCombinatorics+2No attempts yet2s512 MBJudgeable
Quasi-templateCount the distinct words that, as substrings of v with possibly overhanging copies, can tile across the whole input; report the count and the shortest, lexicographically smallest such word.Hard9String matchingString+2No attempts yet1s128 MBJudgeable
Prefix-SuffixesCount proper borders summed over all substrings of a given lowercase word of length up to 10^5.Hard9String matchingString+1No attempts yet1s128 MBJudgeable
HighwaysGiven a tree plus extra highway edges, count for each query (x,y) the main tree path plus alternative single-highway paths that touch the main path only at x and y.Hard9TreeDFS+2No attempts yet3s128 MBJudgeable
The Most Valuable TowerFind the largest sum any single tower can reach by swapping top segments between towers of different heights.Hard9Number theorySorting+2No attempts yet1s512 MBJudgeable
Land TaxChoose a non-empty contiguous row and column range that maximizes combined row and column payments weighted by heights and widths.Hard9Divide and conquerGeometry+2No attempts yet1s128 MBJudgeable
CrystalSum the signed charges of all three-colored unit triangles in a hexagonal crystal filled row by row from a modular generator.Hard9MathGeometry+2No attempts yet1s128 MBJudgeable
AdriaticOn a 2500 by 2500 grid, islands ordered alike from northwest to southeast connect in one hop, and each island needs the sum of fewest hops from all others.Hard9GraphPrefix sum+1No attempts yet2s256 MBJudgeable
Covering postersFor each new axis-aligned rectangle, compute the total area of the given union of rectangles that it covers.Hard9Segment treePrefix sum+2No attempts yet2s1024 MBJudgeable
XOR QueriesMaintain an array under appends, rollbacks of the last k elements, and range queries for max XOR, count <= x, and k-th smallest.Hard9TrieSegment tree+2No attempts yet2s512 MBJudgeable
Sequence and Queries 0For each query range [i,j] of a ±1 sequence, report the length of the longest contiguous subarray inside it whose sum is 0, or 0 if none exists.Hard9Segment treePrefix sum+2No attempts yet2.5s512 MBJudgeable
Sequence and Queries 6For each query range [i, j], report the highest number of occurrences of any single value inside that range.Hard9Segment treeDivide and conquer+2No attempts yet2s512 MBJudgeable
EggscavationGiven up to 100000 shell species (each in at most 4 cells) and egg insertions, answer queries for the probability that a random K x K scoop covers at least V species and no egg.Hard9GeometryPrefix sum+2No attempts yet10s512 MBJudgeable
MinerFor each lamp position above a polyline mine floor, find the reachable floor interval lit without crossing the floor.Hard9GeometryBinary search+2No attempts yet1.5s512 MBJudgeable
Bracket PathsGiven a tree with '(' or ')' on each node, count ordered pairs (a,b) whose path string w_{a,b} is a properly matched bracket expression.Hard9TreeDivide and conquer+2No attempts yet3s1024 MBJudgeable
The Enormous SequenceDefine a_n by summing every nonempty subset sum of the first n-1 terms, then answer queries about gcd, 2-adic valuation of lcm, prefix sums, or a single term for various starting values.Hard9MathNumber theory+2No attempts yet2s128 MBJudgeable
Rolling the BottleGiven a convex polygon as a bottle base and a water volume, find the minimum and maximum number of sides of the water region as the bottle rolls.Hard9GeometrySorting+2No attempts yet2.5s512 MBJudgeable
Largest window sumFor every window length K, find the largest possible sum of a length-K window over all non-negative arrays that satisfy each given length bound.Hard9GreedyPrefix sum+2No attempts yet1s512 MBJudgeable
Intrinsic IntervalFor each query range in a permutation, find the smallest subarray containing it whose values form a set of consecutive integers.Hard9Segment treeStack+1No attempts yet3s512 MBJudgeable
Laminar FamilyGiven an undirected tree and f vertex sets, each a simple path, decide whether the family of paths is laminar.Hard9TreeDFS+2No attempts yet2s512 MBJudgeable
L-th K-th numberGiven N cards, take the K-th smallest value of every contiguous block of length at least K, then report the L-th smallest of all those values.Hard9Binary searchArray+2No attempts yet2s512 MBJudgeable
Conveyor BeltAfter each of Q delivery requests (a, b, p) is added, report the minimum time to finish all tasks, given plates arrive one per second and each plate carries one product.Hard9MathGreedy+2No attempts yet2s512 MBJudgeable
In honor of Taekhee's graduationDeer bounce on a line segment [0,T], each with strength; a statue at x falls when the net force of deer that have reached it exceeds W. Maximize the fall time over x.Hard9MathSimulation+2No attempts yet3s128 MBJudgeable
Pia's Atelier: The Alchemist of Mysterious LifeGiven 2x2 parity constraints on an n by n binary grid, decide for each day whether a grid exists satisfying all interval cell-fixing conditions active that day.Hard9Union-findPrefix sum+2No attempts yet2s512 MBJudgeable
International Cow Lineup Photo ContestGiven a 0/1 array and up to 1e5 adjacent swaps, after each swap report the longest subarray with equal numbers of 0s and 1s.Hard9Segment treePrefix sum+2No attempts yet2s512 MBJudgeable
Lexicographically Smallest Sign SequenceFill a sign sequence of -1 and 1 with some fixed entries so that every range [Ai,Bi] has sum at least Ci, and output the lexicographically smallest valid sequence or Impossible.Hard9GreedyPrefix sum+2No attempts yet1s512 MBJudgeable
Fruit TreeGiven a tree whose vertices hold fruit types, answer queries asking whether one type is a strict majority on the path between two vertices, and which type it is.Hard9TreeBinary search+2No attempts yet3s1024 MBJudgeable
Historical ResearchFor each query range, report the maximum over event types t of t times the count of t inside the range.Hard9Divide and conquerArray+2No attempts yet4s512 MBJudgeable
Sequence and Queries 32Maintain a sequence under point updates and answer whether it can be split into contiguous blocks whose xors all lie in a small given set.Hard9Dynamic programmingPrefix sum+2No attempts yet10s512 MBJudgeable
Dance CircleCount, modulo 1e9+7, the binary assignments to n children around a circle matching n parity constraints, each covering a contiguous arc centered at some child.Hard9MathPrefix sum+2No attempts yet2s512 MBJudgeable
Colored Paper and QueriesGiven N axis-aligned rectangles and M axis-aligned query rectangles, report for each query the maximum number of input rectangles covering any single point inside it.Hard9Segment treeDivide and conquer+2No attempts yet1s512 MBJudgeable
Speed Reading CourseCount how many positions i where c contains the given m-bit word w, with c defined by an arithmetic progression modulo n against threshold p.Hard9Number theoryString matching+2No attempts yet2s512 MBJudgeable
Rooted SubtreesFor each query with two roots r and p, count the distinct non-empty sets that are the intersection of a subtree of the tree rooted at r and a subtree of the tree rooted at p.Hard9TreeDFS+2No attempts yet11s512 MBJudgeable
Linear Congruential GeneratorGiven a linear congruential generator and two index ranges, sum X_i mod (X_j+1) over all pairs i in the first range and j in the second.Hard9MathNumber theory+2No attempts yet2s512 MBJudgeable
Greatest Chicken DishCount, for each query range [L, R] and value D, the number of contiguous subarrays inside [L, R] whose GCD equals D.Hard9Dynamic programmingNumber theory+2No attempts yet15s512 MBJudgeable
Sprinklers 2: Return of the AlfalfaCount the ways to place sweet corn and alfalfa sprinklers on an N by N grid, with some blocked squares, so that every square is covered by exactly one sprinkler type.Hard9Dynamic programmingPrefix sum+2No attempts yet2s512 MBJudgeable
Dirt RatioChoose a contiguous subarray to minimize (number of distinct values)/(subarray length); print the minimum ratio.Hard9Binary searchPrefix sum+2No attempts yet2s512 MBJudgeable
Unseen SegmentsGiven n vertical segments and queries of (west power, east power), find the total length of parts no observer sees through at most that many segments.Hard9GeometrySorting+2No attempts yet2s256 MBJudgeable
Master Zhu and RikkaGiven a rooted tree with values on vertices, answer queries that ask for the GCD of sums of values occurring exactly a times and exactly b times in a subtree or on a path.Hard9TreeDFS+2No attempts yet3s512 MBJudgeable
GCD vs LCMFor each of q queries with n, m, a up to 1e5, sum lcm(i,j) over all i<=n, j<=m with gcd(i,j)<=a, modulo 1e9+7.Hard9Number theoryMath+2No attempts yet2.5s512 MBJudgeable