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,702 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Parenthesis String ?Answer M queries asking whether substring S[i..j] is a correct bracket sequence, and output the sum of all answers.Medium6Prefix sumStack+1No attempts yet0.5s512 MBJudgeable
Bracket StringsGiven N and K, find the K-th lexicographically smallest string of length N over '(' and ')' that is not a valid bracket string, using combinatorial counting.Medium7CombinatoricsDynamic programming+2No attempts yet2s128 MBJudgeable
Smallest Integer with K Distinct DigitsGiven N up to 10^18 and K up to 10, construct the smallest integer at least N that contains exactly K distinct decimal digits.Medium7Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
DNA Deletions and Protein CountCount, modulo 1e9+7, the distinct proteins obtainable by deleting some nucleotides from a DNA string and translating the remaining codons via a given table.Medium7Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Palindrome FactoryCompute the minimum number of insertions, deletions, replacements, and at most one swap needed to turn a given string into a palindrome.Medium7Dynamic programmingString+1No attempts yet2s128 MBJudgeable
Twin VillagesSelect as many village pairs as possible with Manhattan distance at least D and degree at most P per village, then minimize the total distance among maximum selections.Medium7Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
Coin Board GameA coin on a grid jumps exactly the digit on its cell in one of four directions; find the maximum number of moves before it leaves the board or hits a hole, or -1 if it can move forever.Medium7Dynamic programmingDFS+2No attempts yet2s512 MBJudgeable
Counting K-gonsCount the subsets of exactly K segments (from N, N up to 50) whose longest side is shorter than the sum of the rest, forming a valid K-gon.Medium7Dynamic programmingCombinatorics+2No attempts yet2s128 MBJudgeable
Restore an Addition EquationFill the ? digits in an addition equation A+B=C with digits (no leading zeros) so the sum holds, maximizing C then A.Medium7Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Placing Puzzle PiecesGiven a board length and a set of piece lengths, find the minimum number of pieces to place so that no remaining piece can fit in any leftover gap.Medium7Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
BackupGiven n sorted company positions on a line, choose k disjoint pairs (2k companies) minimizing the total sum of pairwise distances.Medium7GreedyHeap+2No attempts yet2s128 MBJudgeable
Oh Min-sik's WorryFind the maximum money achievable traveling from city A to city B using weighted directed edges and city rewards, detecting infinite gain via positive cycles.Medium7GraphShortest path+2No attempts yet2s128 MBJudgeable
ParliamentGiven seat counts for N parties, find the maximum-seat coalition that has more than half the total seats but loses majority if any single member is removed.Medium7Dynamic programmingSorting+1No attempts yet2s128 MBJudgeable
WarGiven a forest of vassal relations and per-country conquest costs, find the minimum days needed to conquer or force surrender of at least M countries using tree knapsack DP.Medium7Dynamic programmingTree+1No attempts yet2s128 MBJudgeable
Stock King DonghoGiven prices for C stocks over D days and starting cash M, find the maximum cash obtainable by buying and selling whole shares each day using knapsack-style dynamic programming.Medium7Dynamic programmingArray+2No attempts yet2s128 MBJudgeable
Palindrome Word SequencesCount ordered sequences of given words, reused any number of times, whose concatenation has exact length L and forms a palindrome.Medium7Dynamic programmingString matching+2No attempts yet2s128 MBJudgeable
Special NodesIn a rooted tree where child weights exceed parent weights, mark vertices special or ordinary to minimize the total of each ordinary vertex's weight minus its nearest special ancestor's weight.Medium7Dynamic programmingTree+2No attempts yet2s128 MBJudgeable
Custom DiceCount six-faced dice with distinct positive integers averaging at most M, treating rotations as identical, and print the count mod 1e9+7.Medium7CombinatoricsDynamic programming+2No attempts yet2s128 MBJudgeable
Gem Shop LightingGiven required light values for an N by M grid of gems, find the minimum total intensity of row and column lamps so every gem's light requirement is met, which reduces to a maximum weight bipartite matching problem.Medium7GraphDynamic programming+1No attempts yet5s128 MBJudgeable
BiomagnificationGiven a DAG of predator-prey species where each consumer picks prey via an unbounded knapsack to meet its calorie need while minimizing heavy metal, determine if the human species survives and find its minimum accumulated metal.Medium7Dynamic programmingGraph+2No attempts yet5s128 MBJudgeable
Bead NecklaceCount distinct linear arrangements of beads with given color counts (3 to 5 colors, up to 35 beads total) so that every three consecutive beads have different colors.Medium7CombinatoricsMath+2No attempts yet2s128 MBJudgeable
RPGGiven quests that require either a strength or intelligence threshold and grant points to freely raise those stats, find the maximum number of quests completable.Medium7Dynamic programmingSorting+2No attempts yet2s128 MBJudgeable
High-Rise BuildingsCount permutations of heights 1..N arranged so exactly L buildings are visible from the left and R from the right, modulo 1e9+7.Medium7CombinatoricsDynamic programming+1No attempts yet2s128 MBJudgeable
Number of NKD SequencesCount length-K strictly increasing sequences summing to N where consecutive differences are at most D and the first term is at most D, modulo 1e9+7.Medium7Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Candy Stair ClimbFind the maximum candies collectible by jumping between horizontal stair segments within distance K, never decreasing height, starting from the ground.Medium7Topological sortGraph+2No attempts yet2s128 MBJudgeable
Ideal StringBuild the lexicographically smallest length-N string where each character's total occurrence count equals the position of its first appearance, or output -1 if none exists.Medium7GreedyDynamic programming+2No attempts yet2s128 MBJudgeable
TetrisCount the number of ways to tile a 3xN grid using square, T, S, Z, L, and J tetrominoes (no straight piece), modulo 1,000,000.Medium7Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Coin ProblemFind the minimum number of coins from denominations 10^K and 25x100^K needed to make an exact price up to 10^15.Medium7GreedyMath+2No attempts yet2s128 MBJudgeable
Fan ServiceCount length-2K ticket numbers over a given digit set where the two halves have equal digit sums or the odd/even positions have equal digit sums, modulo 999983.Medium7Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
MarriageGiven up to 12 men and 12 women with mutual liking pairs, partition everyone into star-shaped marriages (one person of one gender with several of the other) to cover all people with the fewest marriages, or report impossibility.Medium7Dynamic programmingBit manipulation+2No attempts yet5s128 MBJudgeable
Paper OverlayOverlay two grid papers, each freely rotated, flipped, and positioned, then find the largest all-X rectangle in the combined grid.Medium7MatrixBrute force+2No attempts yet2s128 MBJudgeable
Fixing an ArrayFor each array value, find the number within a given range that has the smallest Hamming distance in binary, breaking ties by choosing the smallest value.Medium7Bit manipulationDynamic programming+1No attempts yet2s128 MBJudgeable
Olympic RankingGiven current medal counts, decide how to award all remaining silver and bronze medals so that team 1 (which wins every remaining gold) reaches the best possible final rank.Medium7Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Dial LockGiven a current dial state and a password of N digits, find the minimum number of operations, each rotating a contiguous block of at most three circular dials by 1 to 3 steps, to reach the password.Medium7Dynamic programmingMath+2No attempts yet2s128 MBJudgeable
Number of Routes Arriving at the Exact TimeCount the number of routes from S to E in a weighted directed graph that take exactly T minutes, modulo 1,000,003.Medium7MatrixGraph+2No attempts yet2s128 MBJudgeable
New OperatorGiven digit-based functions and a custom operator @ built from them, find the minimum number of @ operations starting from X to reach target value G, or report -1.Medium7MathDynamic programming+2No attempts yet2s128 MBJudgeable
Stair NumbersCount N-digit numbers whose adjacent digits differ by exactly 1 and that contain every digit 0-9 at least once, modulo 1,000,000,000.Medium7Dynamic programmingBit manipulation+1No attempts yet2s128 MBJudgeable
Treasure HuntGiven a grid where the player travels down-right, then up-left, then down-right again, find the maximum treasure collected counting each cell only once per visit.Medium7Dynamic programmingMatrix+1No attempts yet2s128 MBJudgeable
Traffic EnforcementGiven shuffled entry and exit times for N cars, pair them into valid entry-exit matches and find the minimum and maximum total speeding fine over all valid perfect matchings.Medium7GraphDynamic programming+2No attempts yet2s128 MBJudgeable
Youngsik FunctionCount integers in [A, B] up to 1e9 whose repeated adjacent-digit-difference reduction (the Youngsik function) eventually collapses to the single digit 7.Medium7Dynamic programmingRecursion+2No attempts yet2s128 MBJudgeable
Once Opened, You Can't StopChoose one integer per flavor within its given range so the sum of absolute changes between consecutive picks is minimized, and output the values.Medium7Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Counting Single-Letter TrianglesCount all size-2-or-larger right isosceles and diamond-shaped isosceles triangles made of one repeated letter, in any rotation, inside an N x N grid.Medium7Dynamic programmingMatrix+2No attempts yet2s128 MBJudgeable
Maximum Increasing Rectangle SetGiven N rectangles, find the maximum subset that can be strictly ordered by lower-left to upper-right containment, solvable via DP with a segment tree over compressed coordinates.Medium7Dynamic programmingSegment tree+2No attempts yet2s128 MBJudgeable
MusicInsert non-consecutive rest symbols into three note sequences to equalize their lengths while maximizing a column-matching score, or report impossibility.Medium7Dynamic programmingString+1No attempts yet2s128 MBJudgeable
Top Shelf of the BookshelfPick up to 10 book titles, sorted lexicographically, so that no two neighboring titles share the same letter at any aligned alphabetic position, maximizing total preference score.Medium7Dynamic programmingString+2No attempts yet2s128 MBJudgeable
Number Game 2Given a set of integers and a cap K on how many may be summed, find the first integer that cannot be formed and decide which player loses at that turn.Medium7Dynamic programmingMath+2No attempts yet2s128 MBJudgeable
Trash CleanupGiven a grid with trash cells, find the minimum number of top-left-to-bottom-right monotone paths needed to cover every trash cell.Medium7Dynamic programmingSorting+2No attempts yet2s128 MBJudgeable
Racing ResultsCount how many full car rankings are consistent with given pairwise 'beat' results, essentially counting linear extensions of a partial order mod 1,000,003.Medium7Dynamic programmingCombinatorics+2No attempts yet2s128 MBJudgeable
Inverse Descent PermutationsCount permutations of size N with a fixed first element F whose inverse permutation has exactly K descents.Medium7CombinatoricsDynamic programming+1No attempts yet2s128 MBJudgeable
Farmland LevelingGiven N heights forming a 1D terrain, find the minimum number of unit cells to remove so that the number of resulting peaks is at most K.Medium7Dynamic programmingGreedy+1No attempts yet2s128 MBJudgeable
Number PairingGiven an N x 3 grid, find a perfect domino tiling that maximizes and minimizes the total sum of absolute differences over all pairs.Medium7Dynamic programmingGreedy+1No attempts yet2s128 MBJudgeable
BallerinoFind the minimum extra cushions needed for a knight-move dancer to reach the goal on a grid with stones, and count how many minimal cushion sets work.Medium7Shortest pathBFS+2No attempts yet2s128 MBJudgeable
Parcel DeliveryGiven each parcel's destination branch along a line, find the minimum cost to deliver all parcels using per-distance trucks and fixed-cost multi-parcel helicopter trips.Medium7Dynamic programmingSorting+2No attempts yet2s128 MBJudgeable
Tetris StackingGiven a sequence of up to 100 Tetris pieces falling into a width-3 field, choose each piece's rotation and column to minimize the final stack height.Medium7Dynamic programmingSimulation+2No attempts yet2s128 MBJudgeable
Seat SwappingGiven N students each with a team label (K up to 8), find the minimum adjacent swaps to group each team into one contiguous block in some chosen team order.Medium7Dynamic programmingBit manipulation+1No attempts yet2s128 MBJudgeable
Expression RepresentationCompute the minimum number of 1-symbols needed to build an integer n using +, *, ! and parentheses, using DP over factorial and multiplicative decompositions.Medium7Dynamic programmingMath+1No attempts yet2s128 MBJudgeable
Bookcase ConstructionPartition n books into three non-empty groups to minimize the sum of per-shelf maximum heights times the maximum total thickness of any shelf.Medium7Dynamic programmingSorting+1No attempts yet5s128 MBJudgeable
Ladder GameGiven a ladder diagram, find the minimum cost of removing existing rungs and adding new rungs so a traveler starting at column a ends at column b.Medium7Dynamic programmingSimulation+1No attempts yet2s128 MBJudgeable
Increasing SequenceGiven a digit string up to 80 characters, split it into a strictly increasing sequence of integers (leading zeros allowed) minimizing the last number's value.Medium7Dynamic programmingString+1No attempts yet2s128 MBJudgeable
Number GameGiven a sequence of numbers, determine the winner of a two-player suffix-removal game where each player takes a suffix block ending at the current rightmost element and minimizes their own total sum, for three separate games with n up to 3000.Medium7Dynamic programmingGame theory+1No attempts yet2s128 MBJudgeable
Wire ConnectionDecide whether a subset of given semicircular wires can be joined end to end, with free rotation at joints, to form one closed non-overlapping loop.Medium7GeometryDynamic programming+1No attempts yet2s128 MBJudgeable
Counting Base RepresentationsCount the ways to split a digit string into a base suffix and a sequence of no-leading-zero digit values all less than that base.Medium7Dynamic programmingString+1No attempts yet2s128 MBJudgeable
Image EnergyAssign each grid cell to black or white to minimize per-cell cost plus adjacency mismatch cost, solvable via min-cut on a grid graph.Medium7GraphDynamic programming+1No attempts yet2s128 MBJudgeable
Final Drive RouteGiven a graph where only minimum-fatigue outgoing edges per city are usable, find the S to T route minimizing total fatigue then total length, detecting unreachable or unbounded (negative cycle) cases.Medium7GraphShortest path+1No attempts yet2s128 MBJudgeable
Chip ConstructionGiven N component priorities and K non-crossing power lines each serving up to two components, find a nesting-valid pairing that maximizes total sum of squares/products.Medium7Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Building a TournamentGiven a sequence of distinct ranks, build a bracket by repeatedly merging adjacent intervals (like matches in a tournament) minimizing the total sum of absolute rank differences over all merges.Medium7Dynamic programmingDivide and conquer+1No attempts yet2s128 MBJudgeable
Drawing a Mountain RangeGiven n polyline points, choose K interior points (plus both endpoints) to form an approximating polyline that minimizes the total area between it and the original mountain outline.Medium7Dynamic programmingGeometry+1No attempts yet2s128 MBJudgeable
Turning Off StreetlightsFind the optimal order to switch off all streetlights on a line, starting from a given position, minimizing sum of power times shutoff time, a classic interval DP problem.Medium7Dynamic programmingGreedy+1No attempts yet2s128 MBJudgeable
Binary Tree DrawingGiven a binary tree reconstructed from preorder and inorder traversals, compute the minimum area of a grid drawing where each right child extends the row and each down child extends the column.Medium7Dynamic programmingTree+1No attempts yet2s128 MBJudgeable
Three-Way CallFind a minimum-cost subtree (Steiner tree) connecting three given switches in a weighted graph and output the cost and chosen edges.Medium7GraphShortest path+1No attempts yet2s128 MBJudgeable
Maximum String PastingGiven a long string and up to 500 short patterns, find all their occurrences and select non-overlapping intervals to maximize total covered length via DP.Medium7String matchingDynamic programming+1No attempts yet1s128 MBJudgeable
Department AssignmentGiven friend/rival constraints among N employees, decide via union-find with parity whether a bipartition exists and, if so, find the split minimizing the size difference between two groups using a subset-sum style DP over component sizes.Medium7Union-findDynamic programming+1No attempts yet1s128 MBJudgeable
BookshelfPartition an ordered sequence of books into contiguous shelves to minimize the max of total shelf-height sum and the largest shelf-width, using binary search plus greedy/DP feasibility check.Medium7Binary searchGreedy+1No attempts yet1s128 MBJudgeable
Mobile Binary NumberGiven a nested-bar mobile whose bars may each be flipped independently, find the K-th lexicographically smallest distinct binary string obtainable across all flip combinations.Medium7Dynamic programmingRecursion+2No attempts yet1s128 MBJudgeable
Crossing SegmentsGiven segments between two parallel lines that are 2-colorable by non-crossing constraint, find the longest chain where consecutive segments cross.Medium7Dynamic programmingSorting+1No attempts yet1s128 MBJudgeable
High-Speed RailwayCount subsets of interval-graph vertices forming a vertex cover of the interval overlap graph, modulo a given number.Medium7IntervalsDynamic programming+1No attempts yet1s128 MBJudgeable
Car RaceGiven a directed graph with no cycles avoiding vertex 1, find the maximum-score simple route from checkpoint 1 back to checkpoint 1 and print it.Medium7GraphDynamic programming+1No attempts yet1s128 MBJudgeable
DNA SimilarityFind the lexicographically smallest longest common subsequence of two DNA strings where adjacent picked characters in each string must be within index-distance K.Medium7Dynamic programmingStringNo attempts yet1s128 MBJudgeable
Connecting RectanglesGiven N candidate axis-aligned rectangles with weights equal to their index, select a maximum-weight subset of pairwise non-overlapping and non-touching rectangles.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Optimizing Mobile Phone Text EntryPartition the 26 letters into K ordered contiguous groups (max 8 each) to minimize frequency-weighted key presses, breaking ties by lexicographically smallest concatenated output.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Secret WordsGiven secret words and a target string, find minimum total rearrangement cost to build the target by concatenating (possibly rearranged) copies of the words, or -1 if impossible.Medium7Dynamic programmingString+1No attempts yet1s128 MBJudgeable
Romantic KingGiven a grid with a start, an end, and up to 16 gift trees where movement speed decreases with carried gifts, find the maximum number of gifts deliverable within a time limit.Medium7BFSDynamic programming+1No attempts yet10s128 MBJudgeable
Business ExpansionGiven a directed graph, find a walk from city 1 to city 2 and back to city 1 that minimizes the number of distinct visited cities.Medium7Shortest pathGraph+1No attempts yet1s128 MBJudgeable
Function Return ValueGiven N nested loops whose bounds are either fixed integers or an outer loop variable, compute the total iteration count modulo 1e9+7.Medium7Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
GremlinsGiven a graph of gremlin reproduction with hatching and growth delays over T years (T up to 10^15), compute the maximum number of ancestors any gremlin has.Medium7Dynamic programmingGraph+1No attempts yet1s128 MBJudgeable
Clearing the BeadsFind the minimum number of beads to insert between colored beads so every bead can eventually be cleared by removing runs of length at least K.Medium7Dynamic programmingStack+1No attempts yet1s128 MBJudgeable
Explosion-Safe FoldingCount ways to fold N tape pieces at seams (straight or 180 degree) so coated faces never touch, given coating patterns from both ends, modulo 10301.Medium7Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Strange PainterReconstruct a picture painted by a recursive quadrant-coloring process closest (in Hamming distance) to a given N x N binary target, then output that minimal difference and the picture.Medium7Divide and conquerDynamic programming+1No attempts yet1s128 MBJudgeable
A=SInsert plus signs between digits of a huge number A so the resulting sum equals a small target S, using as few plus signs as possible.Medium7Dynamic programmingString+1No attempts yet1s128 MBJudgeable
VictoryCount first moves in a circular pick-up game with adjacency constraints that force a win for the first player against an optimal second player counting odd numbers picked.Medium7Dynamic programmingGame theory+1No attempts yet1s128 MBJudgeable
HousewarmingGiven a grid with blocked cells, find the maximum rectangle of empty cells and output twice its width plus height (the perimeter).Medium7Dynamic programmingStack+1No attempts yet1s128 MBJudgeable
CookiesCount, modulo 10007, the number of orders of choosing cookies on a circle so that each chosen cookie's two current neighbors always match in flavor, until 1 or 2 remain.Medium7Dynamic programmingCombinatorics+1No attempts yet5s128 MBJudgeable
BakeryGiven a grid where pipelines move from the first column to the last column stepping right, diagonal-up-right or diagonal-down-right without sharing cells, find the maximum number of vertex-disjoint such paths.Medium7GraphGreedy+1No attempts yet1s256 MBJudgeable
LakeCount simple cycles in a fixed circular ladder graph with some edges removed, given three binary strings of usable inner, outer, and bridge edges, modulo 1e9+7.Medium7GraphDynamic programming+1No attempts yet1s128 MBJudgeable
BulbsGiven a target 2×N binary grid, find the minimum number of toggle operations on contiguous row or column segments to reach that pattern.Medium7Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
HighwayGiven a road profile and costs for flat, sloped, tunnel or viaduct travel, find the minimum time to cross using at most K equal-height shortcut structures.Medium7Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Railway Route CoverGiven a tree, partition all vertices into vertex-disjoint paths covering every node so that the total edge weight used by the paths is maximized, using tree DP.Medium7Dynamic programmingTree+1No attempts yet1s128 MBJudgeable
Pilot CrewsGiven pilots sorted by age with captain and assistant salaries, pair them into captain-older-than-assistant crews minimizing total salary paid.Medium7GreedySorting+1No attempts yet1s128 MBJudgeable
Jozo's Train TripGiven stations, railways, and scheduled trains, find the minimum station-waiting time for a trip starting at station 1 at time 1 and returning to station 1 within a given time window.Medium7Shortest pathGraph+1No attempts yet2s128 MBJudgeable
Two Snow PlowsGiven a tree rooted at S, find minimum total edge traversal cost for two walks starting at S that together cover every edge, without returning to S.Medium7TreeDynamic programming+1No attempts yet1s128 MBJudgeable