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,701 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Fibonacci Number 7Compute the n-th Fibonacci number modulo 1,000,000,007 for n up to one million.Medium6Dynamic programmingMath+1No attempts yet1s512 MBJudgeable
Pepper WreathGiven a tree whose vertices carry non-negative weights and a cap k, find the minimum number of edges to cut so every resulting component has total weight at most k.Medium6TreeDFS+2No attempts yet1s1024 MBJudgeable
Python syntaxGiven a string of for and execute statements, count the valid Python indentation schemes modulo 1,000,000,007.Medium6Dynamic programmingImplementation+2No attempts yet1s128 MBJudgeable
Taming the HerdGiven a log of N counter readings, find for each possible number of breakouts the minimum number of entries that disagree with some valid breakout sequence that starts with a breakout on day 1.Medium6Dynamic programmingImplementation+2No attempts yet2s512 MBJudgeable
Talent ShowChoose a group of cows with total weight at least W maximizing the ratio of total talent to total weight, and print floor(1000A).Medium6Dynamic programmingBinary search+1No attempts yet2s512 MBJudgeable
Sejin VirusGiven a directed graph of facilities and pipes, find the minimum number of starting nodes from which all nodes are reachable.Medium6GraphDFS+1No attempts yet1s512 MBJudgeable
You on That DayGiven measured environmental factors and one-operation definitions, compute each factor's partial derivative of HAPPY and print it as a reduced fraction.Medium6Dynamic programmingDFS+2No attempts yet1s512 MBJudgeable
Eli's Curious ExperimentCount the maximal independent sets of a path on N vertices that have size at least two, for many N up to 76, labeled by test case number.Medium6Dynamic programmingCombinatorics+1No attempts yet3s512 MBJudgeable
Super BallChoose a factory for each layer in the production order and again in the recycling order, minimizing layer costs plus transfer costs C whenever consecutive layers use different factories.Medium6Dynamic programmingGreedyNo attempts yet2s512 MBJudgeable
Pseudo-Banana StringsGiven a string of B, A, N, find the minimum number of character replacements that turn it into a concatenation of blocks of the form B+ANANA(NA)*.Medium6Dynamic programmingString+2No attempts yet2s512 MBJudgeable
Building a SpaceshipPartition the ordered parts into contiguous groups, paying for each group the product of its maximum weight and maximum energy; minimize the total cost.Medium6Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Hyunwook Is the Parenthesis King!!Given a string of parentheses, find the length of the longest contiguous substring that forms a correct parenthesis string.Medium6StackString+2No attempts yet2s512 MBJudgeable
1, 2, 3 Sum 6Count the compositions of n into parts 1, 2, and 3 that read the same forwards and backwards, modulo 1,000,000,009.Medium6Dynamic programmingCombinatorics+2No attempts yet1s512 MBJudgeable
1, 2, 3 Sum 8For each n, count the ordered compositions of n into parts 1, 2, 3, reporting the number using an odd count of terms and the number using an even count, each modulo 1,000,000,009.Medium6Dynamic programmingMath+1No attempts yet1s512 MBJudgeable
BracketGiven a bracket pattern with some fixed brackets and some dots, count the ways to fill the dots so the whole string is a balanced bracket sequence.Medium6Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Lush GearsPick one model per gear type so the total cost is as close to C as possible without exceeding it, and report the leftover coins.Medium6Dynamic programmingArray+1No attempts yet2s512 MBJudgeable
Commuting MathematiciansGiven a subway network of lines with travel times, find a route from F to D that minimizes total time, then minimizes line transfers among fastest routes.Medium6GraphShortest path+2No attempts yet2s512 MBJudgeable
Subset Equal PartitionCount the ways to split the set {1,...,N} into two subsets with equal sums, or print 0 if no split exists.Medium6Dynamic programmingCombinatorics+1No attempts yet1s256 MBJudgeable
Noodle Team ContestGiven each member's pot time and seasoning time, order the members to minimize the total time until all noodles are finished.Medium6GreedySorting+1No attempts yet2s512 MBJudgeable
Palapa NumberCount N-digit numbers (no leading zero) where the first two digits sum to an even value or the last two digits form a prime, modulo 9973.Medium6CombinatoricsMath+2No attempts yet2s512 MBJudgeable
Medicine DeliveryFind the fastest route from one settlement to the other along roads, pausing 5 minutes at equipment stations to wash whenever 100 minutes of driving would otherwise be exceeded.Medium6Shortest pathGraph+2No attempts yet1s1024 MBJudgeable
Prime CurrencyCount the unordered ways to make N with unlimited primes, using a coin-change DP, and print the count modulo 123,456,789.Medium6Dynamic programmingNumber theory+1No attempts yet1s256 MBJudgeable
The Chick's Transformation Is Not GuiltyEach chick lays one egg daily and each egg hatches K days later. Find the chick count after N days modulo 100000007.Medium6Dynamic programmingMatrix+1No attempts yet1s512 MBJudgeable
SequencesCount non-decreasing length-n sequences over 1 to m where each integer appears at most k times. Use DP over the largest value and its count.Medium6Dynamic programmingCombinatorics+1No attempts yet2s512 MBJudgeable
ChainFor each position, repeatedly jump to the first strictly greater element on its right and report the length of that chain.Medium6StackDynamic programming+1No attempts yet2s512 MBJudgeable
Left-Right-WinFor players seated in a circle, compute how much of a $100 pot each should pay, given the spinner probabilities of moving left, moving right, or winning.Medium6ProbabilityMath+2No attempts yet2s512 MBJudgeable
The Good, the Great, and the SuperbGiven a sequence of digits, find the minimum number of elements to change so the sequence becomes Good, Great, or Superb, where Superb is constant, Great has adjacent gaps at most 1, and Good splits into Great or Superb blocks.Medium6Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
Ebony and IvoryAssign fingers 1 to 5 to a monophonic piano passage given four ergonomic transition tables and output the minimum total difficulty of all adjacent intervals.Medium6Dynamic programmingImplementationNo attempts yet2s512 MBJudgeable
MatriceCount all triangular regions cut from squares by one diagonal whose cells all hold the same character.Medium6Dynamic programmingMatrix+1No attempts yet1s512 MBJudgeable
JackRabbit SlimGiven sorted distinct carrot positions on a line, Slim repeatedly jumps to the nearest remaining carrot, breaking ties to the right; find the sum of total distances over all possible starting carrots.Medium6Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Arithmetic ProgressionsGiven up to 5000 distinct numbers, find the length of the longest subset that forms an arithmetic progression.Medium6ArrayHash map+1No attempts yet5s512 MBJudgeable
Circle Cross StampsGiven a row of O and X marks printed by single circles, single crosses, and two-mark circle-cross stamps in either orientation, find the largest possible count of circle-cross stamps.Medium6Dynamic programmingGreedy+1No attempts yet2s512 MBJudgeable
PalaceCount ways to place N non-attacking palace pieces (rook plus king moves) on an N by N board, modulo 1,000,000,007, for up to 1,000,000 test cases with N up to 10,000,000.Medium6MathCombinatorics+2No attempts yet2s512 MBJudgeable
Ball on a ChessboardEach cell of an R by C board holds a distinct number; every ball rolls to the smallest neighbor until it reaches a local minimum, and we must count how many balls stop on each cell.Medium6GraphDynamic programming+2No attempts yet2s512 MBJudgeable
Traveling Salesman 3Find the minimum-length round trip that visits all N cities exactly once and returns to the start, where N is at most 16.Medium6Dynamic programmingBit manipulation+2No attempts yet1s512 MBJudgeable
Cow PoetryCount the ways to fill M lines of exactly K syllables with given words, where equal rhyme-scheme letters must share a rhyme class, modulo 1e9+7.Medium6Dynamic programmingCombinatorics+1No attempts yet2s512 MBJudgeable
SličiceGiven current counts of unique cards per team and a nondecreasing points array, choose K additional cards to maximize total points.Medium6Dynamic programmingGreedyNo attempts yet1s512 MBJudgeable
Moving a Pipe 1Count the ways to push a two-cell pipe (horizontal, vertical, or diagonal) across an N by N grid of walls until one end reaches (N, N).Medium6Dynamic programmingSimulation+2No attempts yet1s512 MBJudgeable
Candy GameCount the number of nondecreasing sequences of length n where the i-th value is at most x[i], multiply by n, and report the result modulo 1e9+7.Medium6Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Comparing StringsGiven two lowercase strings, align them by repeating characters of either string, keeping order, and minimize the sum of absolute alphabet-position differences over aligned pairs.Medium6Dynamic programmingString+2No attempts yet1s512 MBJudgeable
Space ProbeGiven travel times between N planets and a start planet, find the shortest route that visits every planet, with no need to return to the start.Medium6Dynamic programmingBit manipulation+2No attempts yet1s512 MBJudgeable
SnakesSplit the sequence into K+1 contiguous segments, set each segment's net size to its maximum, and minimize the total sum of segment maxima minus the sum of all group sizes.Medium6Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Scoring HackStarting from 0, each turn adds a or b points or doubles the total, and the game must end with score below n+a while using at most 10% doublings. Find the minimum number of turns.Medium6Dynamic programmingGreedy+2No attempts yet1s256 MBJudgeable
Team SelectionPick five of n candidates and assign each a distinct role among A to E so the total skill summed over roles is as large as possible.Medium6Dynamic programmingBit manipulation+1No attempts yet1s256 MBJudgeable
Almost-K Increasing SubsequenceFind the longest subsequence of a given sequence that has at most K positions where consecutive elements decrease.Medium6Dynamic programmingArray+2No attempts yet1s256 MBJudgeable
Curse of the MeetingCount the ways N people around a round table can pair up and shake hands simultaneously without any arms crossing, modulo 987654321.Medium6Dynamic programmingCombinatorics+2No attempts yet1s256 MBJudgeable
Life in WartimeGiven N distinct cities (all below 250) in an infinite binary heap tree, count cities that either host a unit or lie on the unique path between two units.Medium6TreeHash map+2No attempts yet2s512 MBJudgeable
Number of Sequences Related to PalindromesCount length-N sequences with values up to M such that every length-K window is a palindrome, modulo 1e9+7.Medium6CombinatoricsMath+2No attempts yet0.25s512 MBJudgeable
RGB Street 2Paint N houses in a cycle with three colors so that every adjacent pair differs, minimizing total cost.Medium6Dynamic programmingImplementation+2No attempts yet0.5s128 MBJudgeable
Count of Increasing SubsequencesCount the strictly increasing subsequences of length K in a sequence of N distinct values, reported modulo 1e9+7.Medium6Dynamic programmingBinary search+2No attempts yet1s512 MBJudgeable
Jinwoo's Moon Trip (Small)Given an N by M grid of fuel costs with N, M at most 6, find the minimum cost path from any cell in the top row to any cell in the bottom row, where each step moves downward and no two consecutive steps use the same direction.Medium6Dynamic programmingMatrix+1No attempts yet1s256 MBJudgeable
Feeding the CatsStarting at (0,0), visit all N cats on a grid, moving in Manhattan steps, and return to (0,0) in the shortest time.Medium6Dynamic programmingBit manipulation+2No attempts yet1s256 MBJudgeable
Stealing Snacks from JuniorsChoose a subset of snacks whose total fullness reaches M, minimizing total satisfaction, or report that it is impossible.Medium6Dynamic programmingGreedy+1No attempts yet1s256 MBJudgeable
Balanced StringCount binary strings of length n where every prefix has at most one more 0 than 1 or one more 1 than 0, modulo 16769023.Medium6Dynamic programmingCombinatorics+2No attempts yet0.5s512 MBJudgeable
Byte CoinGiven n up to 15 days of Byte Coin prices and initial cash W, buy and sell whole coins each day to maximize the cash held after selling everything on day n.Medium6Dynamic programmingBrute force+2No attempts yet0.5s512 MBJudgeable
Star TrekFind the minimum travel time from planet 1 to planet n, where you may switch ships at intermediate planets, paying a preparation time plus pace times distance for each leg.Medium6Dynamic programmingPrefix sum+2No attempts yet1s512 MBJudgeable
Two MachinesAssign each of n tasks to machine A or B, minimizing the maximum total load across the two machines.Medium6Dynamic programmingGreedy+2No attempts yet0.5s512 MBJudgeable
Getting ConfidenceGiven an N by N matrix of confidence values, assign each of N ornaments to a distinct position so that the product of the chosen values is maximized, and output the assignment.Medium6Dynamic programmingBit manipulation+2No attempts yet0.5s512 MBJudgeable
Deceptive DiceGiven an n-sided die and at most k rolls, find the maximum expected final score when you may stop rolling at any point.Medium6Dynamic programmingProbability+2No attempts yet1s512 MBJudgeable
StrapsChoose a set of straps forming a rooted tree: each strap occupies one port of its parent, one strap hangs from the phone, and total happiness is maximized.Medium6Dynamic programmingTree+2No attempts yet1s512 MBJudgeable
Beer BarrelsCount occurrences of digit C across all K-digit strings made only of digits A and B, modulo 1e9+7.Medium6CombinatoricsMath+2No attempts yet2s512 MBJudgeable
Pass the BuckGiven a graph where each holder moves to a random neighbor or wins with probability 1/(d+1), find the win probability of a target player from a given start.Medium6ProbabilityGraph+2No attempts yet1s512 MBJudgeable
Bus PlanningSplit n kids (n up to 17) into the fewest groups so no two enemies share a group and each group has at most c kids, then output one valid grouping.Medium6Bit manipulationDynamic programming+2No attempts yet2s512 MBJudgeable
HaikuGiven a set of syllables, decide whether the three input phrases can each be split into syllables so their syllable counts are 5, 7, and 5.Medium6Dynamic programmingString+2No attempts yet1s512 MBJudgeable
SubwayEach station belongs to company A or B; find the route from station 0 to M that minimizes transfers first, then travel time, and report both.Medium6GraphShortest path+1No attempts yet1s256 MBJudgeable
I Can Feel My Grade in the Flying Test PapersSplit an array into K contiguous groups; maximize the minimum group sum.Medium6Binary searchGreedy+2No attempts yet1s256 MBJudgeable
Sculptural ProjectGiven a string of work and market days, cancel the fewest days so materials never run out and end at zero.Medium6Dynamic programmingPrefix sum+2No attempts yet2s512 MBJudgeable
Hard Sculptural ProjectGiven a string of 'w' (work, consume 1) and 'o' (rest, gain 1), delete the fewest characters so every prefix has more gains than work and the total balances, then count the ways.Medium6Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Gluing PicturesGiven a city string C, find for each friend name the fewest substrings of C that concatenate to form it, or -1 if impossible.Medium6Dynamic programmingString matching+2No attempts yet0.3s512 MBJudgeable
Improve SPAMGiven nested mailing lists, count how many messages reach client emails before deduplication and how many distinct emails are reached, both modulo 1e9+7.Medium6GraphDFS+2No attempts yet0.3s512 MBJudgeable
BoulderingOn a grid of holds with grip costs, find the minimum total Euclidean path length from the bottommost hold to the topmost hold, where consecutive holds must be within reach r and total cost stays at most s.Medium6GraphShortest path+2No attempts yet2s512 MBJudgeable
Binary Number GameGiven two binary strings, find the minimum number of single-bit flips (never the leading bit), increments, and decrements to turn the start number into the target.Medium6BFSDynamic programming+2No attempts yet1s1024 MBJudgeable
Give Me Back My Binary Tree!!!Count the number of distinct binary trees with exactly E edges, where mirror images count as different trees, modulo 1e9+7.Medium6Dynamic programmingCombinatorics+2No attempts yet2s1024 MBJudgeable
Fast ForwardingFind the minimum time to reach position t on a tape when speed can be tripled or divided by three once per second, and playback must end at normal speed.Medium6BFSDynamic programming+2No attempts yet2s512 MBJudgeable
2xN Pretty TilingTile a 2xN grid with at most A dominoes and at most B 2x2 squares, rotating tiles freely, to maximize the sum of tile prettiness values.Medium6Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Team PracticeCount assignments of N ordered problems to solvers A, B, C where A's count is a multiple of K, B never solves two in a row, and C solves at least one.Medium6Dynamic programmingCombinatoricsNo attempts yet1s512 MBJudgeable
Splitting DNAGiven the lengths of N fragments in order, find the minimum total energy to split the original chain, where each cut costs the current chain length.Medium6Dynamic programmingIntervals+2No attempts yet1s512 MBJudgeable
Time is MooneyFind a closed walk starting and ending at city 1 in a directed graph that maximizes collected city rewards minus C times the square of the number of days.Medium6Dynamic programmingGraph+2No attempts yet2s512 MBJudgeable
Gold RushGiven c Oshloobs and the gold price for each of n days, find the maximum Oshloobs at the end of day n, buying and selling gold each day and cashing out at the end.Medium6Dynamic programmingGreedyNo attempts yet2s512 MBJudgeable
DISHFor each pair of strings, output a shortest string that contains both input strings as substrings.Medium6StringDynamic programming+2No attempts yet2s512 MBJudgeable
JourneyCount binary strings of length N with no run of equal symbols longer than K, modulo 1e9+7.Medium6Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Man in the middleFind the lexicographically smallest uppercase string of length L whose polynomial hash mod 10007 equals H, or report that none exists.Medium6MathNumber theory+2No attempts yet2s512 MBJudgeable
Football HooliganismPartition a 2 by N grid of team labels into non-overlapping rectangles so that every rectangle is monochromatic, minimizing the number of 1 by 1 rectangles.Medium6Dynamic programmingImplementation+2No attempts yet2s512 MBJudgeable
Team AssignmentAssign each participant to team A (scoring their attack) or team B (scoring their defense) so the team sizes differ by at most k, maximizing the total.Medium6GreedySorting+2No attempts yet0.7s256 MBJudgeable
Amazing SushiGiven counts of n sushi types and an allowed piece range for each person, decide whether every piece can be split so each type is shared evenly (one extra allowed) and both stay in range.Medium6GreedyMath+2No attempts yet1s512 MBJudgeable
Bubble Bucket SortPartition n bubble sizes into at most b buckets to minimize the sum of squared differences between the largest and smallest size in each bucket.Medium6Dynamic programmingSorting+2No attempts yet1s512 MBJudgeable
The Day of Going to the Training CampCount sequences of length N over values 1..M that avoid any local peak (a[i-1] < a[i] > a[i+1]), modulo 998244353.Medium6Dynamic programmingCombinatorics+2No attempts yet1s1024 MBJudgeable
Autumn Cleaning (16 MiB ML!)Count the k-element subsets of n item prices whose sum is divisible by r, modulo 10^6+3.Medium6Dynamic programmingCombinatorics+2No attempts yet2s16 MBJudgeable
Arithmetic SequencesGiven a set of distinct integers, find the size of the largest subset that can be ordered as an arithmetic sequence.Medium6Dynamic programmingSorting+2No attempts yet1.5s512 MBJudgeable
ElevatorGiven passenger arrival times and destination floors, choose when to dispatch the elevator to minimize the time it finally returns to floor 0.Medium6Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
DivisorGiven up to 5000 positive integers, change the fewest of them to any positive integers so that every pair is in a divisor-multiple relationship.Medium6SortingDynamic programming+2No attempts yet1s1024 MBJudgeable
Hotel Room AssignmentCount the ways to place any number of guests on N floors of two rooms each so that no two guests share a floor or sit vertically adjacent, modulo 1e9+7.Medium6Dynamic programmingCombinatorics+2No attempts yet1s1024 MBJudgeable
Meeting Room Scheduling 2Given N meetings that overlap only with their immediate neighbors in the list, choose a non-overlapping subset maximizing total attendees.Medium6Dynamic programmingArray+2No attempts yet1s256 MBJudgeable
Meeting Room Scheduling 3Choose non-overlapping meetings, where each meeting's time overlaps only its immediate neighbors in the input order, to maximize the total attendee count.Medium6Dynamic programmingGreedy+2No attempts yet1s256 MBJudgeable
How to Fail at Programming ContestGennady picks the order of problems he solves, never starting one he cannot finish, to minimize total points scored within T minutes.Medium6Dynamic programmingSorting+1No attempts yet1s512 MBJudgeable
The Tower of PisaGiven n disks stacked on the first of three rods, where the second rod lets you move a group of top disks together, find the minimum moves to shift all disks to the third rod.Medium6Dynamic programmingRecursion+1No attempts yet2s512 MBJudgeable
ExpeditionEach candidate forbids at most one other candidate; choose the largest subset where no included candidate's forbidden partner is also included.Medium6GraphGreedy+2No attempts yet2s512 MBJudgeable
HomeworkGiven a DAG of assignments with durations, remove one vertex to minimize the makespan of the remaining precedence-constrained schedule.Medium6GraphTopological sort+2No attempts yet2s512 MBJudgeable
Let's Kill the Monster!Each skill takes 1 second to cast, then deals its damage; after casting you must wait out its cooldown. Find the earliest time the monster's HP reaches zero.Medium6Brute forceSimulation+2No attempts yet2s512 MBJudgeable
Moving 5Find the maximum candy sum along a monotone path from (1,1) to (N,M) in an N by M grid where room (i,j) holds A_i*10^9 + B_j.Medium6GreedyMath+1No attempts yet1s512 MBJudgeable