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
Add Parentheses 3Parenthesize an alternating digit and +,-,* expression of length up to 19 to maximize its value, respecting left-to-right and multiplication-first rules.Hard8Divide and conquerDynamic programming+2No attempts yet1.5s512 MBJudgeable
Counting StairsCount symmetric stairs (partitions of n into distinct parts) with n cubes, modulo 998244353, for up to 1e4 queries with n up to 2e5.Hard8Dynamic programmingMath+2No attempts yet3s512 MBJudgeable
The ABCD MurdererFind the fewest word occurrences needed to cover a target text exactly when cut-outs may overlap on matching text, or report -1 if impossible.Hard8String matchingArray+2No attempts yet2s512 MBJudgeable
The Pied PiperPlace the fewest cells so every frozen walk under the U/D/L/R map enters a safe cell; model directed functional reverse graphs and find a minimum set of path-starting states.Hard8GraphSimulation+2No attempts yet1s256 MBJudgeable
Shortest Common Non-SubsequenceGiven two binary strings of length up to 4000, find the shortest binary string that is a subsequence of neither, breaking ties by lexicographic order.Hard8Dynamic programmingGreedy+2No attempts yet5s512 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
Balance BeamChoose at each beam position a cash value or a fair coin random walk stopped at the ends, maximizing expected payment for every starting position.Hard8Dynamic programmingMath+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
Pear-wise VotingGiven ranked ballots and a selectable candidate order, decide for each candidate whether some agenda makes that candidate win sequential pairwise contests.Hard8Bit manipulationDynamic programming+2No attempts yet2s512 MBJudgeable
Sequential YahtzeeGiven up to 195 sequential dice rolls, assign consecutive segments to the 13 Yahtzee categories in order to maximize the total score.Hard8Dynamic programmingPrefix sum+2No attempts yet2s512 MBJudgeable
Funny Number GameGiven a 4-digit N and M turns of incrementing one digit with 9 wrapping to 0, decide which player forces the final value above N.Hard8Bit manipulationMath+2No attempts yet0.5s512 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
Naming the ComputerGiven a string S and integer K, find the shortest string that contains S as a substring at least K times, and output its length.Hard8String matchingDynamic programming+2No attempts yet2s512 MBJudgeable
Substring ReplacementReplace each question mark in S with a lowercase letter so that T appears as a substring as many times as possible, and report that maximum count.Hard8Dynamic programmingString matching+2No attempts yet2s512 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
Chessboard Tour 1On an N by N board holding distinct numbers, find the fewest seconds (each a single piece move or a piece swap) to travel through squares 1, 2, ..., N^2 in order using a knight, bishop, and rook.Hard8BFSShortest path+2No attempts yet2s512 MBJudgeable
Maximum Subarray Sum and QueriesGiven an array, answer queries that ask for the maximum subarray sum inside a given index range.Hard8Segment treeDivide and conquer+2No attempts yet2s512 MBJudgeable
Heaps of FunGiven a rooted tree where each node i draws a uniform random real in [0, b_i], compute the probability that every parent's value is less than both its children's values, modulo 1e9+7.Hard8ProbabilityDynamic programming+2No attempts yet2s512 MBJudgeable
Planes, Trains, but not AutomobilesGiven a DAG of one-way train lines and complete flight connectivity, find the minimum number of flights to visit every city once and list all cities whose airport can be used on some optimal route.Hard8GraphDynamic programming+2No attempts yet2s512 MBJudgeable
RedistrictingGiven a string of H and G representing a line of cows, split it into contiguous districts of length at most K minimizing the number of districts where G outnumbers or ties H.Hard8Dynamic programmingPrefix sum+2No attempts yet2s512 MBJudgeable
Broken DataDelete some integers from a sequence so the rest reads as N M U1 V1 ... UM VM with 1 <= Ui,Vi <= N; among all valid restorations, maximize N, then M.Hard8ImplementationGreedy+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
Dynamic CentroidFor each prefix tree formed by vertices 1..k, output the smallest centroid (the vertex whose removal leaves components of size at most k/2).Hard8TreeDFS+2No attempts yet1.5s512 MBJudgeable
Raider Choragi and Queries (Normal)A donut-shaped ring of 2N zones holds prisoner counts that change over Q updates; after each change, print the minimum number of squads, each covering one zone or two adjacent zones with total at most W.Hard8Dynamic programmingSegment tree+2No attempts yet5s512 MBJudgeable
Alpine ValleyGiven a weighted tree with shops and an exit, answer queries where one edge is removed and you need either the shortest distance to the exit or to the nearest shop from a village.Hard8TreeGraph+2No attempts yet3s512 MBJudgeable
Overflowing PopularityGiven M guests with arrival and departure times, choose when to insert up to K extra friends so that the count of ordinary attendees stays below T as long as possible.Hard8Dynamic programmingGreedy+2No attempts yet1s256 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
ZooGiven a string, count for each prefix the non-overlapping prefix-suffix matches and output the product of (count+1) modulo 1e9+7.Hard8StringString matching+2No attempts yet1s512 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
Plants vs. ZombiesGiven a grid of plants, each with a score and an attack range, zombies enter from the right and can eat a plant only after clearing the plants to its right, but eating a plant that any surviving plant covers is fatal; maximize total score.Hard8GraphTopological sort+2No attempts yet1s512 MBJudgeable
Pipe MarblesGiven two binary strings as stacks, count the sum of squares of the number of interleavings producing each distinct output string, modulo 1024523.Hard8Dynamic programmingString+2No attempts yet1s512 MBJudgeable
Counting Spanning TreesCount spanning trees of a path graph where every pair of nodes at distance at most k is joined, k <= 5, n <= 10^15, modulo 65521.Hard8MatrixDynamic programming+2No attempts yet1s256 MBJudgeable
Third Baseman UnknownOn an N by N grid of uppercase letters, walk right or down from the top-left to the bottom-right and maximize how many times "MOLA" appears in the collected string.Hard8Dynamic programmingMatrix+2No attempts yet1s512 MBJudgeable
AbbreviationCount the ways to split a query string into pieces, where each piece is a prefix of some dictionary word, with duplicates counted as distinct.Hard8Dynamic programmingString matching+2No attempts yet2.5s1024 MBJudgeable
Binary TransformationChoose a chain of N numbers from x0 to 0, each step clearing some 1 bits, so the set of adjacent differences has the smallest possible max minus min.Hard8GreedyBit manipulation+2No attempts yet1s512 MBJudgeable
Time DraggingGiven an N by M board with marked cells, find the longest sequence of row and column picks such that no pick creates a marked intersection among chosen lines.Hard8GreedyGraph+2No attempts yet1s512 MBJudgeable
Sequence and Queries 24Maintain an array under point updates and range queries that ask for the largest sum of two distinct elements within a subarray.Hard8Segment treeDynamic programming+2No attempts yet1s512 MBJudgeable
Overflowing BanknotesFor each query, after updating one node, find the maximum banknotes that can be gathered at one safe when any node is chosen as root and the coins fall optimally.Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
2xN Tiling with QueriesMaintain the count of tilings of a 2xN grid by 1x2 and 2x1 tiles while cells get blocked and unblocked by queries.Hard8Dynamic programmingSegment tree+2No attempts yet2s256 MBJudgeable
Fox QuizGiven answer strings S and T over O/X, answer range queries and point flips: for a range, choose positions to mark F to maximize A times correct answers plus B times occurrences of the consecutive pattern F,O,X.Hard8Segment treeDynamic programming+2No attempts yet3s1024 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
kdh9949Find the longest path in an undirected graph whose vertex labels spell repeated KDH blocks, or report -1 if such a path can be infinite.Hard8GraphDynamic programming+2No attempts yet1s1024 MBJudgeable
Deadly! 60-Note ComboFor each query (a, b, c), count how many binary strings x with a <= x <= b score strictly higher than c in a 60-note combo game, where a GOOD after a combo of X gives 2X-1 points.Hard8Dynamic programmingBit manipulation+2No attempts yet2s1024 MBJudgeable
Expression TreeGiven a binary expression tree with + and - operators, permute the operand values freely to maximize the evaluated result.Hard8TreeGreedy+2No attempts yet1s256 MBJudgeable
All You Need is DatingGiven bipartite preferences and per-student min/max date counts, find the maximum number of dates satisfying all lower and upper bounds, or -1.Hard8GraphDynamic programming+2No attempts yet1s512 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
Dishonest DriverGiven a string of N characters, find the size of the shortest compressed form built from single characters, concatenation, and repetition (C repeated k times).Hard8Dynamic programmingString+2No attempts yet6s512 MBJudgeable
Running RoutesGiven chords of a convex n-gon, find the largest set of chords no two of which share any common point, including endpoints.Hard8Dynamic programmingIntervals+2No attempts yet12s1024 MBJudgeable
BracketsFor each N, find the valid bracket string with bracket value N whose digit-encoded decimal value is smallest, and print it.Hard8Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
Black StonesGiven a tree with some vertices marked black, count how many queries (i, j) admit a connected subtree with exactly i vertices and j black vertices.Hard8TreeDynamic programming+2No attempts yet1s512 MBJudgeable
ResistancePlayers leave and return over time; after each change report the maximum value of a split into two teams, where friendship edges crossing the split are lost.Hard8GraphMinimum spanning tree+2No attempts yet2s512 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
TentsCount nonempty subsets of tents on an H by W grid with directions obeying monotone entrance rules in every row and column, modulo 1e9+7.Hard8CombinatoricsDynamic programming+2No attempts yet2s512 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
JOI Logo DesignGiven a circular string of length 4^K over {J,O,I}, find the rotation that minimizes mismatches with a level-K JOI sequence built by recursive quarter block replacement.Hard8Dynamic programmingDivide and conquer+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
MascotsCount the orders of placing the remaining mascots so that the number of steps where the occupied cells form a full rectangle is maximized, modulo 1e9+7.Hard8CombinatoricsDynamic programming+2No attempts yet2s256 MBJudgeable
White Day Present ExchangeEach student gives treats to one other student; choose whether each makes cookies or cake to maximize total happiness from what they receive.Hard8GraphDynamic programming+2No attempts yet1s256 MBJudgeable
EquationCount integers n in [a, b] up to 10^18 with k times the sum of squares of n's decimal digits equal to n.Hard8MathBrute force+2No attempts yet2s512 MBJudgeable
JOI FlagFill and fix a 2^K by 2^K grid so it follows the recursive quadrant rule for JOI flags, minimizing the number of already-written cells whose character must change.Hard8Divide and conquerDynamic programming+2No attempts yet3s512 MBJudgeable
Inquiry IIGiven a connected simple graph with at most n+15 edges, output the size of its maximum independent set.Hard8TreeDFS+2No attempts yet5s512 MBJudgeable
Estate AgentGiven directed offers between families with amounts, pick a subset of disjoint cycles so the total sum of offer amounts is maximized, then output 5% of it.Hard8GraphDynamic programming+2No attempts yet2s512 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
Mosaic MansionGiven n rows of m colored tiles, remove rows so that the kept rows contain the same number of tiles of each color; maximize the number of kept rows.Hard8Dynamic programmingHash map+2No attempts yet12s512 MBJudgeable
DžumbusGiven a forest of N friends with drink thresholds, and Q queries each supplying a total drink S, find the maximum number of people who exchange solutions.Hard8Dynamic programmingTree+2No attempts yet1s512 MBJudgeable
Just Passing ThroughGrid path from the west edge to the east edge moving east, northeast, or southeast, crossing exactly n passes, minimizing total elevation.Hard8Dynamic programmingMatrix+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
Watch LaterGiven a string of video types, find the minimum number of manual clicks needed to watch everything, where playback auto-advances to the next video only if it has the same type.Hard8Dynamic programmingBit manipulation+2No attempts yet6s512 MBJudgeable
Loo RollsFind the smallest number of loo rolls, each of length l, so that consuming n per visit never triggers a shortage.Hard8MathNumber theory+2No attempts yet1s512 MBJudgeable
Dice and LaddersFind the minimum number of die rolls so that the probability of finishing a snakes-and-ladders board within that many rolls is at least p.Hard8ProbabilityDynamic programming+2No attempts yet2s512 MBJudgeable
Counting Permutations with a Given Greedily Increasing SubsequenceCount the permutations of 1 to N whose greedily increasing subsequence equals a given sequence G, modulo 1e9+7.Hard8CombinatoricsMath+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
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
Drive SafelyPlace k speed limit signs on a polyline road so that travel time is minimized, where each turn caps the speed limit by |180 - alpha| km/h.Hard8Dynamic programmingGeometry+2No attempts yet1s512 MBJudgeable
Fixed Point PermutationsFind the kth lexicographically smallest permutation of 1..n having exactly m fixed points, or print -1 if fewer than k exist.Hard8CombinatoricsDynamic programming+2No attempts yet1s512 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
Cocoa CoalitionBreak an n by m chocolate bar with straight-line cuts into pieces that can be grouped into one pile of a cells and one of b cells, minimizing the number of cuts.Hard8Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
Hold or Continue?For each query state (Catelyn score, Hoster score, current turn total) decide hold or continue to maximize Catelyn's win probability when both play optimally in Pig to exactly 75.Hard8Dynamic programmingProbability+2No attempts yet2s512 MBJudgeable
Gnoll HypothesisGiven n spawn probabilities and a random pool of k chosen types, compute each type's expected effective spawn chance after unchosen chances shift to the next chosen type cyclically.Hard8ProbabilityDynamic programming+2No attempts yet2s512 MBJudgeable
ICPCConcatenate all lowercase words of length 1 through N in length-then-alphabetical order; count occurrences of the substring "icpc" modulo 1e9+7, with N up to 1e9.Hard8CombinatoricsString matching+2No attempts yet2s512 MBJudgeable
K==SCount sequences of length N over 26 letters that avoid any of Q given forbidden strings as contiguous substrings, modulo 1e9+7, where N can be up to 1e9.Hard8String matchingDynamic programming+2No attempts yet1s512 MBJudgeable
True/False WorksheetCount binary strings of length n that satisfy range hints, where each hint says a range is all equal or not all equal, modulo 1e9+7.Hard8Dynamic programmingPrefix sum+2No attempts yet2s512 MBJudgeable
Who Has Not Read the Message?Given each message's sender and the count of people who had not read it, count the possible sets of unread people per message, modulo 1e9+7.Hard8CombinatoricsDynamic programming+2No attempts yet1s256 MBJudgeable
Shortest Paths and QueriesGiven a grid with up to 5 rows and 100,000 columns, answer queries for the minimum-weight monotone-free path between two cells.Hard8Dynamic programmingMatrix+2No attempts yet5s512 MBJudgeable
Interleaved Periodic StringGiven a binary string S, find the minimum total length of two binary strings whose repeated copies can be interleaved to produce S.Hard8Brute forceDynamic programming+2No attempts yet1s512 MBJudgeable
Fantastic FožgajCount length-m lowercase strings over 26 letters that avoid any of n forbidden patterns as a substring, modulo 1e9+7, with m up to 1e9.Hard8Dynamic programmingString matching+2No attempts yet1.5s512 MBJudgeable
Coloring a Rectangle 2Count binary colorings of an N by M grid, N up to 1e18 and M at most 5, with no 2x2 block of a single color, modulo 1e9+7.Hard8Dynamic programmingMatrix+2No attempts yet1s512 MBJudgeable
NM and K (1)Choose exactly K non-adjacent cells from an N by M grid, at most 10 by 10, to maximize the sum of their values.Hard8Dynamic programmingBit manipulation+2No attempts yet2s512 MBJudgeable
NM and K (2)Choose exactly K non-adjacent cells from an N by M grid, each with a value, to maximize the total sum.Hard8Dynamic programmingBit manipulation+2No attempts yet2s512 MBJudgeable
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
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
Rock-Scissors-Paper ExpressionCount the assignments of R, S, P to the ? symbols in a fixed arithmetic expression, under rock-scissors-paper defined operators, so that evaluation gives A.Hard8Dynamic programmingDivide and conquer+2No attempts yet2s512 MBJudgeable
ZapinaCount the ways to assign N distinct tasks to N programmers so that at least one programmer i receives exactly i tasks, modulo 1e9+7.Hard8CombinatoricsDynamic programming+2No attempts yet1s512 MBJudgeable
Collecting Stamps 3On a circular lake, N stamps sit at given positions with individual collection deadlines; find the maximum number of stamps JOI-kun can collect starting from position 0.Hard8Dynamic programmingIntervals+2No attempts yet2s512 MBJudgeable
Olympic BusChoose at most one directed bus edge to reverse, paying its reversal cost, so that a round trip from city 1 to N and back exists, minimizing total fare plus reversal cost.Hard8GraphShortest path+2No attempts yet2s512 MBJudgeable