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 results1,800 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
KaraokeAssign each note of a sequence to one of two singers so that the total of the absolute pitch jumps within each singer's subsequence is minimized.Medium7Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Secret MissionGiven n candidates with talkativeness values, use at most s adjacent swaps to make the sum of the first k values as small as possible.Medium7Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Hongjun and AntimatterCount contiguous subarrays of length at least 2 that can be split into two disjoint nonempty parts with equal sums, modulo 1e9+7.Medium7Dynamic programmingPrefix sum+2No attempts yet2s512 MBJudgeable
PasswordGiven finishes over N years, find the lexicographically largest password substring allowed by rules and count its occurrences.Medium7ArrayString matching+1No attempts yet4s256 MBJudgeable
Glass BridgeGiven N and values a_i, count pairs i < j with a_i > a_j.Medium7ArrayDivide and conquer+2No attempts yet1s512 MBJudgeable
Largest XOR sum subarrayGiven a sequence, find the maximum XOR value over all contiguous subarrays of length at least one.Medium7Bit manipulationTrie+2No attempts yet10s512 MBJudgeable
Sequence and Queries 4For each query range [l,r], find the maximum distance between two positions in the range that hold the same value.Medium7ArrayPrefix sum+2No attempts yet4s512 MBJudgeable
Distinct values in a rangeGiven a static array and many range queries, report how many distinct values occur in each subarray.Medium7ArraySorting+2No attempts yet2s512 MBJudgeable
Suffix Array 3Given a permutation built by moving and reversing intervals, count the strings whose suffix array equals it, modulo 1e9+7.Medium7ArrayCombinatorics+2No attempts yet5s512 MBJudgeable
Free WeightsTwo rows of dumbbells, each mass appearing twice, must be paired up; minimize the heaviest dumbbell that must be lifted.Medium7ArrayTwo pointers+2No attempts yet4s512 MBJudgeable
Expect to WaitGiven a time-ordered schedule of unicycle drops and grouped requests, compute the total wait time of all requesters for each of several starting unicycle counts, or report infinity if anyone is left waiting.Medium7Prefix sumBinary search+2No 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
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
Happy sequenceGiven a non-happy sequence, count and list every single-element replacement that makes all adjacent absolute differences exactly the set 1..N-1.Medium7ArrayHash map+1No attempts yet1.5s256 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
Why Did the Cow Cross the Road 10Given two permutations of 1..N, cyclically shift one of them and minimize the number of pairs whose order differs between the two sequences.Medium7ArraySorting+2No attempts yet2s512 MBJudgeable
Jurisdiction DisenchantmentGiven n odd points, find the smallest axis-aligned rectangle (possibly degenerate) that contains strictly more than n/2 of them, and output its area.Medium7ArraySorting+2No attempts yet2s512 MBJudgeable
Wookje is a gambler!!Given the starting top faces of N signed coins in two rounds, maximize the difference between the largest reachable first-round sum and the smallest reachable second-round sum using flips of three consecutive coins (clipped at the ends).Medium7MathGreedy+2No attempts yet2s256 MBJudgeable
Distinct values in a rangeGiven an array, answer many queries counting the number of distinct values in a subarray.Medium7ArraySorting+2No attempts yet5s1024 MBJudgeable
Distinct values and queries 2Count distinct values in subarray [l, r] for up to 10^6 queries, where each query's left endpoint depends on the previous answer.Medium7SortingPrefix sum+2No attempts yet5s1024 MBJudgeable
Maze EscapeOn a grid with walls, find the shortest path from start to exit when exactly one wall cell may be removed.Medium7BFSGraph+1No attempts yet1s512 MBJudgeable
Collatz ConjectureCount how many distinct gcd values appear among all contiguous subarrays of the given sequence.Medium7ArrayMath+1No attempts yet10s512 MBJudgeable
Manhattan MorningsChoose a monotone shortest path from house to workplace on the Manhattan grid that passes through as many errand points as possible.Medium7Dynamic programmingSorting+1No attempts yet2s512 MBJudgeable
Biotechnology laboratoryGiven a string of lowercase letters weighted 1 to 26, count how many distinct total weights occur among all non-empty substrings.Medium7Prefix sumTwo pointers+2No attempts yet7s1024 MBJudgeable
Yes, Yes, It's NonogramsRepeatedly apply line-by-line nonogram deduction until no square's color is forced, then print the resulting grid.Medium7SimulationImplementation+2No attempts yet2s512 MBJudgeable
Intelligence in PerpendiculariaGiven an orthogonal simple polygon, find the total length of wall that an observer looking along a principal axis direction cannot see.Medium7GeometryImplementation+2No attempts yet3s512 MBJudgeable
Robot RaceFor each of up to a million queries on an n by m grid of obstacles, decide whether a monotone path moving only right or down connects the two given empty cells.Medium7Dynamic programmingPrefix sum+2No attempts yet2s1024 MBJudgeable
A New SequenceGiven a circular sequence A, compute each b_i as the sum of a_{i+k mod N} weighted by (-1)^k times (k+1) over all k from 0 to N-1.Medium7MathPrefix sum+2No attempts yet2s512 MBJudgeable
Black or WhiteGiven a start row s and target row t of B/W bricks, find the minimum number of strokes, each painting at most k consecutive bricks one color, to reach t.Medium7Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Reverse and RejoinSplit a fixed sequence into two non-empty parts, reverse each part, and print the lexicographically smallest result among all split positions.Medium7ArrayString matching+2No attempts yet3s512 MBJudgeable
Paul the barista picks coffee beansPick the longest subsequence of the given row so that consecutive picked values are congruent mod k or differ by at most d in absolute value.Medium7Dynamic programmingSegment tree+2No attempts yet1.5s64 MBJudgeable
Road ConstructionGiven a permutation, for each query [l,r] reverse that segment and report the number of maximal increasing runs in the resulting array.Medium7ArrayMath+2No attempts yet1s128 MBJudgeable
Heaven's Kitchen 2Given an array of integers, choose two non-overlapping nonempty contiguous subarrays and maximize the product of their sums.Medium7ArrayDynamic programming+2No attempts yet1s128 MBJudgeable
Yonsei Water ParkGiven N stones in a line with values K_i, pick a starting stone and a sequence of distinct stones where each jump moves at most D positions, maximizing the sum of visited values.Medium7Dynamic programmingSegment tree+1No attempts yet1s128 MBJudgeable
Open SesameGiven pebble and groove heights per column, choose subarray moves adding or subtracting 1 each second to align all pebbles with grooves in minimum time.Medium7ArrayPrefix sum+2No attempts yet1s256 MBJudgeable
Snow BootsFind the minimum number of boot pairs Farmer John must discard, given a stack-ordered backpack and snow-depth and step-size limits, to walk from tile 1 to tile N.Medium7Dynamic programmingArray+2No attempts yet2s512 MBJudgeable
Out of SortsCount how many times the outer loop of this bubble sort implementation runs before the array becomes sorted.Medium7SortingArray+2No attempts yet2s512 MBJudgeable
Puyo Puyo StackingGiven a final Puyo Puyo board, print one accepted sequence of pair drops that builds it in the exact column order the statement fixes, using temporary pops to clear leftovers.Medium7SimulationImplementation+2No attempts yet1s1024 MBJudgeable
The Final Weapon, the BowCut a circular rubber band at K of M marked notches into K arcs; maximize the shortest arc among the K pieces.Medium7Binary searchGreedy+2No attempts yet1s512 MBJudgeable
IncineratorMaintain a queue of waste and M incinerator cells under burn, query, append, and recycle commands, then report the final cells.Medium7ImplementationQueue+2No attempts yet2s512 MBJudgeable
Ukje Is a Politician!!Given an odd N, a target bit t, and an N by N grid of 0/1, repeatedly set any full row or column to all 1 if it currently has a majority of 1s, else all 0; decide whether the whole grid can reach all t.Medium7ArrayMatrix+2No attempts yet2s512 MBJudgeable
Array and OperationsApply a sequence of global 'add index to each position' updates and range reversals to a zero array, then report the values at m queried positions.Medium7ArrayImplementation+2No attempts yet2s512 MBJudgeable
WarGiven a permutation of worm targets, reorder humans only by moving the last to the front and find the minimum moves for a winning formation, or report -1.Medium7ArraySorting+1No attempts yet2s512 MBJudgeable
Andrew's Amazing ArchitectureGiven required block lengths for n columns, choose actual heights forming a unimodal sequence that respects each requirement and minimizes total volume.Medium7ArrayGreedy+2No attempts yet3s512 MBJudgeable
The 271st Well-Known CupPick pairs so the opponent takes the one with larger B; greedily keep the largest A while holding a B gap and fallback cheaper in A.Medium7GreedyHeap+2No attempts yet1s1024 MBJudgeable
HillsLower consecutive hills to form k peaks in n hills so that at least k hills exceed both neighbors, minimizing total height reductions, for every k from 1 to ceil(n/2).Medium7Dynamic programmingGreedy+1No attempts yet1s512 MBJudgeable
Zebra ArtToggle each pixel by as many rectangle and diamond updates as cover it, then print the resulting two-color image of W by H pixels.Medium7MatrixArray+2No attempts yet1.5s512 MBJudgeable
Strange Power LinesKeep a maximum subset of K lines with at most one per pole and no crossings, where pole labels are given in shuffled order. Output the number of lines to remove.Medium7Dynamic programmingArray+2No attempts yet1s512 MBJudgeable
Mount MarathonGiven up to 52 piles of one card each, repeatedly move a single-card pile onto the pile just to its right if its value is at least the right pile's top card. Find the minimum final number of piles.Medium7ArrayStack+2No attempts yet2s512 MBJudgeable
Sixth SenseGiven the opponent's fixed play order and Future's multiset of cards, decide the order she plays them to win the most tricks, breaking ties with the lexicographically greatest sequence.Medium7GreedySorting+2No attempts yet5s512 MBJudgeable
Bovine ConventionGiven N cow arrival times and M buses of capacity C, assign cows so the largest difference between a cow's arrival and its bus's departure is minimized.Medium7Binary searchGreedy+2No attempts yet2s512 MBJudgeable
Sterilizing SprayMaintain an array under point assignments and range operations that replace each value y by floor(y/K), answering range-sum queries; K is at most 10.Medium7Segment treeArray+2No attempts yet5s512 MBJudgeable
Get to Work, Lute!Chemicals with given viscosities travel in order through M pipes; find the completion time of each chemical given minimum-clearance waits between them.Medium7SimulationGreedy+2No attempts yet2s512 MBJudgeable
Buying Cards 3Sum, over all contiguous subarrays, of (maximum minus minimum) in the subarray.Medium7StackArray+2No attempts yet2s512 MBJudgeable
RunningOn a grid with walls, each move slides 1 to K empty cells in one of four directions; find the minimum number of moves from start to goal.Medium7BFSGraph+2No attempts yet1s512 MBJudgeable
Castle DefensePlace 3 archers on the wall row so that the total number of enemies killed by their attacks before reaching the wall is maximized.Medium7Brute forceSimulation+2No attempts yet1s512 MBJudgeable
Fine Dust, Goodbye!Simulate T seconds of dust diffusion on a grid plus the circular wind from a two-cell air purifier, then sum the remaining dust.Medium7SimulationImplementation+2No attempts yet1s512 MBJudgeable
Odd SubsequenceCount the distinct multisets chosen as subsequences whose element sum has an odd number of odd digits (1, 3, 5, 7, 9 in the decimal representation).Medium7CombinatoricsArray+2No attempts yet3s512 MBJudgeable
Unify the ColorsFor each button, compute the minimum presses needed to unify all colors when allowed to press only that button. Output the leftmost button with the smallest count.Medium7ImplementationArray+2No attempts yet1s512 MBJudgeable
Dynamic RollerFor each tile i, count the tiles to its right whose viscosity B is at most A_i, given B is nondecreasing.Medium7Binary searchArray+2No attempts yet2s512 MBJudgeable
Flag DanceMaintain an array under point updates and answer range queries for the absolute difference between sums of charismas at even and odd positions within the range.Medium7Segment treePrefix sum+2No attempts yet2s512 MBJudgeable
Sequence and Queries 1.5Maintain an array under point updates and answer range queries counting how many elements in a subarray exceed k.Medium7Segment treeSorting+2No attempts yet1.5s512 MBJudgeable
Blurred PicturesEach row gives a contiguous run of good pixels [ai, bi]; find the largest axis-aligned square whose every pixel is good.Medium7ArrayTwo pointers+2No attempts yet2s512 MBJudgeable
Tally CountersGiven initial and target values on n counters that wrap from m back to 1, find the minimum number of operations, where each operation pushes a contiguous block of counters once.Medium7Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Killing ChaosCoaches are destroyed one by one in a given order; after each destruction, report the maximum total chaos over the whole process, where chaos sums rounded-up segment counts times the number of segments.Medium7Union-findImplementation+2No attempts yet1s512 MBJudgeable
A+B ProblemAdd two huge integers given as run-length encoded digit blocks and print the sum in the same compressed format.Medium7ImplementationSimulation+2No attempts yet2s512 MBJudgeable
Incremental InductionGiven the tournament results of n players, choose an elimination order and find the smallest k so that at every prefix, at most k games were won by a player who is not yet inducted against one already inducted.Medium7GreedyImplementation+1No attempts yet2s512 MBJudgeable
Card DroppingGiven the technique used for each dropped card in order, reconstruct the initial top-to-bottom ordering of cards 1..N that produces a sorted pile.Medium7SimulationLinked list+2No attempts yet2s1024 MBJudgeable
Chisam's Stepping Stone CrossingWater spreads from given sources one cell per day; find the earliest day Chisam can walk over watered stones from (1,1) to (N,N).Medium7BFSBinary search+2No attempts yet1s1024 MBJudgeable
WinteringMaintain acorn counts on a circular walkway split into contiguous regions, supporting range additions and range sum queries over possibly wrapping cell intervals.Medium7Segment treePrefix sum+2No attempts yet2s256 MBJudgeable
Piano PerformanceAssign each of M notes to one of N fingers spaced K apart so the largest adjacent-note difficulty is minimized; output that minimum.Medium7Binary searchGreedy+2No attempts yet2s512 MBJudgeable
Idyllic InstagramDelete the fewest photos from a reading-order sequence so that no row of three contains photos from different trips, then print the remaining sequence in rows of three.Medium7Dynamic programmingArray+1No attempts yet1s512 MBJudgeable
SpidermanFor each skyscraper height, count how many other buildings it can jump to, where a jump from h_i to h_j is allowed only when h_i mod h_j equals K.Medium7MathNumber theory+2No attempts yet2s512 MBJudgeable
SongwriterGiven a melody A, find the lexicographically smallest B with the same up/equal/down pattern as A, bounded in [L, R], and with adjacent differences at most K.Medium7GreedyImplementation+2No attempts yet1s512 MBJudgeable
CalendarFind the minimum number of segment reversals that rotate an array of n elements cyclically by k positions, and output the reversals.Medium7ArrayMath+2No attempts yet1s512 MBJudgeable
Adult SharkSimulate a grid of sharks that each move by fixed directional priorities, leave fading scent trails, and eat the weaker shark when they collide, until only shark 1 is left.Medium7SimulationImplementation+2No attempts yet1s512 MBJudgeable
Matrix SumCount the submatrices of an N by M matrix whose element sum is at most x.Medium7Prefix sumTwo pointers+2No attempts yet2s256 MBJudgeable
Longest Increasing SubsequenceGiven target LIS-ending lengths f_i, construct a permutation of 1..n whose longest increasing subsequence ending at position i has length exactly f_i.Medium7GreedySorting+2No attempts yet1s256 MBJudgeable
Cute PandaEach panda splits its donuts between bin i and bin i+1 (cyclically); find the maximum total donuts the bins can absorb.Medium7GreedyArray+2No attempts yet2s512 MBJudgeable
PilotFor each of Q altitude limits, count subarrays of heights whose maximum is at most that limit.Medium7StackSorting+2No attempts yet1s512 MBJudgeable
Table TransformationApply up to a million row, column, and cell swaps to a large grid, then output a weighted modular checksum; the operation list is generated by a linear recurrence.Medium7SimulationArray+2No attempts yet4s512 MBJudgeable
Fighting RoutineFor every window length d from 1 to n, sum the number of distinct task types over all length-d windows of the given array.Medium7ArrayPrefix sum+2No attempts yet2s512 MBJudgeable
HandshakesGiven each employee's handshake count with earlier arrivals, find the largest possible number of friends any single employee can have.Medium7GreedyGraph+2No attempts yet2s512 MBJudgeable
Same TowersGiven up to 50 block heights summing to at most 500,000, find the maximum equal height achievable by two disjoint nonempty stacks, or report -1 if impossible.Hard8Dynamic programmingArray+1No attempts yet2s512 MBJudgeable
Quiz ShowFor N ordered quiz questions, choose right or wrong answers to maximize score: correct answers earn coins and points, hitting M coins gives a bonus, wrong answers reset coins and cost points.Hard8Dynamic programmingArray+2No attempts yet5s128 MBJudgeable
Choosing GuitarsN guitars sit in a circle, and each turn the mover must take one guitar from every remaining contiguous group; find the max total value the first player can secure with optimal play.Hard8Dynamic programmingGame theory+2No attempts yet2s128 MBJudgeable
N-RookGiven a grid with walls blocking line of sight and pit cells that block placement but not sight, find the maximum number of mutually non-attacking rooks.Hard8GraphDFS+2No attempts yet2s128 MBJudgeable
Number BoxGiven two rows of tiles that can slide within their row preserving order, find the arrangement maximizing the sum of column-wise products.Hard8Dynamic programmingGreedy+1No attempts yet2s512 MBJudgeable
Nap TimePick exactly B of N intervals arranged in a circle, maximizing sum of chosen values where the first interval of each consecutive block scores zero.Hard8Dynamic programmingGreedy+1No attempts yet2s128 MBJudgeable
Rank SortingGiven n distinct scores, output a minimum-cost sequence of single-element move operations (cost i+j each) that sorts them in descending order.Hard8GreedyArray+1No attempts yet1s128 MBJudgeable
Dynamic Sequence Data StructureDesign a data structure supporting range assignment, range arithmetic-progression addition, mid-sequence insertion, and range-sum queries efficiently.Hard8Segment treeArray+1No attempts yet1s128 MBJudgeable
Logo MatchingGiven a permutation pattern of length n and a sequence of m distinct heights, find all starting positions where a length-n window matches the relative order pattern.Hard8String matchingArray+1No attempts yet2s128 MBJudgeable
Selling LandFor every grid cell (as a rectangle's bottom-right corner), find the maximum perimeter of an all-grass rectangle ending there, then output counts grouped by perimeter.Hard8Dynamic programmingArray+1No attempts yet1s128 MBJudgeable
Digging for OilPlace three non-overlapping K by K squares on an M by N grid of oil estimates to maximize the total sum covered, with the grid up to 1500 by 1500.Hard8Prefix sumDynamic programming+2No attempts yet2s128 MBJudgeable
Magic BitstringsGiven a prime p, output the lexicographically smallest non-constant magic bitstring of length p-1, where each row of the modular index matrix must equal the string or its complement.Hard8Number theoryMath+2No attempts yet1s128 MBJudgeable
Intellectual PropertyGiven two code bases as raw strings, find the k longest maximal substrings of the JCN base that also occur in the TDP base, with exact positions and lengths.Hard8String matchingSorting+2No attempts yet1s128 MBJudgeable
Rubik's CubeGiven a scrambled Rubik's Cube as an unfolded net and a sequence of up to 1000 face rotations, output the cube state after applying all rotations.Hard8SimulationImplementation+2No attempts yet1s128 MBJudgeable
Edge DetectionGiven an image as run-length encoded runs, set each output pixel to the largest absolute difference from its 8 neighbors, and emit the result as runs.Hard8SimulationImplementation+2No attempts yet1s128 MBJudgeable
The Stairways of SaharnaSplit a sequence into k disjoint non-decreasing subsequences to maximize the total number of chosen elements, and output this maximum for every k up to the point where all n elements are used.Hard8Dynamic programmingGreedy+2No attempts yet0.2s128 MBJudgeable