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
XH CompanyFor each query day D, report the length of the shortest suffix ending on day D-1 with the largest average.Medium7StackPrefix sum+1No attempts yet2s256 MBJudgeable
Flipping ParenthesesAfter each single-bracket flip that breaks a balanced parenthesis string, find the leftmost second flip that restores balance.Medium7Segment treePrefix sumNo attempts yet5s256 MBJudgeable
UFOSimulate K laser shots that each remove the first R cells reaching one layer along a row or column, then find the P by P square with the largest remaining sum.Medium7Segment treeSimulation+2No attempts yet5s256 MBJudgeable
Strange AntennasCount grid cells covered by an odd number of diagonal triangular antenna signals.Medium7GeometryPrefix sum+1No attempts yet5s256 MBJudgeable
Kebab HouseCount subsets of the work seconds with gaps of at least t+1 such that each kebab misses at most q_i minus x_i ingredients, modulo 1e9+7.Medium7Dynamic programmingCombinatorics+1No attempts yet2s256 MBJudgeable
GatheringPick an integer intersection within Manhattan distance d of every house so the sum of Manhattan travel distances is smallest, or report impossible.Medium7GeometrySorting+2No attempts yet3s256 MBJudgeable
Third Round StandingsGiven two rounds of scores from 0 to 650, the task asks each contestant's highest and lowest final rank over third-round scores that respect dominance.Medium7Prefix sumGreedyNo attempts yet1s32 MBJudgeable
Cube ColoringCount the cubes in an X by Y by Z box by Manhattan distance from a given cube modulo N.Medium7CombinatoricsPrefix sum+1No attempts yet2s128 MBJudgeable
WTF TransformationChoose the ID array that maximizes the two-phase rotating sum and output that maximum with the lexicographically smallest optimal ID array.Medium7Dynamic programmingPrefix sum+1No attempts yet1s256 MBJudgeable
Fortress WallCount square one-cell-thick borders of size at least L that fit in an H by W grid without covering a tree.Medium7Prefix sumMatrixNo attempts yet10s512 MBJudgeable
Slave to achievements 1Craft as many N-cost daggers as possible and reclaim 0-to-K chips per dagger until fewer than N remain then print each final remainder probability modulo 1e9+7.Medium7Dynamic programmingProbability+2No attempts yet3s256 MBJudgeable
Rotating the KeyringCount all wrong key tries made while doors 1 to N are unlocked in cyclic order K times with a rotating keyring.Medium7ArrayMath+1No attempts yet1s64 MBJudgeable
Cow HopscotchCount paths from the top-left to the bottom-right cell moving down and right where consecutive cells hold different values.Medium7Dynamic programmingPrefix sumNo attempts yet1s256 MBJudgeable
Queen BeeSimulate N days of growth on an M by M grid where each inner cell copies the largest daily growth among its left, upper-left, and upper neighbors.Medium7Dynamic programmingPrefix sumNo attempts yet2s256 MBJudgeable
Palembang BridgesChoose positions for up to two bridges so the total driving distance of all citizens is minimized.Medium7SortingGreedy+1No attempts yet2s256 MBJudgeable
RukaUpdate vectors of a polyline through cursor commands and report how many segments cross the coordinate axes.Medium7Segment treePrefix sumNo attempts yet2s512 MBJudgeable
Block StackingCount distinct front-view colorings of supported stacks of width W and height at most H built from unlimited blocks of widths 1 to K, modulo 1e9+7.Medium7Dynamic programmingCombinatorics+1No attempts yet1s32 MBJudgeable
City InfluenceAdd N weighted rectangles on a billion by billion grid and print the sum of squared cell values modulo 1,000,000,007.Medium7Segment treeSorting+1No attempts yet2s64 MBJudgeable
Covering the gridPlace corner-touching rectangles chaining from the top-left cell to the bottom-right cell to maximize the sum of covered cell values.Medium7Dynamic programmingPrefix sumNo attempts yet1s256 MBJudgeable
Unique right triangleCount the perimeters up to N that form exactly one integer-sided right triangle.Medium7Number theoryArray+1No attempts yet1s256 MBJudgeable
Rectangle update and rectangle sumYou add w to all cells in one rectangle per update and print the cell sum of one rectangle per query in order.Medium7Segment treePrefix sum+1No attempts yet1s256 MBJudgeable
Icons in the ToolbarPlace 2N squares with given side lengths into a 2 by N grid so the product of the summed row heights and summed column widths is minimal.Medium7GreedySorting+1No attempts yet1s256 MBJudgeable
Spam FilterFind the contiguous block of at least k binary results with the highest share of ones, breaking ties by earliest start then shortest length.Medium7Binary searchPrefix sum+1No attempts yet1s256 MBJudgeable
The Running GamePick disjoint segments of the given sequence so the sum of each segment weighted by its position inside the segment is as large as possible.Medium7Dynamic programmingPrefix sum+1No attempts yet1s512 MBJudgeable
RainfallChoose when to leave and how fast to ride within T minutes to minimize trip rain plus sweat that grows with the square of speed.Medium7MathPrefix sum+1No attempts yet5s256 MBJudgeable
TelescopeCount the 4-connected white regions of a binary sky given only its N by N averaged and rounded-down picture.Medium7GreedyPrefix sum+1No attempts yet1s256 MBJudgeable
Keep it energizedBuy energy packs at level shops so the stored energy covers each level cost in order for the least total cash.Medium7Dynamic programmingSegment tree+2No attempts yet3s256 MBJudgeable
LCM(i, j)Add the least common multiple over every pair i<j up to n and print the remainder modulo 1,000,000,007.Medium7Number theoryMath+1No attempts yet1s256 MBJudgeable
Delete This!Find the fewest icons to move so a single box encloses all delete centers and excludes all keep centers.Medium7GeometryPrefix sum+1No attempts yet1s256 MBJudgeable
Jumping JoeyA frog visits pads in order, pulls ropes to drag upcoming pads closer, jumps gaps up to D, swims the rest, and needs the fewest swims.Medium7Dynamic programmingGreedy+1No attempts yet3s256 MBJudgeable
Building a Scholarship TableCount CGPA range tables with equal widths and arithmetic rates that spend exactly P units on the given students.Medium7Brute forceMath+1No attempts yet4s256 MBJudgeable
Weighing the stonesAfter each ranked stone is placed on pan 1 or pan 2, report whether pan 1 is heavier under every valid weight assignment, pan 2 is, or neither is certain.Medium7Segment treeGreedy+1No attempts yet1s256 MBJudgeable
XORPrint the start and length of the longest contiguous segment whose xor is at least x.Medium7TrieBit manipulation+1No attempts yet5s256 MBJudgeable
Gold Camp ForcefieldChoose a contiguous group of camps whose total energy covers the distance between its ends to maximize total gold.Medium7Segment treePrefix sum+1No attempts yet1s256 MBJudgeable
Circular BarnChoose up to k outer doors on a ring of n rooms so the total clockwise walking distance to every cow room is minimized.Medium7Dynamic programmingPrefix sumNo attempts yet2s512 MBJudgeable
Circular BarnAssign each cow waiting outside n rooms on a ring to a distinct room clockwise ahead so the sum of squared walking distances is as small as possible.Medium7GreedyPrefix sumNo attempts yet2s512 MBJudgeable
Circular Barn RevisitedFarmer John opens k doors on a ring of n rooms so cows walking clockwise to their assigned rooms travel the smallest total distance.Medium7Dynamic programmingPrefix sum+1No attempts yet2s512 MBJudgeable
Sums of Sums (Large)Given a positive array, sort all its subarray sums and answer the sum of entries ranked L through R for each query.Medium7Binary searchTwo pointers+1No attempts yet5s512 MBJudgeable
Pretty Good Proportion (Large)Given a binary string and a target fraction F, find the smallest starting position among substrings whose proportion of 1s is closest to F.Medium7Prefix sumSortingNo attempts yet5s512 MBJudgeable
Smoothing Window (Large)Given N, K and every window sum of a hidden integer sequence, find the smallest max-minus-min range among all integer sequences that match.Medium7Binary searchMath+1No attempts yet5s512 MBJudgeable
Hot Dog ProliferationSpread vendors sharing corners with pair splits that send one vendor east and one west, using the fewest moves so every corner holds at most one vendor.Medium7MathGreedy+2No attempts yet5s512 MBJudgeable
Interesting Ranges (Small)Count subranges of [L, R] containing an even number of decimal palindromes, modulo 1000000007, for R up to 10^13.Medium7MathCombinatorics+2No attempts yet5s512 MBJudgeable
Busiest railway segment (large)Given a tree and Q paths, count how many paths use each edge and report the edge with the maximum count, breaking ties by lexicographic order of endpoints.Medium7TreeDFS+2No attempts yet2s512 MBJudgeable
Problem PreparationMaintain an array under point increments and decrements, and after each update answer the sum of ceil(t_i / k) for a given k.Medium7MathPrefix sum+2No attempts yet2s256 MBJudgeable
Range XORMaintain an array under range xor updates and range xor queries, both on subarrays given by index bounds.Medium7Bit manipulationSegment tree+2No attempts yet2s512 MBJudgeable
Decompose into a ProductGiven m as a product of n factors (n ≤ 500, each up to 1e9), count ordered n-tuples of positive integers whose product is m, modulo 1e9+9.Medium7Number theoryCombinatorics+2No attempts yet2s512 MBJudgeable
Number lock 2Given two equal-length digit strings S and T, find the fewest moves to turn S into T where a move shifts any contiguous block of dials one step up or down modulo 10.Medium7Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Moving Stones Around a CircleGiven stone counts a and b on a cycle of N positions, find the minimum number of moves to transform a into b, or report impossibility.Medium7GreedyPrefix sum+1No attempts yet2s512 MBJudgeable
Secret LinesSum |Xa - Xb| * max(Va, Vb) over all pairs of members with given power and position.Medium7SortingDivide and conquer+1No attempts yet1s512 MBJudgeable
Colorful Village 3For each query range of houses, report the highest number of times any single brightness value appears within that range.Medium7Prefix sumSorting+1No attempts yet5s512 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
Maximal SumFor each query value b_j, find the maximum sum of a contiguous segment of a whose elements are all at least b_j, or 0 if none exists.Medium7SortingDivide and conquer+2No attempts yet2s512 MBJudgeable
FishCount contiguous subarrays whose sum is at least K.Medium7Prefix sumDivide and conquer+2No attempts yet1s64 MBJudgeable
Glass BridgeGiven N and values a_i, count pairs i < j with a_i > a_j.Medium7ArrayDivide and conquer+2No attempts yet1s512 MBJudgeable
Contiguous Subsequence XORCount contiguous subsequences of the given sequence whose bitwise XOR is less than K.Medium7Bit manipulationTrie+1No attempts yet1s512 MBJudgeable
Integral PolygonsCount the diagonals of a convex polygon that split it into two pieces of integer area, given integer vertex coordinates.Medium7GeometryMath+2No attempts yet2s256 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
Chameleon SubstringGiven a string S, find the longest substring that is both a prefix and a suffix of S and also appears somewhere strictly inside S.Medium7String matchingString+1No attempts yet2s512 MBJudgeable
Tree and Queries 2Answer path-cost and k-th-vertex queries on a weighted tree with up to 100,000 nodes and queries.Medium7TreeBinary search+2No attempts yet2s512 MBJudgeable
Build a BoatSplit a simple polygon into the largest number of equal-area vertical sections, each of area at least C, and print the bulkhead x-coordinates.Medium7GeometryPrefix sum+1No attempts yet2s512 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
Bracket substring queriesFor each query substring, find the length of the longest balanced bracket subsequence within it.Medium7Prefix sumString+2No attempts yet2s512 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
Prefix and SuffixFor each prefix of S that is also a suffix, output its length and how many times it occurs as a substring.Medium7String matchingPrefix sum+1No attempts yet2s512 MBJudgeable
Perfect ChoirGiven sorted starting notes for N singers, each measure moves one singer up and another down by one; find the minimum measures until all notes are equal, or -1 if impossible.Medium7MathGreedy+2No attempts yet2s512 MBJudgeable
Strings and QueriesFor a string S, F(i) is the length of the longest common suffix of S and the prefix of S ending at position i; answer M queries for F(i).Medium7StringString matching+2No 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
Orchard DivisionFind the smallest axis-aligned rectangle anchored at one orchard corner that contains exactly half of N given tree coordinates.Medium7GeometryPrefix sum+1No attempts yet2s512 MBJudgeable
Performance ReviewFor each employee, sum t_j over all descendants j whose rank r_j is lower than the employee's rank.Medium7TreeDFS+2No attempts yet2s512 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
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
The Hottest Piece of CheeseGiven two families of non-crossing cuts across a rectangle and points inside it, find the piece containing the most peppers.Medium7GeometrySorting+1No attempts yet1s512 MBJudgeable
BananasPlace a spiral-walking monkey on an infinite grid so every banana cell lies on its path, minimizing total steps walked.Medium7GeometryImplementation+2No attempts yet1s128 MBJudgeable
RivaFind two points on a left-to-right non-self-intersecting polyline whose allowed chord length is within L and maximizes the area between the chord and the polyline above it.Medium7GeometryTwo pointers+1No attempts yet2s64 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
Blocks&BallsGiven a container with fixed blocks and balls inside, find the water level where water volume v fills the region below that height.Medium7Binary searchGeometry+2No attempts yet2s512 MBJudgeable
Smallest Square 2Given N lattice points, choose an axis-aligned square with lattice corners containing at least K points strictly inside and minimize its area.Medium7Binary searchSorting+2No 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
Hyobin the LiarGiven missiles landing on distinct cells in order, find the first missile after which no legal placement of k non-touching ships of length a survives.Medium7Binary searchGreedy+1No attempts yet2s512 MBJudgeable
Drawing a PicturePaste the same N by M clipboard picture T times with its top-left corner at (i,i) for each second i, then count red, green, and blue pixels remaining.Medium7MatrixMath+1No attempts yet2s512 MBJudgeable
Three PointsCount triples of points where the x coordinates increase and the y coordinates order as r < b < g.Medium7SortingPrefix sum+1No attempts yet2s512 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
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
Remove One for the Greatest GCDRemove one number so the GCD of the rest is as large as possible, but that GCD must not divide the removed number.Medium7Number theoryPrefix sum+1No attempts yet2s512 MBJudgeable
Apple MarketGiven a grid of apple inventories and rectangle requests with budgets, sell apples to maximize total money where each apple costs 1.Medium7GreedySorting+1No attempts yet2s512 MBJudgeable
Professional NetworkGiven N people, each joinable when Kevin's current connection count reaches A_i or by paying B_i points, find the minimum total points to connect with everyone.Medium7GreedySorting+2No attempts yet2s512 MBJudgeable
Drawing a pictureColors cycle through cells of a row-major grid; each cell area is H_i times W_j. Report the total area covered by each color.Medium7MathPrefix sum+2No attempts yet2s512 MBJudgeable
Venue Rental (Large)Given up to 3000 axis-aligned rectangles, find the total area of their union, counting overlaps once.Medium7GeometrySorting+2No attempts yet5s256 MBJudgeable
Faster SortingFor each MINRUN, simulate Timsort's run splitting and report the number of subarrays and the number of bad elements pulled in.Medium7SimulationTwo pointers+1No attempts yet1s128 MBJudgeable
Good RectanglesPrecompute an answer table so each query asks how many all-zero subrectangles fit inside a given rectangle of an n by m binary grid.Medium7Dynamic programmingPrefix sum+1No attempts yet4s256 MBJudgeable
Binary String ToggleApply U range-toggle operations to an all-zero binary string and print the lexicographically largest string among all U+1 intermediate states.Medium7Prefix sumGreedy+1No attempts yet2s512 MBJudgeable
Gather at one pointFor each query [l, r], find the minimum sum of Chebyshev distances from the people l..r to a freely chosen point.Medium7Prefix sumDivide and conquer+2No attempts yet5s512 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
Tree VisitsMaintain a value X under increments of 2^C modulo 2^N, mark all nodes on each root-to-leaf walk, and report the count of distinct visited nodes.Medium7TreeBit manipulation+2No attempts yet5s1536 MBJudgeable
Gems (GEM)Given range-sum constraints modulo 10 on an array of N values each in [0,100], find the lexicographically smallest valid array or report -1 if the constraints conflict.Medium7Union-findPrefix sum+2No attempts yet2s512 MBJudgeable
AntsEach room of a weighted tree rooted at room 1 holds an ant with limited energy; for every ant, find the closest-to-root room it can reach moving toward room 1.Medium7TreeDFS+2No attempts yet2s256 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