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,698 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Product Sum QueriesFor each query K, sum the products of all K-element subsets of A, counting positions separately, modulo 100003.Medium6Dynamic programmingCombinatorics+1No attempts yet2s512 MBJudgeable
Daruma OtoshiGiven a stack of weighted blocks, remove adjacent pairs whose weights differ by at most 1, in any order, to maximize the total removed.Medium6Dynamic programmingIntervalsNo attempts yet2s512 MBJudgeable
Big TruckFind a shortest path from node 1 to node n in an undirected weighted graph, and among all shortest paths maximize the total items collected at visited nodes.Medium6GraphShortest path+2No attempts yet2s512 MBJudgeable
Nine PacksGiven multiset pile sizes of hotdog and bun packs, buy the fewest total packs so the chosen hotdogs and buns sum to the same number.Medium6Dynamic programmingNo attempts yet2s512 MBJudgeable
A Typo in FloydCount ordered pairs whose shortest-path values differ when Floyd's outer loop skips vertex N as an intermediate.Medium6Shortest pathDynamic programming+1No attempts yet2s512 MBJudgeable
Message PassingCount the telephone calls made at time t when each informed employee calls d new people over the next d time units, modulo 31991.Medium6Dynamic programmingCombinatorics+1No attempts yet1s512 MBJudgeable
Bless You Autocorrect!For each target word, compute the fewest keystrokes using letter keys, tab (autocomplete to the most common dictionary word matching the typed prefix), and backspace.Medium6TrieDynamic programming+1No attempts yet3s512 MBJudgeable
Coin ExchangeGiven the generating-function coefficients of a coin multiset, answer queries that remove N coins of value V and report the new coefficient of x^D modulo 1e9+7.Medium6Dynamic programmingCombinatorics+1No attempts yet2s512 MBJudgeable
Iterated SumsCompute S(k, n) mod 1,000,000,007, where S iterates prefix sums k times starting from S(0, n) = n.Medium6CombinatoricsMath+1No attempts yet2s512 MBJudgeable
Painting the BoardGiven a grid picture of black and white squares, find the minimum number of horizontal or vertical strokes that paint exactly the required black squares.Medium6Dynamic programmingGreedy+1No attempts yet2s512 MBJudgeable
SW Skill TestPick and order problems within T minutes, each solved back to back, to maximize the sum of M_i - (start minute) * P_i.Medium6Dynamic programmingSorting+1No attempts yet2s512 MBJudgeable
Safe RacingCount binary circular arrangements of L booths where every S consecutive booths contain at least one marshal, modulo 123456789.Medium6CombinatoricsDynamic programming+1No attempts yet2s512 MBJudgeable
JetpackFind the lexicographically smallest schedule of screen holds that moves Barry right across N columns through a 10-row grid while avoiding obstacles.Medium6Dynamic programmingGreedy+2No attempts yet1s64 MBJudgeable
MacbethGiven n time intervals and w witches, each witch predicts a chain of non-overlapping intervals, so find the maximum number of intervals coverable by w chains.Medium6IntervalsGreedy+1No attempts yet2s512 MBJudgeable
CompilerPrint the specific 40-instruction-bounded program that displays N on a one-register display, following the stated decomposition rule.Medium6Dynamic programmingMath+1No attempts yet2s512 MBJudgeable
Knight Moves to a CornerCount knight walk sequences of length at most k starting from a board corner and ending on any corner of a 2n x 2n board, modulo 1000007.Medium6Dynamic programmingMatrix+1No attempts yet5s512 MBJudgeable
Unstacking BoxesBoxes sit in piles in a row; a box can be removed only when it is on top and at least one side is unblocked. Find the fewest removals needed to expose box 1.Medium6Dynamic programmingGreedy+1No attempts yet1s512 MBJudgeable
Even Number of TollsFind the cheapest walk from city 1 to city C in a weighted undirected graph where the number of edges traversed (tolls paid) must be even, counting repeated edges each time.Medium6GraphShortest path+2No attempts yet1s512 MBJudgeable
TeleportationCount length-L button sequences that move from ship S to ship T, where each ship has four outgoing transitions, modulo 10^4.Medium6MatrixDynamic programming+1No attempts yet2s512 MBJudgeable
Buses and MinibusesGiven a total line length N, count ordered sequences of 10-meter buses and 5-meter minibuses with K minibus colors and L bus colors, and print the last six digits.Medium6CombinatoricsDynamic programming+1No attempts yet2s512 MBJudgeable
CardsGiven an even row of cards with integers, two players alternately take an end card; the first player maximizes his total sum while the second minimizes it. Report the best score the first player can guarantee.Medium6Dynamic programmingGame theory+2No attempts yet2s512 MBJudgeable
Alien Ribonucleic AcidFor each strand, compute the largest number of base pairs (B-S and C-F) that can form when disjoint intervals fold onto themselves.Medium6Dynamic programmingIntervalsNo attempts yet2s512 MBJudgeable
Cash BookGiven N amounts and a signed total F, decide for each amount whether it is forced to be added, forced to be subtracted, or free, over all sign choices summing to F.Medium6Dynamic programmingBacktracking+2No attempts yet2s512 MBJudgeable
Survival Probability of a Water FleaCount the paths of length n on a line starting at k that never return to 0, so the survivor count is S in S/2^n.Medium6CombinatoricsDynamic programming+1No attempts yet5s512 MBJudgeable
Longest Common Subsequence of Two PermutationsTwo permutations of 1 to N are given; find the length of their longest common subsequence.Medium6Dynamic programmingBinary searchNo attempts yet2s512 MBJudgeable
Painting the fencePick a pairwise non-overlapping set of intervals to cover as many of the n slats as possible, then report the number left unpainted.Medium6SortingDynamic programming+2No attempts yet2s512 MBJudgeable
Longest Zigzag SubsequenceFind the length of the longest subsequence whose adjacent comparisons strictly alternate between up and down.Medium6Dynamic programmingGreedyNo attempts yet2s512 MBJudgeable
BarbellsGiven up to 14 bars and 14 plates, find every total weight obtainable by putting plates on both sides of one bar so that the two sides balance.Medium6Brute forceHash map+2No attempts yet2s512 MBJudgeable
Banking IIGiven a PIN and a leftover lowercase pattern, insert uppercase skips so the letter values sum to the PIN length, maximizing the extracted digit sum.Medium6Dynamic programmingGreedyNo attempts yet1s512 MBJudgeable
Pokemon Identification SystemWith a budget B, buy k_f agents for each feature (k_f >= 1) to maximize the product of 1-(1-r_f)^k_f, and report the smallest optimal cost.Medium6Dynamic programmingMath+1No attempts yet2s512 MBJudgeable
Step Step EvolutionGiven a sequence of dance-pad arrows, find the minimum number of adjacent pairs pressed by the same foot, respecting the left/right column rule.Medium6Dynamic programmingGreedy+2No attempts yet8s512 MBJudgeable
Optimal RestGiven a sequence of R commands with dotted durations, find the shortest valid equivalent expression, breaking ties by lexicographic order.Medium6Dynamic programmingGreedy+2No attempts yet8s512 MBJudgeable
So SleepyFind the longest total time asleep on one train while traveling from a start station and time to an appointment station by a deadline.Medium6GraphShortest path+1No attempts yet8s512 MBJudgeable
Lying about your ageTrack the smallest claimable value at a real age given a starting claim, where a claim read in some base equals the real age and claims never decrease.Medium6Number theoryDynamic programming+1No attempts yet8s512 MBJudgeable
University RankingsGiven M rankings of N universities, find the longest sequence where each earlier university beats the next in every ranking.Medium6Dynamic programmingSorting+1No attempts yet8s512 MBJudgeable
Building Uppercase SentencesCount the distinct uppercase sentences you can form by deleting letters and grouping the rest into blocks of three identical letters.Medium6Dynamic programmingStringNo attempts yet1s256 MBJudgeable
Finding a HouseOn a weighted undirected graph, find the vertex with no McDonald's or Starbucks whose distance to the nearest McDonald's is at most x, to the nearest Starbucks at most y, and whose two distances sum to the minimum.Medium6GraphShortest path+1No attempts yet1s256 MBJudgeable
Alien Creature NumberingCount the labelings of a complete binary tree of height H with 1..2^(H+1)-1 where every parent's label is smaller than its children's labels, modulo 1e9+7.Medium6CombinatoricsTree+1No attempts yet1s256 MBJudgeable
PohlepkoFind the lexicographically smallest string read along a monotone path from the top-left to the bottom-right cell of a grid of lowercase letters.Medium6Dynamic programmingGreedy+2No attempts yet1s64 MBJudgeable
Emptying the GlassesGiven N glasses and pairwise pour costs, find the minimum effort to end with water in at most K glasses.Medium6Dynamic programmingGraph+2No attempts yet2s32 MBJudgeable
Merging Files 2Given the sizes of K consecutive chapter files, find the minimum total cost of merging them two at a time into one file, where each merge costs the sum of the two sizes.Medium6Dynamic programmingPrefix sumNo attempts yet6s512 MBJudgeable
Small PhD RestaurantGiven N challenges with cost A_i and payoff B_i, starting money M, choose an order to maximize final money while affording each cost.Medium6GreedySorting+1No attempts yet2s512 MBJudgeable
The Longest Travel RouteGiven a directed weighted graph with at most 18 cities, find the maximum total length of a simple path from city 0 to city n-1.Medium6Dynamic programmingBit manipulation+2No attempts yet2s512 MBJudgeable
Grayscale PhotoCount the color photos (RGB triples) whose floor average matches each given gray value, modulo 10007.Medium6CombinatoricsMath+1No attempts yet1s512 MBJudgeable
Anadrome splitSplit a lowercase word into the fewest substrings that are each anagrams of some palindrome, breaking ties by the lexicographically smallest printed line.Medium6Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Multiple SubsequenceGiven a sequence, find the longest subsequence where each element is a larger multiple of the previous one.Medium6Dynamic programmingSortingNo attempts yet2.5s256 MBJudgeable
Connecting switches to bulbsCount the number of functions from A numbered switches onto B numbered bulbs, modulo 1000000007, i.e. B! times Stirling number of the second kind S(A, B).Medium6CombinatoricsDynamic programming+2No attempts yet1s64 MBJudgeable
Cow ChecklistFind the cheapest path that visits all Holsteins in order and all Guernseys in order, starting at Holstein 1 and ending at Holstein H.Medium6Dynamic programmingGeometryNo attempts yet2s512 MBJudgeable
Electoral CollegeGiven each state's win probability and electoral votes, find the probability that Jenabkhan gets more than half of the total electoral votes.Medium6Dynamic programmingProbabilityNo attempts yet2s512 MBJudgeable
Halting MachineParse N goto statements, build a directed graph, and print the longest path length from line 0 to line N, or infinity if a cycle is reachable on some path to N.Medium6GraphDynamic programming+2No attempts yet2s512 MBJudgeable
Key Rearrangement 2Given n keys with lists of compatible keyholes and a time limit k, decide whether a perfect matching exists with total |i-j| cost at most k.Medium6Dynamic programmingBit manipulation+2No attempts yet2s512 MBJudgeable
Partitioning Balls into BucketsCount the ways to split N balls into buckets whose sizes are non-decreasing, span at most 2, and start with a value divisible by D.Medium6Dynamic programmingMath+2No attempts yet5s512 MBJudgeable
Partitioning Number (Large)Count non-decreasing partitions of N whose first part is divisible by D and whose parts span a range of at most 2.Medium6Dynamic programmingCombinatorics+2No attempts yet5s512 MBJudgeable
Monster Path (Small)Given a small grid, a start cell, and a fixed step count, choose a walk maximizing the expected number of distinct monsters caught.Medium6Dynamic programmingBit manipulation+1No attempts yet5s512 MBJudgeable
Counting Distinct SubsequencesCount the distinct subsequences of a string, including the empty string, for up to 10,000 test cases.Medium6Dynamic programmingString+1No attempts yet1s512 MBJudgeable
WhitespaceGiven the line lengths of a Whitespace program and a RETURN key that duplicates the current line's spaces, find the minimum key presses to build the text from a single newline.Medium6Dynamic programmingGreedy+1No attempts yet2s512 MBJudgeable
Sequence PermutationsCount how many distinct permutations of 1..N are reachable from the sorted order by exactly M adjacent swaps, modulo 1,000,000,009.Medium6Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Two OperationsStarting from X = Y = 1, repeatedly add one variable to the other, and find the shortest (then lexicographically smallest) operation string that makes N appear.Medium6BFSGraph+2No attempts yet2s512 MBJudgeable
Hoof, Paper, Scissors (Gold)Given John's sequence of N gestures and at most K gesture switches, find the maximum number of games Bessie can win.Medium6Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Why Did the Cow Cross the Road 7On an N x N grid, find the fastest route from the top-left to the bottom-right cell when every third move forces Bessie to spend that cell's eating time.Medium6GraphShortest path+2No attempts yet2s512 MBJudgeable
Snake JOIFind the shortest travel time from room 1 to room N where entering a hot room requires X minutes since last leaving a cold room, and vice versa.Medium6Shortest pathGraph+1No attempts yet2s512 MBJudgeable
MemoryGiven R times C face-down cards forming pairs, find the best-case and worst-case number of actions a perfect-memory player needs to clear the board.Medium6Game theoryMath+2No attempts yet1s256 MBJudgeable
Taekwondo KingWith S < T, using combo A doubles S but adds 3 to T, and combo B adds 1 to S. Find the fewest kicks that make S equal T.Medium6Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Younghoon's Coloring BookCount the ways to place one red and one blue cell in each row and column of an N x N grid, with no cell both colors, modulo 1e9+7.Medium6CombinatoricsMath+1No attempts yet1s128 MBJudgeable
Island TripGiven an undirected graph with node heights, for each query (A, K) find the minimum height reachable from A in exactly K edge steps, or -1 if impossible.Medium6GraphDynamic programming+2No attempts yet1s256 MBJudgeable
PosterizeChoose k allowed red values so the weighted sum of squared distances from the d distinct intensities is minimized.Medium6Dynamic programmingMath+2No attempts yet2s512 MBJudgeable
Sickly YunhoGiven a string of B, L, D doses, remove from either end in the fixed order B, L, D, B, L, D... and find the most doses removable before the required dose is missing from both ends.Medium6Dynamic programmingArray+2No attempts yet1s512 MBJudgeable
The County FairFarmer John visits booths with fixed giveaway times and directed travel times, choosing a route that collects the most prizes.Medium6Dynamic programmingGraph+1No attempts yet2s512 MBJudgeable
Fashion ShowGiven a legal partial placement of +, x, and o models on an N by N grid, add or upgrade models to maximize style points under the row/column and diagonal rules.Medium6GraphTwo pointers+2No attempts yet5s512 MBJudgeable
Fresh Chocolate (Small)Choose the order of groups so that as many as possible receive only chocolate from freshly opened packs, given that leftovers must be finished first.Medium6GreedyMath+2No attempts yet5s512 MBJudgeable
Dumpling shop owner Seungwon ParkMake at most limited numbers of m filler dumplings and unlimited filler-free ones from n grams of flour to maximize sales.Medium6Dynamic programmingGreedy+1No attempts yet2s512 MBJudgeable
CatsFind the minimum number of moves to reorder a line of cats, dogs, and lions so no cat is adjacent to a dog.Medium6GreedyDynamic programming+2No attempts yet1s16 MBJudgeable
Playing with FireTwo distinct people start just above the burning top tile and each step down or diagonally, never landing on the same tile; count escape sequences.Medium6Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Game MapGiven an undirected connected graph, find the longest simple path where the degree of each successive vertex strictly increases.Medium6GraphDynamic programming+2No attempts yet1s512 MBJudgeable
Lemonade TradeGiven a sequence of one-way lemonade exchanges walked in order, find the maximum litres of blue obtainable starting from one litre of pink, capped at 10.Medium6Dynamic programmingHash map+1No attempts yet2s512 MBJudgeable
Stationary bike programsCount sequences of T levels where each step changes by exactly 1 and all values stay between M and N, modulo 1e9+7.Medium6Dynamic programmingNo attempts yet1s1024 MBJudgeable
HipercampoGiven two anchors on the x-axis and N points above, choose the largest subset whose segments to both anchors meet only at the anchors.Medium6GeometrySorting+2No attempts yet1s1024 MBJudgeable
Red RoverGiven a route string over N, S, E, W of length at most 100, find the minimum total length of a message using one optional macro M and its definition that expands to the route.Medium6Dynamic programmingStringNo attempts yet2s512 MBJudgeable
A Question of IngestionGiven n hourly courses with calorie counts, maximize total calories eaten when the per-hour limit starts at m, shrinks to two thirds while eating, and resets after two skipped hours.Medium6Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Ducks in a RowFind the fewest flips needed so the string contains at least k maximal runs of D of length at least n.Medium6Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Jumping HaybalesOn an n by n grid with haybale obstacles, find the fewest jumps of length 1 to k moving only east or south from the top-left corner to the bottom-right corner, or -1 if unreachable.Medium6BFSDynamic programming+2No attempts yet2s512 MBJudgeable
Dangerous DiscusGiven falling acid drops in columns, decide whether the single-pixel disc can stay at some height and cross without ever touching a drop.Medium6Dynamic programmingSliding window+2No attempts yet2s512 MBJudgeable
Intuidiff IIGiven intervals in the order they appear in a modified document, choose a subsequence of intervals whose original ranges strictly increase; maximize total characters left plain.Medium6Dynamic programmingIntervals+2No attempts yet4s512 MBJudgeable
Just Terraffic!Given sorted trigger times, count cars with two axles and cars with three axles where gaps under 1000 ms join the same vehicle and gaps over 2000 ms split them.Medium6Dynamic programmingGreedyNo attempts yet3s512 MBJudgeable
Asphalt PavingGiven segments on a triangular grid, choose the largest subset so that no two share an endpoint at an acute angle.Medium6GraphDynamic programming+2No attempts yet1s512 MBJudgeable
Dice BettingCompute the probability that at least k distinct values appear when an s-sided die is rolled n times, and print it to nine decimals.Medium6ProbabilityDynamic programming+2No attempts yet2s512 MBJudgeable
Hay BalesGiven a string of C and P, each move sorts any three consecutive characters so all C come before all P; find the minimum number of moves to fully sort the whole row.Medium6GreedyString+2No attempts yet2s512 MBJudgeable
Global WarmingThe friendships form a disjoint union of cliques, so each connected component of even size must be split into a perfect matching of minimum total cost.Medium6GraphDynamic programming+2No attempts yet5s512 MBJudgeable
Friend PalindromeGiven a friendship graph on up to 20 students, find the largest number of students that can form a palindrome-like line where every student except the possible middle one is paired with a friend.Medium6Dynamic programmingBit manipulation+2No attempts yet2s512 MBJudgeable
Decisions, DecisionsGiven the truth table of an n-variable boolean function, count the vertices in its unique minimal binary decision diagram.Medium6Dynamic programmingDivide and conquer+2No attempts yet2s512 MBJudgeable
PaversCount the tilings of a 2 x n board with 1x1 squares, 2x1 rectangles, and L-trominoes, and sum the total number of each paver over all tilings.Medium6Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
A Strange TournamentGiven a sequence of distinct powers, choose a non-crossing knockout bracket minimizing the total absolute difference over all matches played.Medium6Dynamic programmingDivide and conquer+2No attempts yet2s512 MBJudgeable
Paasa NumbersFind the Nth positive integer whose digits never increase from left to right, given N up to 10^18 and 10^4 queries.Medium6CombinatoricsDynamic programming+2No attempts yet3s512 MBJudgeable
ExpressionFor each pair (x, y) print a postfix expression over x, +, -, *, / whose value is y, using the fixed construction the statement describes.Medium6Dynamic programmingImplementation+1No attempts yet4s512 MBJudgeable
Enumerating BracketsGiven N and M, print the M-th balanced bracket sequence of length N in lexicographic order, where '(' is smaller than ')'.Medium6CombinatoricsDynamic programming+2No attempts yet2s512 MBJudgeable
Barn PaintingCount the proper 3-colorings of a tree consistent with some pre-colored nodes, modulo 1e9+7.Medium6TreeDynamic programming+2No attempts yet2s512 MBJudgeable
Minimum editCompute the Levenshtein distance between two lowercase strings, using the fewest insert, delete, and replace operations to change A into B.Medium6Dynamic programmingString+2No attempts yet2s512 MBJudgeable
Tap Titanz at Moloco (Easy)On an n by n black/white board, each tap flips a whole same-color connected region; find the minimum taps to make the board one color.Medium6GraphBFS+2No attempts yet2s512 MBJudgeable
Farm VillageEach house along a road needs one crop unit and can grow up to two; minimize the total growing cost plus cost of carrying crops between neighbors.Medium6Dynamic programmingGreedyNo attempts yet2s512 MBJudgeable
The PricesChoose for each product a wholesaler to buy it from, paying each visited wholesaler's round-trip cost once, to minimize the total.Medium6Dynamic programmingBit manipulation+2No attempts yet2s512 MBJudgeable