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,178 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
RAMProcess files one by one; after each, count how many times a given letter appears in the last K characters seen so far.Medium6ArraySimulation+2No attempts yet2s512 MBJudgeable
Big TableEach row of a huge table repeats a short digit period; answer rectangle-sum queries without materializing the table.Medium6Prefix sumMath+2No attempts yet4s128 MBJudgeable
The Walk to SchoolCount ordered pairs of grass cells where a fixed three-segment path (east, south, east) stays entirely on grass cells.Medium6MatrixSimulation+2No attempts yet6s128 MBJudgeable
Array CharacteristicMove one element to any position and maximize the weighted sum of A_i times its new index.Medium6ArrayPrefix sumNo attempts yet2s512 MBJudgeable
Water TankFind the smallest constant drain rate R so the tank never exceeds capacity C while inflow runs through n phases.Medium6Binary searchPrefix sum+1No attempts yet2s512 MBJudgeable
XORMaintain an array under range XOR updates and point queries, printing each queried element in order.Medium6Binary searchPrefix sum+2No attempts yet2s512 MBJudgeable
Foehn PhenomenaAfter each range add to altitudes, report the wind temperature at spot N, where the total depends on the altitude differences between adjacent spots.Medium6ArrayPrefix sum+1No attempts yet1s256 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
Ground DefenseHandle updates that add an arithmetic sequence of troops along a line of cities in one direction, and answer queries for a city's running total.Medium6Prefix sumImplementation+2No attempts yet2s512 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
Ample Syrup (Large)Choose K of N cylindrical pancakes and stack them largest radius first to maximize exposed surface area, reported as a multiple of pi.Medium6GreedySorting+2No attempts yet5s512 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
Subarray XOR sumsFor a sequence, count how often each XOR value appears among all contiguous subarrays, then report the most frequent value, breaking ties by choosing the smallest.Medium6Prefix sumBit manipulation+2No attempts yet2s512 MBJudgeable
Pond CascadeGiven pond capacities and a common fill rate, compute the exact times when the lowest pond begins to overflow and when every pond is full.Medium6SimulationMath+1No 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
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
School PairingFor each query range, count pairs of positions whose skill grades sum to K.Medium6Hash mapPrefix sum+1No attempts yet2s512 MBJudgeable
RoofGiven N column heights, pick a peak position and height so the roof shape h_j = peak - |peakpos - j| is positive everywhere, minimizing total absolute changes.Medium6ArrayPrefix sum+2No attempts yet1.5s128 MBJudgeable
Haybale FeastPick a contiguous block whose flavor sums to at least M while minimizing the block's maximum spiciness.Medium6Two pointersSliding window+2No attempts yet2s512 MBJudgeable
My Cow Ate My HomeworkFor each prefix length K that the cow ate, compute the average after dropping the single lowest remaining score, and list every K that maximizes it.Medium6ArrayPrefix sum+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
LifeguardsFire exactly one of N given time intervals, then maximize the total length of time covered by at least one of the remaining intervals.Medium6IntervalsSorting+1No attempts yet2s512 MBJudgeable
Farmer Juan is a baristaMaintain a grid under range-add rectangle updates and point queries, answering each point query using only earlier updates.Medium6Prefix sumMatrix+2No attempts yet2s512 MBJudgeable
MinecraftGiven N rocks in a row with swing costs K_i, moving costs P, and budget T, find the maximum number of stones that can be collected.Medium6GreedyBinary search+2No attempts yet1s128 MBJudgeable
Strawberry Carrot Watermelon Chamoe Melon GameGiven n words repeated in a b-beat cycle, find the turn on which a target word is shouted for the X-th time.Medium6MathBinary search+2No attempts yet1s128 MBJudgeable
Hiding AcornsGiven K arithmetic-progression rules marking boxes, find the box number where the D-th acorn is placed, counting boxes in increasing order.Medium6Binary searchPrefix sum+1No attempts yet1s128 MBJudgeable
Directory TraversalGiven a directory tree, choose a directory that minimizes the total length of all relative paths from it to every file.Medium6TreeDFS+2No attempts yet2s512 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
Invader JinaPlace two poison sources on empty cells of an N by M grid so that the maximum Manhattan distance from any village to its nearest source is minimized.Medium6Brute forceMath+2No attempts yet2s256 MBJudgeable
Capsaicin Tastes Good in SpringGiven N Scoville values, multiply each adjacent gap in sorted order by (2^k - 1) and sum modulo 1000000007.Medium6SortingCombinatorics+2No attempts yet1s512 MBJudgeable
Junpyo's PebblesFind the longest contiguous segment containing at most B black pebbles and at least W white pebbles.Medium6Two pointersSliding window+1No attempts yet1s512 MBJudgeable
MeetingAdjust arrival times at cost 1 per second so that exactly K subordinates sit in an interval [0, X] with X a nonnegative integer; minimize cost.Medium6Sliding windowSorting+2No attempts yet2s512 MBJudgeable
Tree and ColorsGiven a rooted tree with colored vertices and queries f(v,c) counting subtree vertices of color at most c, print the sum of all answers modulo 1e9+7.Medium6TreeDFS+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
XCorrGiven two sparse nonnegative sequences, sum the cross-correlation XCorr(t) over all shifts t in a query range.Medium6Prefix sumMath+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
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
LiarsGiven each person's claimed range for the truth-teller count, find the maximum possible number of truth-tellers within any consistent assignment.Medium6Hash mapPrefix sum+1No attempts yet1s512 MBJudgeable
Rectangle EscapeA rectangle slides on a grid with walls; find the shortest sequence of unit moves taking its top-left cell from start to finish.Medium6BFSPrefix sum+2No attempts yet2s512 MBJudgeable
Bitaro the BraveCount quadruples (i, j, k, l) with i<k and j<l such that grid cells (i,j)='J', (i,l)='O', (k,j)='I'. H, W up to 3000.Medium6Prefix sumArray+1No attempts yet1s512 MBJudgeable
Painting the Barn (Silver)Given N axis-aligned rectangles with coordinates in 0..1000, find the total area covered by exactly K of them.Medium6Prefix sumArray+2No attempts yet2s512 MBJudgeable
Alice in the Digital WorldFind the maximum sum over subarrays whose minimum element equals m, given that the array and m are bounded by 26.Medium6ArrayDivide and conquer+2No attempts yet1s512 MBJudgeable
Coloring PracticeCount how many 3x3 subgrids contain exactly i black cells for each i from 0 to 9, given up to 1e5 black cells on a huge grid.Medium6Prefix sumHash map+2No attempts yet1s512 MBJudgeable
Why the Fox Climbed Information IslandCount triples of stars (s,t,u) with s.x < t.x < u.x and s.y > t.y < u.y, output the count modulo 1e9+7.Medium6SortingBinary search+2No attempts yet1s256 MBJudgeable
Lemoine's ConjectureCount, for each odd N up to 10^6, the representations N = p + s where p is an odd prime and s is an even semiprime (product of two primes).Medium6Number theoryPrefix sum+2No attempts yet2s512 MBJudgeable
Life GameSimulate Conway-style life on an N x M board for T steps using a (2K+1) square neighborhood with thresholds a and b, then print the final board.Medium6SimulationImplementation+2No attempts yet2s512 MBJudgeable
Galactic RailwayAdd up to M edges between N galaxies one at a time; after each edge print the total planet count in the merged component.Medium6Union-findGraph+2No attempts yet5s512 MBJudgeable
StockFind the shortest subarray whose sum minus y times its length is at least Z and whose length times y is at most X, breaking ties by the latest start.Medium6Sliding windowPrefix sum+2No attempts yet1s512 MBJudgeable
Candy DeliveryGiven N candies weighing 3 g or 5 g with sweetness values and a weight limit w, choose a subset to maximize total sweetness.Medium6GreedySorting+2No attempts yet1s512 MBJudgeable
Bracket String and QueriesFlip one character per query and count how many prefixes of the query sequence leave the string as a correct bracket sequence.Medium6StringPrefix sum+2No attempts yet0.5s512 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
Saving the Ryan StatueChoose one integer point on each side of an N by N square to form a smaller rectangle, maximizing the total value of statues it covers, including those on its border.Medium6ArrayPrefix sum+2No attempts yet3s1024 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
Monument TourPick one eastbound row for the bus to travel; the cost is the horizontal distance across plus twice the vertical detours to visit every monument, and we minimize it.Medium6MathPrefix sum+2No attempts yet1s512 MBJudgeable
JOIOJIGiven a string of J, O, and I, find the longest contiguous substring with equal counts of all three letters.Medium6Prefix sumHash map+2No attempts yet1s512 MBJudgeable
Gerrymandering 2For an N x N grid, try every valid 5-way district split defined by a reference point and two boundary lengths, and report the smallest difference between the largest and smallest district populations.Medium6Brute forceSimulation+2No attempts yet1s512 MBJudgeable
Beer MarathonGiven N beer booth positions and a fixed spacing K, choose an arithmetic progression of N positions (any start) minimizing the total absolute movement of the booths.Medium6SortingGreedy+2No attempts yet2s512 MBJudgeable
Domino PredictionGiven XORs of consecutive domino numbers, answer queries for the XOR of positions x and y, or for the value at y when x holds d.Medium6Prefix sumBit manipulation+2No 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
FractionFor each query, print n decimal digits of a/b starting at the i-th digit after the decimal point, using the terminating representation when two exist.Medium6MathNumber theory+2No attempts yet1s1024 MBJudgeable
Penguin Fall Response CommitteeGiven a line of N blocks with break costs and one marked penguin position, find the minimum total cost to break blocks so the penguin's group falls off the line.Medium6GreedyArray+2No attempts yet2s512 MBJudgeable
Milk VisitsGiven a tree with each node labeled G or H, answer queries asking whether the path between two nodes contains at least one node of a given label.Medium6TreeDFS+2No 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
Just Long NecktiesFor each of the N+1 neckties, remove it and match the remaining N ties to N employees so the largest excess max(a-b, 0) is minimized.Medium6GreedySorting+2No attempts yet2s512 MBJudgeable
JJOOII 2Given a string of J, O, I and a level K, delete characters from the ends or middle to obtain K J's then K O's then K I's, minimizing middle deletions.Medium6GreedyTwo pointers+2No attempts yet2s512 MBJudgeable
Money SharingGiven a sequence of resupplies and loan requests, decide which requests to approve so that the balance never goes negative while declining as few as possible.Medium6GreedyHeap+2No attempts yet1s512 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
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
Multiple of N (1)Given 2N-1 numbers, find N of them whose sum is divisible by N, or report that none exists.Medium6CombinatoricsPrefix sum+2No attempts yet2s512 MBJudgeable
Hyper Array and Hyper QueriesGiven a value for every cell of an 11-dimensional array, answer range-sum queries over axis-aligned 11-dimensional boxes.Medium6Prefix sumArray+2No attempts yet2s512 MBJudgeable
Subarray Average of a SequenceCount the contiguous subarrays of a given sequence whose elements have an average exactly equal to K.Medium6Prefix sumHash map+2No attempts yet1s256 MBJudgeable
CryptographyGiven a permutation P of N distinct integers, output the 1-based rank of P among all permutations of its values, modulo 1,000,000,007.Medium6CombinatoricsSorting+2No attempts yet1s512 MBJudgeable
Collecting MushroomsGiven a grid with mushrooms and sprinklers, count mushrooms covered by at least K sprinklers within Chebyshev distance D.Medium6Prefix sumMatrix+2No attempts yet1s512 MBJudgeable
SnailGiven a daily cycle of N moves that can climb or slide (never below 0), find the day and phase when the snail first reaches height H, or -1 -1 if it never does.Medium6MathSimulation+2No attempts yet1s512 MBJudgeable
Sequence TransformationGiven a sequence of non-negative integers, find the minimum number of single increments needed so that 1,2,...,h appear consecutively as a block, or report that it is impossible.Medium6ArraySliding window+2No attempts yet2s512 MBJudgeable
Two PrefixesGiven strings s and t, count distinct strings formed by concatenating a non-empty prefix of s with a non-empty prefix of t.Medium6StringString matching+2No attempts yet1s512 MBJudgeable
Jimin and Hansu's Orchard SplitGiven up to 50 weighted points on a plane, find a line avoiding all points that splits them into two groups minimizing the difference of their value sums.Medium7GeometrySorting+2No attempts yet2s128 MBJudgeable
Equal-Length Subarray Sum DifferenceFor every subarray length k, find two non-overlapping equal-length subarrays whose sums differ the least, then report the k (largest on ties) with the smallest such difference.Medium7Prefix sumSliding window+2No attempts yet5s128 MBJudgeable
MedianGiven N temperature readings, compute the sum of medians of every contiguous window of length K using an efficient order-statistics structure.Medium7Sliding windowHeap+2No attempts yet1s128 MBJudgeable
Sharp EyesGiven up to 20,000 arithmetic progressions forming a multiset, find the single integer with odd multiplicity using binary search on prefix parity.Medium7Binary searchMath+2No attempts yet2s128 MBJudgeable
Parcel DeliveryGiven each parcel's destination branch along a line, find the minimum cost to deliver all parcels using per-distance trucks and fixed-cost multi-parcel helicopter trips.Medium7Dynamic programmingSorting+2No attempts yet2s128 MBJudgeable
Number GameGiven a sequence of numbers, determine the winner of a two-player suffix-removal game where each player takes a suffix block ending at the current rightmost element and minimizes their own total sum, for three separate games with n up to 3000.Medium7Dynamic programmingGame theory+1No attempts yet2s128 MBJudgeable
Collecting GemsGiven N gem values, find a contiguous subarray of length at least M that maximizes floor(1000*sum/length), using binary search on the average.Medium7Binary searchPrefix sum+1No attempts yet2s128 MBJudgeable
Counting Submatrices with Divisible SumsCount contiguous submatrices of an N by M matrix (N,M up to 256) whose sum is divisible by K, requiring an efficient prefix-sum plus hashing technique.Medium7Prefix sumHash map+1No attempts yet1s128 MBJudgeable
Sangbeom's MelancholyGiven daily moods, compute flower-giving intervals before each depressed run (2T days, or 3T for one chosen longest run) and find the maximum count of distinct covered days by optimally picking which longest run gets the 3T rule.Medium7IntervalsGreedy+1No attempts yet1s128 MBJudgeable
Walking TrailFor up to 100,000 rectangle queries over 300,000 points, count how many points lie exactly on the boundary of each axis-aligned rectangle.Medium7Prefix sumBinary search+1No attempts yet1s128 MBJudgeable
ClotheslineFor each query time, compute the total overlapping area of given rectangles covered by an expanding Chebyshev-distance square of oil centered at the origin.Medium7Prefix sumGeometry+2No attempts yet2s128 MBJudgeable
Median of a Contiguous SubsequenceCount odd-length contiguous subarrays of a permutation of 1..N whose median equals a given value B.Medium7Prefix sumHash map+1No attempts yet1s128 MBJudgeable
Find the MultiplesCount index pairs (i,j) with a_i nonzero such that the decimal number formed by a_i...a_j is divisible by a given prime Q, for a pseudo-randomly generated digit sequence of length up to 1e5.Medium7MathHash map+2No attempts yet2s128 MBJudgeable
Riding Roller CoastersGiven N coasters with fun a_i-(k-1)^2*b_i per ride and fixed ride times, answer Q queries for the maximum total fun within each time budget.Medium7Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
HyperdromeCount substrings of S whose characters can be rearranged into a palindrome, where only the parity of each letter's count matters.Medium7Bit manipulationPrefix sum+2No attempts yet2s128 MBJudgeable
The Minotaur's LabyrinthFind the smallest empty square, avoiding the two corner cells, whose removal disconnects the top-left entrance from the bottom-right lair.Medium7GraphBFS+2No attempts yet2s128 MBJudgeable
The Banzhaf Buzz-OffGiven board members with distinct weights, count for each weight how many winning coalitions make a member with that weight a critical voter.Medium7Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Lawrence of ArabiaCut at most M of the N-1 gaps in a line of weighted depots to minimize the sum of products over all still-connected pairs.Medium7Dynamic programmingPrefix sum+1No attempts yet2s128 MBJudgeable
Largest SquareGiven an N by N grid with W bad cells listed explicitly, find the largest axis-aligned square containing at most L bad cells.Medium7Binary searchPrefix sum+2No attempts yet2s128 MBJudgeable
Choosing the Final Die's Face ValuesEach test case fixes several dice and asks for the r face values of the last die so that m given sums appear with exactly the given counts, choosing the lexicographically smallest set.Medium7Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Covered WalkwayCover all required points on a line with segments, where covering from x to y costs c plus (x - y) squared, minimizing total cost.Medium7Dynamic programmingDivide and conquer+1No attempts yet10s128 MBJudgeable
EstimationPartition an array into k contiguous sections, each replaced by one constant value, to minimize the total absolute error. Multiple test cases until 0 0.Medium7Dynamic programmingDivide and conquer+2No attempts yet5s128 MBJudgeable
Value of a TriangleGiven up to 400 rows of a triangular grid of unit triangles, find the sub-triangle with the largest sum of unit values.Medium7Dynamic programmingPrefix sum+2No attempts yet1s256 MBJudgeable