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,702 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
HypercubeOn the N-hypercube whose arcs join labels differing in one bit, find the largest predecessor and smallest successor of M, then count all paths of length K.Medium7CombinatoricsBit manipulation+2No attempts yet0.2s1024 MBJudgeable
Avoiding the HeatCount the lattice paths from a start point to a home point using at most T unit steps in the four cardinal directions, avoiding N blocked points.Medium7Dynamic programmingCombinatorics+2No attempts yet1s512 MBJudgeable
Network HackingGiven a weighted tree, cut one edge, then reconnect its two endpoints with an edge of the same weight to maximize the resulting tree's diameter.Medium7TreeDFS+2No attempts yet1s512 MBJudgeable
KbinSum every number below N whose binary form has exactly k ones, then report that sum modulo 1234567.Medium7CombinatoricsBit manipulation+2No attempts yet1s512 MBJudgeable
Balanced TreesCount perfectly balanced trees of weight N, where a tree splits into k identical subtrees each of the largest weight summing within the parent's weight.Medium7TreeNumber theory+2No attempts yet2s512 MBJudgeable
JoyrideFind the cheapest closed walk from ride 1 back to ride 1 whose total time (ride durations plus pavement crossings) equals exactly x minutes.Medium7GraphShortest path+2No attempts yet2s512 MBJudgeable
AndCount K-term non-negative integer sequences whose bitwise AND decreases monotonically and whose terms sum to N, modulo 1e9+7.Medium7Bit manipulationDynamic programming+1No attempts yet2s512 MBJudgeable
Moonlight FoxCount vertices where the fox's shortest-path distance is strictly less than the minimum binary-modulated walk time from 1, computed with a run/walk parity state graph.Medium7GraphShortest path+1No attempts yet1s512 MBJudgeable
UnaryCount length-N strings of negation and bitwise-NOT that map 0 to M in two's complement, modulo 998244353.Medium7Dynamic programmingMath+1No attempts yet1s512 MBJudgeable
Blowin' in the WindOn a connected undirected graph with nodes offering some of g ordered goals, find the fewest edge traversals from node 1 to attain goals 1 to g in order.Medium7GraphShortest path+2No attempts yet2s512 MBJudgeable
Bits and GahuiCount multiples of A up to B whose binary representation has 1s in all N specified bit positions.Medium7Bit manipulationDynamic programming+2No attempts yet0.5s256 MBJudgeable
Knights and KnavesGiven two rows of k soldiers, each asked the same one or two questions about exact knight or knave counts among neighbors and all answering yes, find the minimum and maximum possible number of knights, or -1.Medium7Dynamic programmingImplementation+2No attempts yet2s512 MBJudgeable
New KeyboardSwitch layouts by cycling, with a switch after another switch costing b instead of a, and type the message with minimal total time.Medium7Dynamic programmingGraph+2No attempts yet2s512 MBJudgeable
Explosion ExploitGiven up to 10 minions with health at most 6 and d up to 100, find the chance that uniformly random sequential damage kills every opposing minion.Medium7Dynamic programmingCombinatorics+1No attempts yet3s512 MBJudgeable
Space StationGiven a tree with weighted edges, find the minimum time to start at node 1, traverse every edge at least once, and return, where up to M jumps between any two modules cost K each.Medium7TreeDynamic programming+2No attempts yet1s512 MBJudgeable
Split GameGiven piles of tokens, players alternately split one pile into copies of some smaller size K; decide the winner under optimal play.Medium7Game theoryDynamic programming+2No attempts yet2s512 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
Pokemon Go GoGiven up to 20 stops with pet names on a grid, find the shortest closed walk from the origin that catches every distinct pet at least once.Medium7Dynamic programmingBit manipulation+1No attempts yet5s512 MBJudgeable
Smooth ArrayChange the fewest array elements so every window of K consecutive values sums to exactly S, with values kept in [0, S].Medium7Dynamic programmingMath+2No attempts yet2s512 MBJudgeable
Coprime IntegersCount ordered pairs (x, y) with x in [a, b] and y in [c, d] that share no common factor greater than 1.Medium7Number theoryMath+2No attempts yet2s512 MBJudgeable
FestivalPick exactly one non-overlapping show from each of up to 10 stages so the total known-song count is maximized, or report -1 if no valid selection exists.Medium7Dynamic programmingBit manipulation+2No attempts yet2s512 MBJudgeable
Hawawa College Student-chan Goes to Hawaii~Count the ways to start at island 1 and visit all n islands exactly once using steps +1, +2, or -1 to new islands, modulo 1,000,000,009.Medium7Dynamic programmingMath+1No attempts yet1s256 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
Math MazeFind the shortest walk from S to E in a directed graph where visiting any trap region flips the direction of certain trap edges every P-th press.Medium7GraphShortest path+2No attempts yet1s512 MBJudgeable
Largest ValueChoose M disjoint contiguous groups in an array of up to 20 numbers so the total sum of their elements is as large as possible.Medium7Dynamic programmingPrefix sum+1No attempts yet2s512 MBJudgeable
Arithmetic Without ParenthesesGiven an arithmetic expression without parentheses where all four operators have equal precedence, find the minimum and maximum results over all evaluation orders, using custom integer division rules.Medium7Dynamic programmingRecursion+1No attempts yet1s512 MBJudgeable
TextbooksGiven up to 16 priced book titles and a target word of length at most 10, find the cheapest subset of books whose letters can be rearranged to form the target.Medium7Bit manipulationDynamic programming+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
N PokerCount 52-card N-subsets containing a rank's four suits, output the count mod 10,007.Medium7CombinatoricsMath+2No attempts yet1s256 MBJudgeable
Peg Game for TwoGiven a weighted triangular peg board with one empty hole, compute the optimal difference of Jacquez's score minus Alia's when both alternately jump and play to maximize their margin.Medium7DFSGame theory+2No attempts yet2s512 MBJudgeable
Adding Parentheses 2Place non-nested parentheses around single operators in a digit-operator expression to make its value as large as possible.Medium7Dynamic programmingMath+1No attempts yet0.5s512 MBJudgeable
Back to the BonesGiven N rolled dice and a target K, reroll any subset once to maximize the chance the sum reaches K, and report 6^N times that probability together with one optimal subset.Medium7Dynamic programmingProbability+2No attempts yet1s256 MBJudgeable
Paper CutsSplit the source string into the fewest contiguous blocks that can be permuted to form the target word, and output that block count minus one as the cuts.Medium7Bit manipulationDynamic programming+1No attempts yet1s512 MBJudgeable
Hosting MTCount circular binary strings of length N, over all possible numbers of men from 0 to N, where no more than K men sit consecutively, modulo 10^8+7.Medium7CombinatoricsDynamic programming+2No attempts yet1s256 MBJudgeable
ImputationAssign A, T, C, or G in place of each '?' on tree leaves to minimize total transition costs along edges, summed over all string positions independently.Medium7Dynamic programmingTree+2No attempts yet2s512 MBJudgeable
Sum Source DetectionFor each queried sum X, find every open holder that appears in all valid subsets making X, where secret values must each be below the smallest open value.Medium7Dynamic programmingHash map+2No attempts yet2s512 MBJudgeable
Family PortraitInterleave a fixed women's order and fixed men's order into one line so the genders stay evenly spaced, minimizing the sum of squared height gaps between neighbors.Medium7Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Comfortable StringCount how many substrings of a bracket string are both correctly balanced and symmetric under reversal with bracket swap.Medium7Dynamic programmingString+2No attempts yet1s512 MBJudgeable
Tours de Sales ForceGiven d districts, each with 3 to 8 clients, first report the total length of every district's shortest tour, then the minimum total after pairing each fired district with a surviving one.Medium7Dynamic programmingBit manipulation+2No attempts yet15s512 MBJudgeable
Division GameStarting from a pile of N stones, players split a pile into k consecutive descending piles; find the smallest winning first split or -1.Medium7Game theoryDynamic programming+2No attempts yet1s512 MBJudgeable
Breaking Walls and Moving 3Find the shortest path from the top-left to the bottom-right of a grid, where up to K walls can be broken during daytime and day/night alternate with each move or wait.Medium7BFSGraph+2No attempts yet2s512 MBJudgeable
ExhibitionChoose the largest set of pictures and assign each to a distinct frame so that the sequence is nondecreasing in both assigned frame size and picture value.Medium7SortingGreedy+2No attempts yet1s512 MBJudgeable
Growing Vegetables is Fun 3Given a string of N characters R, G, Y, find the minimum number of adjacent swaps to arrange it so no two equal characters are adjacent, or report -1.Medium7Dynamic programmingGreedy+2No attempts yet0.5s1024 MBJudgeable
Subsequences in SubstringsCount how many substrings of s contain t as a subsequence at least once.Medium7Two pointersDynamic programming+2No attempts yet2s512 MBJudgeable
King of Pie, Kim PieChoose one box length x in [L,R] to minimize x times the number of boxes needed to pack pies of given lengths into consecutive groups, where a length-0 pie must sit alone.Medium7Dynamic programmingBinary search+2No attempts yet1s512 MBJudgeable
Why the Rabbit Came to Information IslandA rabbit moves right, up-right, or down-right through a grid with walls, carrots, and side gates; maximize carrots collected before exiting a side gate.Medium7Dynamic programmingImplementation+2No attempts yet1s256 MBJudgeable
Raider Choragi and Queries (Easy)Zones form a cycle; a squad covers one or two adjacent zones holding at most W prisoners. After each point update report the minimum number of squads covering all zones.Medium7Dynamic programmingGreedy+2No attempts yet1s256 MBJudgeable
Beauty and the GeekGiven a left/right path in a complete binary tree and exactly K flips of the meaning of left and right, sum the reachable leaf values in [A,B] modulo 1e9+7.Medium7CombinatoricsMath+2No attempts yet0.5s512 MBJudgeable
Beautiful BridgesPlace pillars at key points so every semicircular arch stays above the ground, minimizing pillar height plus squared span costs.Medium7Dynamic programmingGeometry+2No attempts yet10s512 MBJudgeable
Kaka and BebeFind a path from vertex 0 to N-1 whose total Kaka and total Bebe are each at most 1000, minimizing the product of the two totals.Medium7GraphShortest path+2No attempts yet2.5s512 MBJudgeable
Social NetworkFor every node v, sum over all ordered pairs s,t of the fraction of shortest paths between s and t that pass through v, and print each node's total.Medium7GraphShortest path+2No attempts yet1s256 MBJudgeable
Cash ExchangeGiven future daily prices of two vouchers and a fixed A-to-B buy ratio, find the most cash obtainable from S dollars after N days of buying and selling.Medium7Dynamic programmingMath+2No attempts yet1s256 MBJudgeable
Doom by Random DrawCount the perfect matchings on N labeled positions created by exactly N/2 disjoint swaps where every cup moves once, modulo 1e9+7.Medium7CombinatoricsMath+2No attempts yet1s512 MBJudgeable
Infinite BoosterOn an N by M grid of booster counts, move only right or down within the count of the cell you last stopped on, minimizing the number of stopping cells from (1,1) to (N,M).Medium7Dynamic programmingGraph+2No attempts yet1s512 MBJudgeable
Depressing VacationPlace N ordered appointments within M vacation days to minimize the total squared depression, where each idle day lowers the mood by 1.Medium7Dynamic programmingImplementation+2No attempts yet1s512 MBJudgeable
Longest Increasing Subsequence 6For a sequence of up to one million integers, report the length of the longest strictly increasing subsequence and the number of such subsequences modulo 1e9+7.Medium7Dynamic programmingBinary search+2No attempts yet2s512 MBJudgeable
Round Trips Between Cities 1Given N cities and P directed roads with no direct 1-to-2 road, find the maximum number of paths from city 1 to city 2 that share no road.Medium7GraphShortest path+2No attempts yet2s512 MBJudgeable
K-th Parenthesis StringFind the K-th valid balanced parenthesis string of length N in lexicographic order, or -1 if fewer than K+1 exist.Medium7Dynamic programmingCombinatorics+2No attempts yet0.25s512 MBJudgeable
Jinwoo's Moon Trip (Large)Find the cheapest path from any cell in the top row to any cell in the bottom row of an N x M grid, where no two consecutive moves may use the same direction.Medium7Dynamic programmingMatrix+2No attempts yet1s256 MBJudgeable
Hop GameStart in row 1 of an N x M grid and jump to later rows within Manhattan distance D, multiplying the two cells' values and adding to the score; maximize the total when reaching row N.Medium7Dynamic programmingImplementation+1No attempts yet1s256 MBJudgeable
InterplanetaryGiven a weighted graph of planets with temperatures, answer Q queries for the shortest path from A to B using only intermediate planets among the K coldest or K hottest.Medium7GraphShortest path+2No attempts yet1.5s512 MBJudgeable
Internet UploadGiven cafes with open hours and wifi speeds plus a travel-time matrix, find the earliest time by which all data can finish uploading from some starting cafe.Medium7Dynamic programmingShortest path+2No attempts yet1s512 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
NVWLSGiven a dictionary of words and a consonant-only message, reconstruct a sentence whose words concatenate to the message after vowels and spaces are removed, maximizing total vowels.Medium7Dynamic programmingString+2No attempts yet6s1024 MBJudgeable
Research Productivity IndexChoose any subset of n papers with known acceptance probabilities to maximize the expected value of a^a/s, where s is the subset size and a the number accepted.Medium7Dynamic programmingProbability+2No attempts yet1s1024 MBJudgeable
Change MakingGiven a coin system with c1 = 1, find the smallest target where greedy (always take the largest coin fitting) uses more coins than optimal, or report -1 if none up to 100000.Medium7Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
KoalaGiven houses on a line, a max jump length, and stamina costs, find the maximum stamina on arrival when each tutor house can be used once.Medium7Dynamic programmingGreedy+2No attempts yet2s256 MBJudgeable
Lucky DrawFor n players with k lives each flipping a biased coin every round, compute the probability the game ends in a draw.Medium7Dynamic programmingProbability+2No attempts yet2s512 MBJudgeable
Jammed GymGiven a required sequence of machine types and stations placed on a unit circle, find the minimum total walking distance to visit stations in that order.Medium7Dynamic programmingGeometry+2No attempts yet2s512 MBJudgeable
Low Effort LeagueGiven 2^r teams in a fixed knockout bracket, find the minimum total training hours so team 1 wins, where beating a stronger team costs the squared skill gap.Medium7Dynamic programmingTree+2No attempts yet3s512 MBJudgeable
SixpackFill empty cells of a 2-by-N grid so every three consecutive columns sum to K, then count the distinct valid solutions modulo 1e9+7.Medium7Dynamic programmingCombinatorics+1No attempts yet2s512 MBJudgeable
Big Company Seungbeom'sGiven a rooted tree of employees, pick a matching of edges where each node touches at most one chosen edge, maximizing the sum of products of endpoint skill values.Medium7TreeDynamic programming+2No attempts yet1s512 MBJudgeable
RGB JengaTwo players alternately draw red, green, or blue blocks of given weights; the first draw that pushes the total removed weight to at least N loses, and you must say which player wins with higher probability.Medium7Dynamic programmingProbability+2No attempts yet1s256 MBJudgeable
Bus RoutesCover every edge of a tree with the fewest simple paths, where each path visits distinct vertices in order along tree edges.Medium7TreeDFS+2No attempts yet1s512 MBJudgeable
How Many Unicycles in a Wheel?Count the number of spanning unicycles (spanning trees plus one edge forming a single cycle) in a wheel graph of size m, output modulo 100007.Medium7CombinatoricsGraph+2No attempts yet1s512 MBJudgeable
AssassinsGiven chronological assassination attempts with success probabilities, find the probability each of n assassins is alive at the end, where a dead assassin's attempts are cancelled.Medium7ProbabilityDynamic programming+2No attempts yet1s512 MBJudgeable
Mixing DrinksCount the ways to split the sequence 1..N into consecutive nonempty blocks so that no block contains both endpoints of any listed bad pair, modulo 1e9+7.Medium7Dynamic programmingTwo pointers+2No attempts yet1s512 MBJudgeable
TriangulationGiven a regular n-gon, find the smallest possible diameter over all triangulations, where the diameter is the largest number of triangle borders crossed between any two triangles.Medium7Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
Bus TicketGiven trip days in non-decreasing order, single-trip price s, and a ticket costing p that covers m days from purchase, find the minimum total cost.Medium7Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
Difficult Stair NumbersCount base-B numbers of length N whose adjacent digits differ by 1 and that use every digit 0 to B-1 at least once, modulo 1e9.Medium7Dynamic programmingBit manipulation+2No attempts yet0.5s512 MBJudgeable
Leverage MDTA boustrophedon path flips exactly one cell per row; choose a boustrophedon column cell so that flipping maximizes the largest all-good square.Medium7Dynamic programmingImplementation+2No attempts yet0.2s512 MBJudgeable
Final StandingsGiven each team's strength, each problem's difficulty, and a frozen scoreboard, compute the probability that team t ends up in first place, assuming ties always go to team t.Medium7ProbabilityDynamic programming+1No attempts yet2s512 MBJudgeable
High Load DatabaseSplit a fixed array of transaction sizes into the fewest consecutive batches, each with total at most t, answering many t values; report Impossible when some transaction exceeds t.Medium7Binary searchPrefix sum+2No attempts yet2s512 MBJudgeable
Just the Last DigitGiven the last digit of the number of paths from i to j for every pair i < j, recover the original directed acyclic graph of trails.Medium7GraphDynamic programming+2No attempts yet2s512 MBJudgeable
Chisam's Great AdventureGiven an undirected weighted graph, find the shortest closed walk from H to T and back where no vertex other than H repeats.Medium7GraphShortest path+2No attempts yet1s1024 MBJudgeable
Radio PrizeIn a weighted tree, for every city u output the sum of (t[u] + t[v]) * dist(u, v) over all other cities v.Medium7TreeDFS+2No attempts yet3s512 MBJudgeable
Dragon Ball IGiven a weighted undirected graph and seven target cities, find the minimum total cost of a walk starting at city 1 that visits all seven targets.Medium7GraphShortest path+2No attempts yet2s512 MBJudgeable
Parentheses EditorAfter each push of '(' or ')' or one backspace, print the number of balanced substrings in the current text.Medium7StackDynamic programming+2No attempts yet2s512 MBJudgeable
Visible LatticeCount lattice points in an N x N x N grid visible from the origin, meaning no other lattice point lies on the segment to them.Medium7MathNumber theory+2No attempts yet1s512 MBJudgeable
Moortal CowmbatRewrite a length-N string into streaks of at least K identical letters, where changing any single position from letter i to j costs a shortest-path distance over an M-letter graph; minimize total cost.Medium7Dynamic programmingShortest path+2No attempts yet1s512 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
Team Practice MoreCount assignments of N problems to three people where A's count is a multiple of K, B never solves two in a row, and C solves at least one, mod 1e9+7.Medium7Dynamic programmingCombinatorics+2No attempts yet1s512 MBJudgeable
Environment-Friendly TravelFind the minimum CO2 cost route from home to destination through a station network, staying within a total distance budget B.Medium7GraphShortest path+2No attempts yet3s512 MBJudgeable
Bird Migration MonitoringGiven a DAG where every vertex is reachable from 0 and reaches N-1, choose a vertex subset covering every source-to-sink path; cost is (count of chosen vertices) times the largest chosen price, with some vertices unmonitorable. Minimize the cost.Medium7GraphDynamic programming+2No attempts yet3s512 MBJudgeable
SpringboardsGiven up-and-right springboards that teleport Bessie from (x1,y1) to (x2,y2), find the minimum walking distance from (0,0) to (N,N).Medium7Dynamic programmingSorting+2No attempts yet2s512 MBJudgeable
Commute CircuitGiven a weighted undirected city graph, the office at node 0, and up to 10 employee homes, find the length of the shortest closed route that starts at the office, visits every home, and returns.Medium7GraphShortest path+2No attempts yet2s512 MBJudgeable
Best TreeGiven the degree sequence of a tree, find the maximum possible size of a maximum matching over all trees realizing that sequence.Medium7TreeGreedy+2No attempts yet1s512 MBJudgeable
Game Of ChanceFor each m, find the limit of the expected score difference in a two-player optimal-stopping game where the choice holder assigns a random number to themselves or the opponent.Medium7ProbabilityGame theory+2No attempts yet3s512 MBJudgeable
GurdurrGiven a stable Jenga tower of up to 20 layers, two players alternately remove one block while keeping the tower stable; decide who wins with optimal play.Medium7Game theoryDynamic programming+1No attempts yet5s512 MBJudgeable
The Minions QuizGiven A AND operators, B OR operators, and A+B+1 numbers, arrange the operators between the numbers, evaluating left to right, to maximize the result.Medium7Dynamic programmingBit manipulation+2No attempts yet2s512 MBJudgeable