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,705 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Greeting Card EnvelopesPartition up to 15 card types into at most k groups so the total waste, where each group's waste uses one enclosing envelope sized to the group's max width and max height, is minimized.Medium7Dynamic programmingBit manipulation+2No attempts yet3s512 MBJudgeable
FunfairPick and order k games from n so the expected final money is maximized, then report that value.Medium7Dynamic programmingSorting+1No attempts yet2s512 MBJudgeable
CafebazaarAssign each full-time developer and each critical application to a matching partner while maximizing total payoff, or report -1 if impossible.Medium7GraphDynamic programming+1No attempts yet2s512 MBJudgeable
Delete FilesGiven a top-aligned list of name boxes with widths, find the minimum number of axis-aligned rectangle selections whose deletions remove all 'y' files and keep all 'n' files.Medium7Dynamic programmingGeometry+2No attempts yet5s512 MBJudgeable
SpeedrunGiven per-road win probabilities, choose checkpoints to save at so the expected time to reach checkpoint n is minimized.Medium7ProbabilityDynamic programmingNo attempts yet8s512 MBJudgeable
Cookie CounterCount sequences of D days, each amount in [0, X), summing to N, modulo 1e9+7.Medium7CombinatoricsDynamic programming+1No attempts yet8s512 MBJudgeable
Rock Paper Scissors RankingGiven each contestant's probabilities for scissors, rock, and paper, find the probability that contestant 1 finishes in place K of the recursive elimination tournament.Medium7ProbabilityDynamic programming+1No attempts yet2s512 MBJudgeable
Greedy Coin ExchangeGiven sorted coin denominations starting with 1, decide whether the greedy largest-coin-first method always uses the fewest coins for every amount.Medium7GreedyDynamic programming+2No attempts yet1s64 MBJudgeable
Knapsack in a Globalized WorldWith unlimited copies of n item sizes, decide whether some multiset sums to exactly k, where k can reach 10^18.Medium7Number theoryDynamic programming+1No attempts yet2s512 MBJudgeable
RoutingFind the minimum total processing time for a message from server 1 to server n, where each server blocks forwarding certain (previous server, next server) pairs and revisiting servers adds their cost again.Medium7GraphShortest path+2No attempts yet2s512 MBJudgeable
AbilityCompute the expected damage of one attack where abilities are tried in a uniformly random order without replacement until one fires, and output the fraction modulo 1e9+7.Medium7ProbabilityMath+2No attempts yet2s512 MBJudgeable
BitsGiven N bits and K odd random index toggles per operation after sorting, compute for each starting zero count the expected number of operations to reach all ones.Medium7ProbabilityDynamic programming+1No attempts yet2s512 MBJudgeable
CardsFind the probability that L random packs of N equally likely card types meet every demand D_i, output as a fraction mod 1e9+7.Medium7Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
KangarooCount the alternating-direction routes by which a kangaroo visits every cell of a row exactly once, starting at cs and ending at cf.Medium7Dynamic programmingCombinatoricsNo attempts yet2s512 MBJudgeable
Reading the stone slabAfter each range replacement on a string, count the number of subsequences equal to a given name of length at most 5, modulo 1e9+7.Medium7Dynamic programmingSegment tree+1No attempts yet4s256 MBJudgeable
Lottery interestCompute Kangho's expected balance after C weekly lottery drawings, where each ticket (one per won) is equally likely to win J, and print the exact fraction.Medium7ProbabilityMath+1No attempts yet2s512 MBJudgeable
Birthday CakeCount proper colorings of a cycle with N vertices and K colors, plus a center, as vertices are forced to differ from the center over time.Medium7Dynamic programmingCombinatorics+1No attempts yet2s256 MBJudgeable
Arcade!Given a triangular grid of holes with per-hole bounce probabilities and payouts, compute the expected payout of one dropped ball.Medium7ProbabilityDynamic programming+2No attempts yet2s512 MBJudgeable
Gas StationsIn a connected undirected weighted graph, buy fuel at cities with given prices to travel from city 1 to city N at minimum total cost, with no tank limit.Medium7GraphShortest path+2No attempts yet2s512 MBJudgeable
Card Hand SortingGiven a hand of up to 52 distinct cards, find the minimum number of remove-and-reinsert moves needed so each suit forms a block with ranks sorted ascending or descending.Medium7SortingBrute force+1No attempts yet1s512 MBJudgeable
Jumping WormFind the shortest time for a worm to travel from the base of tree 1 to the top of tree N, where each climb, jump, and gravity rest costs one second, with a free move when standing on a tree top.Medium7GraphShortest path+2No attempts yet1s512 MBJudgeable
Meeting at the Agreed MinuteCount pairs of walks of length T from nodes 1 and N that meet only at minute T, modulo 9973.Medium7MatrixDynamic programming+1No attempts yet2s512 MBJudgeable
JumpTiles on a grid give energy when visited; jump only right or up at cost B, and maximize the energy left on reaching tile N.Medium7Dynamic programmingGraph+1No attempts yet2s512 MBJudgeable
Pry Sequence TransformationFind the minimum edit distance between strings A and B under weighted insert, delete, and replace costs, or print TOSS if it exceeds budget K.Medium7Dynamic programmingStringNo attempts yet2s512 MBJudgeable
Algorithm study membershipChoose two algorithm types for each of N members in a mentor tree so every team (a node plus its children) can assign distinct types to its members, minimizing total teaching cost.Medium7Dynamic programmingTree+2No attempts yet2s512 MBJudgeable
Partition into segments 2Split the array into at most M contiguous segments, minimizing the maximum difference between the largest and smallest value within any one segment.Medium7Binary searchDynamic programming+2No attempts yet2s512 MBJudgeable
Stair Climbing WorkoutCount length-N balanced U/D walk strings (never going below 0, ending at 0) that contain a given piece as a contiguous substring.Medium7Dynamic programmingCombinatorics+1No attempts yet2s512 MBJudgeable
Factorials and a recurrenceGiven N and K, compute the number of divisors of S(N,K), where S follows the given recurrence, modulo 1,000,000,009.Medium7Number theoryDynamic programming+2No attempts yet2s512 MBJudgeable
Metal Is LifeCount permutations of N distinct strings that satisfy up to 8 prefix constraints between fixed positions, modulo 1e9+7.Medium7CombinatoricsBit manipulation+2No attempts yet2s512 MBJudgeable
Stephen CookTwo players alternately assign truth values to variables of a boolean formula; Cook moves first and wins if the formula ends true. Decide the winner under optimal play.Medium7Game theoryDynamic programming+2No attempts yet3s256 MBJudgeable
Bridge AutomationGiven sorted boat arrival times, schedule bridge raises and lowers so no boat waits over 1800 seconds while minimizing total road closure time.Medium7Dynamic programmingGreedy+1No attempts yet2s512 MBJudgeable
The Witch's PuzzleGiven N words, permute the letters of each word independently and find the minimum number of nodes in the prefix tree (trie) of the resulting set.Medium7TrieDynamic programming+2No attempts yet2s64 MBJudgeable
GondolasPlace G gondolas at integer offsets on a loop of period 2T to minimize the total wait of N skiers, where each skier boards the first departure at or after their arrival.Medium7Dynamic programmingSorting+2No attempts yet5s512 MBJudgeable
Buying FlowersCount integer sequences x_i with 0 <= x_i <= f_i summing to S, where N <= 20 and S up to 1e14.Medium7CombinatoricsDynamic programming+2No attempts yet2s512 MBJudgeable
Birthday PartyCount ordered tuples of f positive integers summing to n whose greatest common divisor is 1, modulo 1e9+7, for up to 100000 queries.Medium7Dynamic programmingNumber theory+2No attempts yet5s512 MBJudgeable
Increasing subsequences of length KCount length-K index subsequences whose values are strictly increasing, modulo 5,000,000.Medium7Dynamic programmingSegment tree+2No attempts yet2s512 MBJudgeable
Distinct Increasing Subsequences of Length KCount the distinct value sequences of length K that appear as increasing subsequences of the given array, modulo 5000000.Medium7Dynamic programmingSorting+1No attempts yet2s512 MBJudgeable
Merging treesGiven a left-handed and a right-handed ternary tree, find the minimum number of vertices in a ternary tree that is a superposition of both.Medium7TreeDynamic programming+1No attempts yet1s512 MBJudgeable
Curious GuardiansCount labeled trees on N cities where every vertex has degree at most K.Medium7CombinatoricsDynamic programming+1No attempts yet1s512 MBJudgeable
Palindromic SubsequenceGiven a string and marked positions, find a palindromic subsequence covering the most marked positions, and report the length of the longest such one.Medium7Dynamic programmingStringNo attempts yet1s512 MBJudgeable
Convex polygon quadrangulationSplit a convex 2N-gon into N-1 quadrilaterals with diagonal cuts and find the minimum total cut length.Medium7Dynamic programmingGeometryNo attempts yet2s512 MBJudgeable
Folding MachineGiven two integer tapes, decide whether folding one tape can ever produce the other.Medium7Divide and conquerRecursion+2No attempts yet2s512 MBJudgeable
Space ElevatorFind the number on the N-th floor when floor numbers skip any containing the digit 4 or the substring 13, for N up to 10^18.Medium7Binary searchMath+2No attempts yet2s512 MBJudgeable
SMS ChampionshipGiven a keypad where letters need repeated presses and # separates same-key letters, find the minimum typing time with two alternating thumbs.Medium7Dynamic programmingNo attempts yet2s512 MBJudgeable
Random Sort 2Compute the expected number of random swaps the process needs to turn a given permutation of size up to 10 into increasing order.Medium7ProbabilityDynamic programming+2No attempts yet2s512 MBJudgeable
Buggy RobotGiven a grid and an existing command string, insert or delete single commands at minimum cost so the robot reaches the exit.Medium7Dynamic programmingBFS+1No attempts yet2s512 MBJudgeable
Water Supply UpgradesAfter each of k permanent capacity increases on edges of a small graph, report the maximum flow between station 1 and station 2.Medium7GraphDynamic programming+2No attempts yet2s512 MBJudgeable
Perfect SetsCount the subsets of {0,...,k} closed under bitwise XOR, where k can be as large as 10^9, modulo 10^9+7.Medium7Bit manipulationCombinatorics+1No attempts yet2s512 MBJudgeable
Distinct AND values of subsequencesCount how many distinct values can appear as the bitwise AND of some subsequence of a given array, including the empty subsequence whose AND is 0.Medium7Bit manipulationDynamic programming+2No attempts yet2s512 MBJudgeable
String HashingCount valid strings of any length over ASCII 32 to 126 whose base-31 polynomial hash equals a given string's hash, modulo 1e9+7.Medium7Dynamic programmingCombinatoricsNo attempts yet2s512 MBJudgeable
ButterflyChoose non-overlapping dates; each person pays only if all their dates are kept, so maximize total satisfaction.Medium7IntervalsDynamic programming+2No attempts yet8s512 MBJudgeable
Dungeon Quest IIGiven a fixed walking route through a grid of traps and up to 12 one-use potions, decide whether the agent can survive to the end.Medium7Dynamic programmingBit manipulation+1No attempts yet8s512 MBJudgeable
Merry ChristmasGiven a town road network and timed delivery requests, find the minimum number of Santas so every present arrives exactly at its scheduled time.Medium7Shortest pathDynamic programming+1No attempts yet8s512 MBJudgeable
Alice in FoxlandGiven two strings X and Y, find the longest common subsequence of X and Y that contains a required substring C as a contiguous block, or report impossible; among ties pick the lexicographically smallest.Medium7Dynamic programmingString+2No attempts yet8s512 MBJudgeable
The divisor conquersPlace the N cards one at a time so each new card divides the sum of the cards already down, and print the lexicographically smallest winning order or No.Medium7BacktrackingGreedy+2No attempts yet8s512 MBJudgeable
Sum of CubesWrite N as a sum of as few positive cubes as possible, and among the shortest sums output the one that is lexicographically largest.Medium7Dynamic programmingBrute force+2No attempts yet0.5s256 MBJudgeable
Hotel RewardsGiven nightly hotel prices and a K-points-per-free-night reward rule, find the minimum total cost of the whole trip.Medium7Dynamic programmingGreedy+1No attempts yet2s512 MBJudgeable
Permutation Descent CountsCount permutations of order N with exactly v descents, modulo 1001113, for up to 1000 queries with N at most 100.Medium7Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
AverageCount, over all N-tuples of integer marks from 0 to fullmarks, the total number of teachers whose mark equals the tuple's mean, modulo 1000000007.Medium7CombinatoricsDynamic programming+1No attempts yet1s512 MBJudgeable
Tree StandsCount the K-vertex subsets of a tree in which every chosen vertex is adjacent to at least one other chosen vertex, modulo 1000000007.Medium7TreeDynamic programming+1No attempts yet5s512 MBJudgeable
Quality ExpressionsGiven a bracket expression with ? placeholders and per-arity limits, choose values so the expression is valid and its value is as large as possible.Medium7Dynamic programmingTree+1No attempts yet1s64 MBJudgeable
Dinner BetGiven N balls, D drawn per round, and two size-C cards, find the expected number of rounds until one player completes their card.Medium7ProbabilityDynamic programming+1No attempts yet2s512 MBJudgeable
Pascal's Hyper-PyramidsCompute the distinct multinomial coefficients on the base layer of a D-dimensional Pascal hyper-pyramid of height H, printed in ascending order.Medium7Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Tiling a 3 by N WallCount the tilings of a 3 by N wall with dominoes, modulo 1e9+7, where N can be as large as 10^18.Medium7Dynamic programmingMatrix+1No attempts yet2s512 MBJudgeable
Maximum IslandsGiven an n by m grid of land, water, and cloud cells where clouds may be either, maximize the number of 4-connected land components.Medium7GraphDFS+2No attempts yet2s512 MBJudgeable
Foreign PostcardsPlace postcards in random batches, flipping a batch when its top card is upside down, and compute the expected number left picture down.Medium7ProbabilityDynamic programming+1No attempts yet2s512 MBJudgeable
Longest Increasing Subsequence 4Find a longest strictly increasing subsequence of A, and among all of maximum length output the lexicographically smallest one along with its length.Medium7Dynamic programmingBinary search+2No attempts yet1s256 MBJudgeable
Restoring the longest increasing subsequenceFind the length of the longest strictly increasing subsequence of A and print the lexicographically smallest subsequence achieving that length.Medium7Dynamic programmingBinary search+2No attempts yet3s512 MBJudgeable
Combining RiceballsGiven a row of riceballs, merge equal adjacent pairs or equal pairs with one ball between them, and find the largest size reachable.Medium7Dynamic programmingIntervals+2No attempts yet2s512 MBJudgeable
Cheap TravelingFind a route from village 1 to N whose total fare is at most S and whose total travel time is smallest; rides and villages may repeat.Medium7Shortest pathGraph+2No attempts yet2s512 MBJudgeable
ProbabilityGiven probabilities of letters A to D, find the probability that an optimally played game fills a row of n cells in alphabetical order.Medium7Dynamic programmingProbability+2No attempts yet1.5s512 MBJudgeable
PyramidBuild an n-row triangular pyramid from a linear recurrence, then answer queries for the maximum value inside a downward triangular sub-pyramid.Medium7Dynamic programmingArray+1No attempts yet4s512 MBJudgeable
FormulaFind the maximum number of edges in a closed trail that uses every important edge at least once, or report that none exists.Medium7GraphBit manipulation+1No attempts yet1s128 MBJudgeable
Equal Digit ProductsCount N-digit numbers whose digits in odd positions have the same product as the digits in even positions.Medium7Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Two BallsTwo balls move on a grid for T seconds with different random rules; compute the probability they collide, to 4 decimals.Medium7ProbabilityDynamic programming+1No attempts yet1s256 MBJudgeable
Adjacent Product GameChoose a subsequence of the given numbers to maximize the sum of products of adjacent chosen pairs.Medium7Dynamic programmingGreedyNo attempts yet1s64 MBJudgeable
Cake deliveryGiven a directed graph where every village must be reachable from village 1, find the minimum number of walks starting at village 1 that together cover all vertices.Medium7GraphDynamic programming+2No attempts yet1s64 MBJudgeable
Team BuildingCount pairs of K-cow teams, one from each farmer, such that after sorting both teams John's cow beats Paul's in every paired rank, modulo 1000000009.Medium7SortingCombinatorics+2No attempts yet2s512 MBJudgeable
Arranging HeapsDivide N ordered mining points into K groups, each group merging into one heap at its last point, minimizing total weighted distance moved.Medium7Dynamic programmingDivide and conquer+2No attempts yet2s512 MBJudgeable
Christmas EveGiven n weighted warehouses on a line, choose k of them as teleporter sites so that moving every other warehouse's presents into a chosen site gives the least total weighted distance.Medium7Dynamic programmingSorting+2No attempts yet2s512 MBJudgeable
Sunday CodingCount the distinct sequences of room-winner ranks obtainable when R rooms each hold S contestants with all ranks distinct.Medium7CombinatoricsDynamic programming+1No attempts yet2s512 MBJudgeable
Task ProcessingEach task has a day window and a list of durations by start day; pick a subset and an order to finish as many tasks in their windows as possible.Medium7Dynamic programmingBit manipulation+1No attempts yet2s512 MBJudgeable
ProficiencyGiven two counters with geometric service times, find the probability that all L1 people finish before all L2 people do.Medium7ProbabilityDynamic programming+1No attempts yet2s512 MBJudgeable
WolvesCount subsets of N sections, each holding at most one wolf, such that every given interval contains at least one chosen section, modulo 1e9+7.Medium7Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Coloring a RectangleCount colorings of an N x M grid where every colored cell has an even number of colored side-neighbors.Medium7Dynamic programmingBit manipulation+1No attempts yet2s512 MBJudgeable
Convex SequenceSubtract 1 from elements of a sequence (N up to 50) so that it becomes convex, minimizing total subtractions.Medium7Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Grade ConsolidationPlace all classes of each grade in classrooms so adjacent grades can share only after dropping conflicting class pairs, maximizing kept classes.Medium7Dynamic programmingGraph+2No attempts yet2s512 MBJudgeable
Main Campus Walk 3Count walks of exactly D minutes from building 1 back to itself in an undirected graph, with no restriction on repeated edges or vertices.Medium7GraphMatrix+2No attempts yet2s512 MBJudgeable
Sorting Array (Small)Split a permutation into K contiguous blocks, sort each block, then reorder at most P=2 blocks by swapping to fully sort the array; find the largest feasible K.Medium7ArraySorting+2No attempts yet5s512 MBJudgeable
Codejamon Cipher (Large)Count how many sentences built from vocabulary words, each word internally shuffled, concatenate to each given enciphered string.Medium7Dynamic programmingString+1No attempts yet5s512 MBJudgeable
Sherlock and Permutation Sorting (Small)For every permutation of 1..N, find the maximum number of order-preserving chunks with all earlier-chunk values smaller than later ones, then sum f(p)^2 modulo M.Medium7Dynamic programmingCombinatorics+2No attempts yet5s512 MBJudgeable
Clash Royale (Small)Spend up to M coins upgrading N cards, then pick 8 cards to maximize the deck's total attack power.Medium7Dynamic programmingGreedy+1No attempts yet5s512 MBJudgeable
Interleaved Output: Part 2Given a string that four computers can interleave into, find the largest number of times the IO computer could have printed its name.Medium7Dynamic programmingGreedy+1No attempts yet20s1024 MBJudgeable
Family Hotel (Large)Rooms fill by repeatedly picking a random adjacent free pair until none remain; find the probability that a given room ends up occupied, modulo 1e9+7.Medium7ProbabilityMath+2No attempts yet5s512 MBJudgeable
Forest University (Small)Count the fraction of topological orderings of a tiny rooted forest whose label string contains each given cool word as a substring, printed as an irreducible fraction.Medium7Dynamic programmingTopological sort+2No attempts yet100s512 MBJudgeable
Red Tape Committee (Large)Choose exactly K of N members, each with a known Yes probability, to maximize the chance that exactly half vote Yes.Medium7Dynamic programmingProbability+2No attempts yet5s512 MBJudgeable
Close Match (Large)Fill question marks in two equal-length digit strings to make the scores as close as possible, breaking ties by the smallest C then smallest J.Medium7Dynamic programmingGreedy+2No attempts yet5s512 MBJudgeable
Technobabble (Large)Given a list of two-word topics, find the maximum number of topics that could have been faked by combining the first word of one existing topic with the second word of another.Medium7GraphDynamic programming+2No attempts yet5s512 MBJudgeable
BFFs (Large)Each kid points to one BFF; find the largest circular seating where everyone sits next to their BFF.Medium7GraphDFS+2No attempts yet5s512 MBJudgeable
4 BlocksFill the empty cells of a small N x M board with 1x1 and 2x2 blocks to maximize total score, given fixed 1x1 blocks.Medium7Dynamic programmingBit manipulation+1No attempts yet2s512 MBJudgeable