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,685 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Building a ranchGiven an M by N grid with trees and rocks as obstacles, find the side length of the largest square subgrid that contains no obstacle.Medium5Dynamic programmingMatrix+2No attempts yet1s512 MBJudgeable
EnigmaGiven a digit pattern with question marks and an N, find the smallest matching number with no leading zero that is divisible by N.Medium5Dynamic programmingMath+2No attempts yet1s1024 MBJudgeable
Front NineGiven a clamped random walk on [0,h] with step probabilities, compute the expected area under the piecewise-linear terrain over n steps.Medium5ProbabilityDynamic programming+2No attempts yet6s512 MBJudgeable
TilingCount the ways to tile a 3 by W rectangle with 2 by 1 dominoes, printing the result modulo 1e9+7.Medium5Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Sweet, sour, bitter, saltyCut edges of a rooted binary tree so that at least X resulting components each contain at least K nodes, minimizing total cut cost.Medium5TreeDynamic programming+2No attempts yet2s512 MBJudgeable
Candy ChainGiven a candy string and a list of paid parts (each reversible), find the maximum total value obtainable by repeatedly removing sold parts and rejoining the remainder.Medium5Dynamic programmingIntervals+2No attempts yet7s512 MBJudgeable
SugorokuSquares 2 to N+1 are each marked 0 or 1; find the smallest die size j such that some sequence of rolls from 1 to j reaches or passes square N+2 without landing on any square marked 1.Medium5Dynamic programmingBFS+2No attempts yet2s512 MBJudgeable
Hangul LCSGiven two Hangul strings of up to 1000 characters each, compute the length of their longest common subsequence in characters.Medium5Dynamic programmingString+2No attempts yet2s512 MBJudgeable
Counting a^i b^j c^k subsequencesCount subsequences of a string of a, b, c that read as some positive number of a's, then b's, then c's, modulo 1e9+7.Medium5Dynamic programmingString+1No attempts yet2s512 MBJudgeable
Consultations before resignationGiven up to 1.5 million days, each with a job of length T_i and pay P_i, pick jobs that fit before day N+1 to maximize total pay.Medium5Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Probability that the knight stays on the boardA knight on an N by N board makes K random moves, each of the eight directions equally likely; find the probability it is still on the board after K moves.Medium5Dynamic programmingProbability+2No attempts yet2s512 MBJudgeable
Pascal's triangleBuild Pascal's triangle and sum all entries inside the equilateral sub-triangle whose top cell is row R, position C, with side length W.Medium5ArrayDynamic programming+2No attempts yet1s512 MBJudgeable
Signal 1Choose a subset of points with distinct x-coordinates; maximize the total Euclidean length of the polyline joining them in increasing x order.Medium5Dynamic programmingSorting+2No attempts yet1.5s128 MBJudgeable
Roasting Emma is a barista tooGiven a weighted tree, compute for every vertex the sum of shortest distances to all other vertices.Medium5TreeDFS+2No attempts yet1.5s128 MBJudgeable
QueryreuQMaintain a string under append and pop-back operations, and after each operation print the number of palindromic substrings it contains.Medium5StringDynamic programming+2No attempts yet1s1024 MBJudgeable
Drain PipesCount the number of ways to pick quantities of each pipe type, within the given stock, so the chosen pipes sum to exactly x.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Ah-Choo!Compute the least Dynamic Time Warping distance between two equal-length integer sequences, where every point must match at least one point of the other and matches cannot cross.Medium5Dynamic programmingArray+1No attempts yet1s512 MBJudgeable
Pen Pineapple Apple PenGiven a string of A, P, and p, find the maximum number of disjoint subsequence occurrences of the pattern p, P, A, p in order.Medium5GreedyString+1No attempts yet1s32 MBJudgeable
Uks Is an Apple Fan!!Count the number of paths on an N by M grid where each cell directs movement right, down, or both, and every path must end at cell (N, M).Medium5Dynamic programmingCombinatorics+1No attempts yet2s512 MBJudgeable
Longest Consecutive SubsequenceGiven an integer sequence, find the longest subsequence whose values form an arithmetic run with common difference 1, keeping the original order.Medium5Dynamic programmingHash map+1No attempts yet2s256 MBJudgeable
1, 2, 3 Sum 5Count the ordered sums of 1, 2, and 3 that add to n, with no equal value adjacent, modulo 1,000,000,009.Medium5Dynamic programmingMath+2No attempts yet1s512 MBJudgeable
1, 2, 3 Addition 7Count ordered compositions of n into exactly m parts, where each part is 1, 2, or 3, modulo 1,000,000,009.Medium5Dynamic programmingCombinatorics+2No attempts yet0.25s512 MBJudgeable
BlogGiven a string of R, G, and B, find the minimum number of contiguous same-color paint operations needed to build it.Medium5Dynamic programmingString+2No attempts yet1s256 MBJudgeable
A Great WayFind the cheapest path from node 1 to node N, where an edge costs c + d*max(0,e-10), breaking ties by fewer waypoints.Medium5GraphShortest path+1No attempts yet1s128 MBJudgeable
Execution TimeGiven ranks and operating speeds of n computers in a chain of ranks, compute when the whole task finishes using transmission time (i-j)^2 between machines.Medium5Dynamic programmingGraph+1No attempts yet2s128 MBJudgeable
Adding 1, 2, 3 (9)Count ordered compositions of n into parts 1, 2, and 3 that use at most m terms, and output each count modulo 1,000,000,009.Medium5Dynamic programmingCombinatorics+2No attempts yet1s512 MBJudgeable
Bit Palindromic NumbersCount integers in [l, r] whose first and last decimal digits match; solve with per-length counts and digit-DP over 10^18 ranges.Medium5MathDynamic programming+1No attempts yet2s512 MBJudgeable
Amusement ParkCitizens at various blocks must reach block 0 by taxi (A per block, one rider) or by sharing a bus (B won, up to 40 riders, one pick-up point). Find the minimum total cost.Medium5Dynamic programmingSorting+2No attempts yet1s256 MBJudgeable
Making a PalindromeFind the largest odd-length palindrome centered at index i, then answer each query by dropping the rest of the N cards.Medium5String matchingDynamic programming+1No attempts yet1s512 MBJudgeable
Cheap TripsOrder trips cannot be reordered and take no gaps; plan discounts across 120-minute windows to minimize total cost.Medium5Dynamic programmingGreedyNo attempts yet2s512 MBJudgeable
TeamworkPartition cows in a row into blocks of at most K so each block contributes its maximum times block size; maximize the sum.Medium5Dynamic programmingArrayNo attempts yet2s512 MBJudgeable
Root GameFor each N, decide who wins the subtraction game where a move subtracts any perfect square from a running total and taking the last square wins.Medium5Game theoryDynamic programming+2No attempts yet1s512 MBJudgeable
Restore the ArrayRecover grid A from grid B, where B is built by overlapping A with A shifted down X and right Y so overlapping cells are summed.Medium5MatrixSimulation+2No attempts yet2s512 MBJudgeable
Pipe Move 2Count the ways to push a 2-cell pipe (horizontal, vertical, or diagonal) across an N by N grid so its end reaches (N, N), keeping all covered cells empty.Medium5Dynamic programmingImplementation+2No attempts yet0.5s512 MBJudgeable
ContestGiven N intervals with start time, end time, and prize money, choose non-overlapping contests (end must not touch the next start) to maximize total prize.Medium5Dynamic programmingSorting+2No attempts yet1s256 MBJudgeable
Cowburger Kitchen WorkerWith M cheeseburgers and K fries available, pick the largest subset of orders, each requiring some of each item, that fits within both limits.Medium5Dynamic programmingGreedy+2No attempts yet3s512 MBJudgeable
Largest Sum Decreasing SubsequenceGiven a sequence, find a strictly decreasing subsequence with the maximum possible sum and print that sum.Medium5Dynamic programmingArray+2No attempts yet1s256 MBJudgeable
Making the Number NCount how many digit-by-digit sequences build the number N when each new digit is attached to the left or right end.Medium5Dynamic programmingString+2No attempts yet1s256 MBJudgeable
Being a Celebrity Is HardGiven a weighted undirected graph and two starting nodes, pick a meeting node minimizing the sum of both shortest distances and breaking ties by Jiheon's distance then index.Medium5Shortest pathGraph+1No attempts yet1s256 MBJudgeable
League of Legends (Large)Count the sequences of skills A (1 second) and B (M seconds) that fill exactly N seconds with no idle time, modulo 1e9+7.Medium5Dynamic programmingCombinatorics+1No attempts yet3s256 MBJudgeable
BackdoorFind the shortest travel time from junction 0 to junction N-1 in an undirected weighted graph, where every intermediate junction marked visible is blocked and only the Nexus may be entered.Medium5Shortest pathGraph+2No attempts yet2s512 MBJudgeable
FLEXDistribute M extra ten-thousand-won units among N days to minimize the sum of squared drops between consecutive daily spends.Medium5Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Promoting a ClubGiven a forest, choose the fewest vertices so that every vertex is either chosen or adjacent to a chosen one (minimum dominating set on a forest).Medium5TreeDynamic programming+2No attempts yet2s256 MBJudgeable
StringsBuild strings by concatenating earlier strings or slicing a substring, then output the sum of ASCII codes of the final string modulo 1e9+7, without materializing the possibly huge string.Medium5Dynamic programmingString+2No attempts yet2s512 MBJudgeable
Code WordCount length-l digit sequences on an r by c grid where no two consecutive presses are orthogonally or diagonally adjacent, mod 1e9+7.Medium5Dynamic programmingMatrix+2No attempts yet1s512 MBJudgeable
Four SquaresGiven n up to 50,000, print the minimum number of perfect squares whose sum equals n.Medium5Dynamic programmingMath+2No attempts yet0.5s512 MBJudgeable
Efficient ExchangeGiven a payment amount, minimize the total number of power-of-10 coins exchanged in both directions, allowing both sides to give change.Medium5Dynamic programmingGreedy+2No attempts yet3s512 MBJudgeable
What Does UNIST Stand For?Count ways to pick a prefix of each of N words so the concatenation spells UNIST, modulo 1e9+7.Medium5Dynamic programmingString+2No attempts yet1s512 MBJudgeable
Course SelectionChoose courses with given importance and study time so total time stays within N and total importance is maximized.Medium5Dynamic programmingArray+2No attempts yet1s512 MBJudgeable
Keyboards in ConcertGiven n keyboards, the sets of notes each can play, and the note sequence of a tune, find the minimum number of keyboard switches needed to play the whole tune.Medium5Dynamic programmingHash map+2No attempts yet1s512 MBJudgeable
SnowballSnowballs form at each altitude with size 1 and multiply by x each centimeter they descend; find the total size of all snowballs modulo 1e9+7.Medium5MathPrefix sum+2No attempts yet0.5s256 MBJudgeable
DessertEach day pick one of M desserts to maximize total satisfaction, where repeating the same dessert halves that day's value (rounded down).Medium5Dynamic programmingGreedy+2No attempts yet1s256 MBJudgeable
What's Mine is MinePick non-overlapping ore intervals to maximize total value, where each interval's value is its duration times its mineral's price.Medium5Dynamic programmingSorting+2No attempts yet0.5s512 MBJudgeable
HowlGiven a valid howl over A, H, O, W, construct a valid howl that is strictly longer, or report that none exists.Medium5StringGreedy+2No attempts yet1s512 MBJudgeable
Rainbow StringsCount subsequences of a string in which no letter repeats, distinguishing them by position, modulo 11092019.Medium5Dynamic programmingMath+2No attempts yet1s512 MBJudgeable
7-Segment DisplayUsing n seven-segment displays, each showing a digit 0-9 or the two-digit value 11, find the largest multiple of m displayable across the displays.Medium5Brute forceMath+2No attempts yet3s1024 MBJudgeable
Buying Ramen (Small)Buy exactly Ai packs from each factory using 1-pack, 2-pack, or 3-pack deals with different costs, minimizing total money.Medium5GreedyDynamic programming+2No attempts yet0.5s32 MBJudgeable
Stacking Blocks TogetherEach of N students offers a set of distinct block sizes, at most one block per student is used, and we count subsets of students whose chosen blocks sum to exactly H modulo 10007.Medium5Dynamic programmingPrefix sum+2No attempts yet1s256 MBJudgeable
Unstable SubstancesEach substance conflicts with exactly one other; choose a subset with no conflicting pair to maximize total weight.Medium5GraphDynamic programming+2No attempts yet1.2s256 MBJudgeable
A Really Odd SequenceGiven a sequence of integers, find the maximum sum of a contiguous subarray whose length is odd.Medium5ArrayDynamic programming+2No attempts yet6s512 MBJudgeable
Reversing StringsFor each string choose to reverse it or not so the sequence becomes lexicographically sorted, and output the lexicographically smallest such 0-1 choice string.Medium5GreedyString+2No attempts yet1s256 MBJudgeable
Meeting Room Scheduling 4Choose a set of non-overlapping meetings, where touching endpoints are allowed, to maximize the total number of attendees.Medium5Dynamic programmingSorting+2No attempts yet1s256 MBJudgeable
Painting ExchangeGiven who can sell to whom at what price, find the longest chain of distinct buyers starting from artist 1 where each resale price never drops below the purchase price.Medium6Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
Park Seongwon's ProbabilityCount permutations of up to 15 numbers whose concatenation is divisible by K, and output the probability as a reduced fraction.Medium6Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
Power PlantsGiven restart costs between plants and which plants are already on, find the minimum total cost to reach at least P working plants, or -1.Medium6Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
Search EngineGiven directed links between websites, compute one website's trust score by summing scores of linking sites only when no cycle would result.Medium6GraphDFS+2No attempts yet2s128 MBJudgeable
FencesPartition up to 16 given fence lengths into disjoint triples, keep only triples that form a valid triangle, and maximize the total area.Medium6Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
Zigzag LineupCount permutations of N distinct heights where adjacent comparisons strictly alternate, modulo 1,000,000.Medium6Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Road PavingFind the minimum travel time from city 1 to city N when up to K roads can be paved to cost zero, using layered shortest-path search over (node, paves used).Medium6Shortest pathGraph+1No attempts yet2s128 MBJudgeable
Student ShuffleCount permutations of up to 16 students so that every pair of adjacent heights differs by more than a given value K.Medium6Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
Hexagonal NumbersGiven N up to 1,000,000, compute the minimum number of hexagonal numbers (1, 6, 15, 28, ...) that sum to N.Medium6Dynamic programmingMath+2No attempts yet2s128 MBJudgeable
String DistanceGiven strings O and N, find the minimum number of substring-insertion operations to turn O into N, or output -1 if impossible.Medium6Dynamic programmingString+2No attempts yet2s128 MBJudgeable
Christmas TreeCount the ways to decorate an N-level tree where level k needs k ornaments split evenly among chosen colors, given limited red, green and blue ornaments.Medium6Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Problem AssignmentGiven an N x N matrix of student-problem times, find the minimum-cost perfect matching assigning one distinct problem to each student.Medium6Dynamic programmingGraph+2No attempts yet5s128 MBJudgeable
Restricted PermutationsCount permutations of 1..N where every element differs from its index by at most K, using a bitmask DP over a sliding window.Medium6Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
Sum of Tree Path WeightsGiven a weighted tree, compute the sum over all vertex pairs of the product of edge weights along their connecting path, modulo 1e9+7.Medium6TreeDFS+2No attempts yet2s128 MBJudgeable
Assigning Tasks 1Given an N by N cost matrix, assign each person exactly one task to minimize the total assignment cost.Medium6Dynamic programmingBit manipulation+1No attempts yet1s512 MBJudgeable
Picking Trash in the Same Increasing OrderFind the longest common strictly increasing subsequence of trash sizes recorded on two different days.Medium6Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
Infinite Sequence 2Compute A_N for a recursively defined sequence using nested floor divisions, requiring memoized recursion over a bounded set of distinct arguments.Medium6RecursionMath+2No attempts yet10s512 MBJudgeable
Optimal Binary Search TreeGiven up to 300 distinct keys within range 1..n, build a binary search tree minimizing total node visits over all searches for every integer from 1 to n, using an optimal BST DP with unsuccessful search gaps.Medium6Dynamic programmingTree+1No attempts yet2s128 MBJudgeable
Random RobotGiven move probabilities for E, W, S, N and up to 14 steps, compute the probability that the robot's random walk visits no grid cell twice.Medium6Dynamic programmingBrute force+1No attempts yet1s128 MBJudgeable
CandyGiven candy prices, count the distinct ways to pick a multiset of candies whose price sum is a prime number.Medium6Dynamic programmingNumber theory+2No attempts yet2s128 MBJudgeable
Character TrainingGiven character counts and power values per level, decide how to spend at most D training days across characters to maximize total power.Medium6Dynamic programmingGreedy+1No attempts yet2s128 MBJudgeable
Movie Director ShomFind the N-th smallest positive integer whose decimal digits contain at least three consecutive 6s, for N up to 10000.Medium6Binary searchDynamic programming+2No attempts yet2s128 MBJudgeable
Nice NumbersCount integers in the range [L, R] whose binary representation has three consecutive equal bits, using digit DP over bits.Medium6Dynamic programmingBit manipulation+1No attempts yet2s128 MBJudgeable
Prefix Reversal 3Given a string, for each prefix length from 1 to N in order you may choose to reverse that prefix, and you must output the lexicographically smallest string achievable after all choices.Medium6StringGreedy+2No attempts yet2s128 MBJudgeable
Palindrome PartitioningGiven an uppercase string up to length 2500, compute the minimum number of pieces to cut it into palindromic substrings.Medium6Dynamic programmingStringNo attempts yet2s128 MBJudgeable
Sum of Lucky NumbersWrite N as a sum of the fewest numbers made only of digits 4 and 7, breaking ties by the lexicographically smallest sequence.Medium6Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Dongmin SequenceCount sequences of lucky numbers (digits 4/7 only) chosen from a given list of length L, where consecutive elements share first/last digit, modulo 1,234,567,891.Medium6MatrixDynamic programming+2No attempts yet2s128 MBJudgeable
Artist Lee DonghoGiven a black/white grid and a limit on horizontal single-color brush strokes, find the minimum number of cells that end up unpainted or wrongly colored.Medium6Dynamic programmingPrefix sum+2No attempts yet2s128 MBJudgeable
Making the Best Phone NumberSplit a digit string into groups of 2 or 3 to maximize a score based on group types, then output the lexicographically smallest optimal formatting.Medium6Dynamic programmingString+2No attempts yet2s128 MBJudgeable
Morning Three and Evening FourGiven N banana weights, choose non-overlapping length-K blocks to move as a C-second group, minimizing total time and then the number of groups used, with output of chosen block positions.Medium6Dynamic programmingPrefix sum+2No attempts yet2s128 MBJudgeable
Tiling a GridCount the ways to fully tile an N by M grid (N, M up to 14) with 2x1 dominoes, modulo 9901.Medium6Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
XYZ StringGiven a self-similar X/Y/Z rewriting sequence, answer queries about the stage N string's length, its k-th character, or the count of a given character without building the full string.Medium6RecursionDivide and conquer+2No attempts yet2s128 MBJudgeable
Largest Zero SubmatrixGiven a binary matrix, find the maximum area rectangle of consecutive rows and columns that contains only zeros.Medium6StackDynamic programming+2No attempts yet2s128 MBJudgeable
CubeditorGiven a lowercase string of length up to 5000, find the maximum length of a substring that occurs at least twice, allowing overlapping occurrences.Medium6StringDynamic programming+1No attempts yet0.5s128 MBJudgeable
Tile CodesCount distinct tilings of a 2xN board using 1x2, 2x1, and 2x2 tiles, where mirror-image tilings under left-right flip count as one.Medium6Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Making CouplesGiven lists of men's and women's personality values, form min(n, m) man-woman couples that minimize the total absolute difference of matched values.Medium6Dynamic programmingSorting+2No attempts yet2s128 MBJudgeable
PibonacciCompute a Fibonacci-like sequence defined with the irrational constant pi as a recursive step and output it modulo 10^18.Medium6Dynamic programmingRecursion+1No attempts yet2s128 MBJudgeable
Maximum Submatrix SumGiven an N by M integer matrix, find the maximum possible sum over all contiguous rectangular submatrices.Medium6Dynamic programmingMatrix+2No attempts yet2s128 MBJudgeable