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 results6,373 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Dropping BlocksGiven pile heights, decide whether prefix-wise operations (add 1 to a prefix or a suffix starting at k) can produce exactly that array, and say valid or invalid.Hard8GreedyMath+2No attempts yet2s512 MBJudgeable
Knights and DragonsGiven n distinct points (strength, magic), decide for each whether it lies in the convex hull of the others, since a point is reachable by repeated weighted averaging of the other points exactly when it is not a vertex of the hull.Hard8GeometrySorting+2No attempts yet4s512 MBJudgeable
Distance SumGiven a connected undirected unweighted graph with at most n+42 edges, compute the sum of shortest-path distances over all unordered vertex pairs.Hard8GraphBFS+2No attempts yet4s512 MBJudgeable
FractionsGiven n, represent 1 - 1/n as a sum of fractions with denominators dividing n and strictly between 1 and n, or report that no such sum exists.Hard8MathNumber theory+2No attempts yet2s512 MBJudgeable
King Kog's ReceptionKnights join or cancel reservations with a start time and duration; after each change, a query asks how long a visitor arriving at time t must wait, since she yields to a knight arriving at the same instant.Hard8Segment treeBinary search+2No attempts yet2s512 MBJudgeable
Shooter IslandOn a 50 by 100000 grid, rectangles flood when hit, and after each query decide whether a radius-0.31416 boat can sail between two given squares on the remaining water.Hard8Union-findIntervals+2No attempts yet3s512 MBJudgeable
Erasing MatrixDecide whether all cells of a grid can be driven to zero by repeatedly adding the same integer k to two adjacent cells while keeping every value non-negative, and print a valid sequence of at most 10^6 operations.Hard8GraphGreedy+2No attempts yet1s256 MBJudgeable
Nader ShahFrom roads and marked Afshari edges, reconstruct the root and capture order consistent with the growth rule, lexicographically minimum, or output Wrong Map!.Hard8GraphGreedy+2No attempts yet2s512 MBJudgeable
Python ClassesReorder single-inheritance class definitions so every superclass appears before its subclasses, using the fewest cut-and-paste moves, or output -1 when superclass links form a cycle.Hard8GreedyUnion-find+2No attempts yet2s512 MBJudgeable
Metal Bar CubeGiven the four viewing counts from left, right, top and bottom of an N by N grid, decide whether any placement of blocked cells can produce exactly those counts.Hard8GreedyImplementation+2No attempts yet1s512 MBJudgeable
Balance BeamChoose at each beam position a cash value or a fair coin random walk stopped at the ends, maximizing expected payment for every starting position.Hard8Dynamic programmingMath+2No attempts yet2s512 MBJudgeable
Trodden CablePlace a cable along grid edges connecting two given corners so that, over repeated fixed walks, staff cross it as few times as possible.Hard8Shortest pathGraph+2No attempts yet5s512 MBJudgeable
Endless BFSRun a BFS that forgets visited vertices, so the active set alternates between bipartition classes. Decide whether it ever equals all vertices and report the least step when it does.Hard8GraphBFS+2No attempts yet2s512 MBJudgeable
Librarian's WorkGiven a shuffled permutation with book weights, restore the original order using two adjacent-rotation-like moves and minimize total labor cost.Hard8GreedyDynamic programming+2No attempts yet5s512 MBJudgeable
Permutation PeriodStarting from the identity permutation, apply swaps one at a time and after each swap report the permutation's period modulo 1e9+7, where the period is the LCM of its cycle lengths.Hard8MathNumber theory+2No attempts yet5s512 MBJudgeable
Clique ColoringGiven up to five clique sizes, find the smallest number of vertices in a complete graph whose edges can be covered by cliques of those sizes with no repeated edge.Hard8CombinatoricsMath+2No attempts yet2s512 MBJudgeable
DifferenceBuild the sequence from A1 incrementally, adding each next gap so that m hits as a value or an existing difference; report the first step that covers it.Hard8SimulationMath+2No attempts yet2s512 MBJudgeable
Sequential YahtzeeGiven up to 195 sequential dice rolls, assign consecutive segments to the 13 Yahtzee categories in order to maximize the total score.Hard8Dynamic programmingPrefix sum+2No attempts yet2s512 MBJudgeable
Knight GameTwo players alternately place non-attacking knights on an N x N board; decide who wins under optimal play, with N up to 10,000.Hard8Game theoryMath+2No attempts yet1s512 MBJudgeable
Distinct Substring Queries 2Process a stream of append-character and count-distinct-substrings queries on a growing string, answering each count query online.Hard8StringString matching+2No attempts yet1s512 MBJudgeable
String FoldingFold the string at a sequence of positions into vertical columns, then find the longest column-run of one repeated character that starts at the bottom with no gaps.Hard8StringBrute force+2No attempts yet2s512 MBJudgeable
Number of Integer Lattice PointsCount pairs of lattice points in a grid whose connecting segment contains exactly K lattice points.Hard8MathNumber theory+2No attempts yet2s512 MBJudgeable
MaaaaaaaaazeGiven five 5x5 boards, rotate each freely, stack them in any order, then find the shortest path through the resulting 5x5x5 cube from one corner to the opposite corner.Hard8Brute forceBFS+2No attempts yet2s512 MBJudgeable
Rope and QueriesMaintain a string under up to 100,000 queries that cut a substring and move it to the front or back, and print single characters.Hard8Linked listImplementation+2No attempts yet0.3s512 MBJudgeable
3-SAT 2Given a 3-CNF formula with N variables and M clauses, decide whether it is satisfiable and, if so, output a satisfying assignment.Hard8GraphDFS+2No attempts yet2s512 MBJudgeable
Artifact RestorationGiven a grid with some unknown cells, fill unknowns with 0 or 1 so that the total number of people summed over all subrectangles is divisible by K.Hard8MathNumber theory+2No attempts yet1s512 MBJudgeable
Broken DataDelete some integers from a sequence so the rest reads as N M U1 V1 ... UM VM with 1 <= Ui,Vi <= N; among all valid restorations, maximize N, then M.Hard8ImplementationGreedy+2No attempts yet1s512 MBJudgeable
Truth TellersGiven N people each stating a range for the number of truth tellers, find the maximum consistent truth-teller count after each of Q point updates.Hard8ArraySegment tree+2No attempts yet3.5s256 MBJudgeable
SEGWAYSimulate N riders over a 300 m track with three speed sections and accelerators granting 1 s/m boost for X mod 20 meters, where X counts riders strictly ahead, and print each finish time.Hard8SimulationImplementation+2No attempts yet1s512 MBJudgeable
Whiskey TradeModel the distribution network as a flow graph with node capacities and compute the maximum flow from Myeongjin to Jueun.Hard8GraphShortest path+2No attempts yet1s256 MBJudgeable
Overflowing PopularityGiven M guests with arrival and departure times, choose when to insert up to K extra friends so that the count of ordinary attendees stays below T as long as possible.Hard8Dynamic programmingGreedy+2No attempts yet1s256 MBJudgeable
The Valley OverflowsGiven a tree of valleys with heights, decide whether water starting from any non-K valley can reach valley K under the splash-up movement rule.Hard8TreeDFS+2No attempts yet1s512 MBJudgeable
Card Factory (Large)Each of N cards shows its front initially; given M queries K that flip every card whose visible number is at most K, report the final visible sum.Hard8SortingBinary search+2No attempts yet3s256 MBJudgeable
Making Everything WhiteGiven an N by M black/white grid, choose for each cell one of three local color-inversion actions so that every cell ends up white, or report impossibility.Hard8GreedyImplementation+2No attempts yet1s512 MBJudgeable
Superb DartGiven a planar straight-line graph, list the areas of its bounded faces in increasing order, rounded to two decimals.Hard8GeometryGraph+2No attempts yet1s512 MBJudgeable
Random Number GeneratorSimulate a quadratic-polynomial generator to build a grid, then find the path from top-left to bottom-right whose sorted values are lexicographically smallest.Hard8SimulationGreedy+2No attempts yet3s256 MBJudgeable
Plants vs. ZombiesGiven a grid of plants, each with a score and an attack range, zombies enter from the right and can eat a plant only after clearing the plants to its right, but eating a plant that any surviving plant covers is fatal; maximize total score.Hard8GraphTopological sort+2No attempts yet1s512 MBJudgeable
Pipe MarblesGiven two binary strings as stacks, count the sum of squares of the number of interleavings producing each distinct output string, modulo 1024523.Hard8Dynamic programmingString+2No attempts yet1s512 MBJudgeable
Masquerade PartyGiven directed visibility edges between masks, find the maximum and minimum possible number of mask types k (at least 3) consistent with the observations.Hard8GraphUnion-find+2No attempts yet1s256 MBJudgeable
Sequence and Queries 24Maintain an array under point updates and range queries that ask for the largest sum of two distinct elements within a subarray.Hard8Segment treeDynamic programming+2No attempts yet1s512 MBJudgeable
Overflowing Gift CardsGiven each card's days until expiry and the day he plans to use it, find the fewest 30-day extensions so every card is still valid when used, under a rule that he must always use the card closest to expiry.Hard8GreedySorting+2No attempts yet1s512 MBJudgeable
Overflowing BanknotesFor each query, after updating one node, find the maximum banknotes that can be gathered at one safe when any node is chosen as root and the coins fall optimally.Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
Function Composition and QueriesGiven a function f on 1..m, answer queries n, x by returning the value of the n-fold composition f^n(x).Hard8Binary searchGraph+2No attempts yet1s512 MBJudgeable
kdh9949Find the longest path in an undirected graph whose vertex labels spell repeated KDH blocks, or report -1 if such a path can be infinite.Hard8GraphDynamic programming+2No attempts yet1s1024 MBJudgeable
Tree Colors and QueriesA rooted tree where edges are deleted over time; after each deletion, count distinct colors among vertices still reachable from a queried vertex.Hard8DFSTree+2No attempts yet2s256 MBJudgeable
Building Bridges 2On a small grid, connect all islands with straight length-2+ bridges over sea so the total bridge length is minimized, or print -1.Hard8GraphMinimum spanning tree+2No attempts yet1s512 MBJudgeable
Sequence and Queries 25Maintain an array under range bitwise AND, range bitwise OR, and range maximum queries, each value below 2^20.Hard8Segment treeBit manipulation+2No attempts yet2s512 MBJudgeable
Sequence and Queries 28Maintain an array under range add, range floor-sqrt, and range sum queries, and report each range sum.Hard8Segment treeMath+2No attempts yet1s512 MBJudgeable
BorderGiven an N by N grid of species (N at most 4), find a non-self-crossing border path from the top-left to the bottom-right corner so that different species end up in separate regions, or report that none exists.Hard8GraphBrute force+2No attempts yet1s256 MBJudgeable
Hilbert's HotelSimulate Hilbert's Hotel as guests arrive in finite or infinite groups, and answer which group occupies a room or which room holds a given index of a group.Hard8MathImplementation+2No attempts yet1.5s1024 MBJudgeable
Lexicographically Minimum WalkFind the lexicographically smallest color sequence among all walks from S to T of length at most 10^100, reporting IMPOSSIBLE or TOO LONG when needed.Hard8GraphGreedy+2No attempts yet2s1024 MBJudgeable
All You Need is DatingGiven bipartite preferences and per-student min/max date counts, find the maximum number of dates satisfying all lower and upper bounds, or -1.Hard8GraphDynamic programming+2No attempts yet1s512 MBJudgeable
Dishonest DriverGiven a string of N characters, find the size of the shortest compressed form built from single characters, concatenation, and repetition (C repeated k times).Hard8Dynamic programmingString+2No attempts yet6s512 MBJudgeable
Running RoutesGiven chords of a convex n-gon, find the largest set of chords no two of which share any common point, including endpoints.Hard8Dynamic programmingIntervals+2No attempts yet12s1024 MBJudgeable
Sequence and Queries 31Maintain a 0/1 sequence under range reversals, and answer queries for the longest run of 1s inside a given range.Hard8Segment treeIntervals+2No attempts yet2s512 MBJudgeable
DroneA drone moves on an N x N tile maze with walls; LED tiles light up in sequence order as the drone steps on them, and we need the shortest total travel time to display the whole sequence and exit.Hard8BFSShortest path+2No attempts yet1s512 MBJudgeable
Strange MachineCount the distinct pairs (x, y) produced by the map t -> (((t + floor(t/B)) mod A), t mod B) over n disjoint time intervals.Hard8MathNumber theory+2No attempts yet4s512 MBJudgeable
SeparatorAppend values one at a time to a growing sequence and after each append report how many indices are separators, meaning every earlier element is smaller and every later element is larger.Hard8TreeImplementation+2No attempts yet1.2s512 MBJudgeable
NamuhsGiven N unknown planet potentials, find the unique contiguous segment with the maximum sum using only queries that compare the sums of two segments.Hard8Divide and conquerBinary search+2No attempts yet2s512 MBJudgeable
ResistancePlayers leave and return over time; after each change report the maximum value of a split into two teams, where friendship edges crossing the split are lost.Hard8GraphMinimum spanning tree+2No attempts yet2s512 MBJudgeable
Cake 3Choose M of N slices and arrange them in a cycle to maximize total value minus the sum of absolute color-depth differences around the cycle.Hard8Dynamic programmingGreedy+2No attempts yet4s256 MBJudgeable
MineralsGiven 2N slices forming N unknown pairs, determine all pairs using at most 1,000,000 device operations that report the number of distinct mineral kinds currently inserted.Hard8Divide and conquerImplementation+2No attempts yet1s256 MBJudgeable
TentsCount nonempty subsets of tents on an H by W grid with directions obeying monotone entrance rules in every row and column, modulo 1e9+7.Hard8CombinatoricsDynamic programming+2No attempts yet2s512 MBJudgeable
LibraryGiven a hidden permutation of N books, query the oracle with a set of book numbers and receive the minimum number of contiguous-block removals needed to extract exactly those books, then recover the order.Hard8IntervalsMath+2No attempts yet2s512 MBJudgeable
Copy and Paste 2Simulate N copy-and-paste edits on a string capped at length M, tracking positions backward so the first K characters of the final string can be printed.Hard8ImplementationBinary search+2No attempts yet1s512 MBJudgeable
Making Friends is FunGiven a directed graph of ambassador arrows, repeatedly pick a mediator x and two countries p,q with arrows (x,p) and (x,q), then add (p,q) and (q,p); maximize final arrow count.Hard8GraphUnion-find+2No attempts yet1s512 MBJudgeable
Collecting Images is FunStart with an all-white 2^N by 2^N grid; after each of Q row or column flips, report the size of the quadtree that represents the image.Hard8Divide and conquerImplementation+2No attempts yet5s256 MBJudgeable
MascotsCount the orders of placing the remaining mascots so that the number of steps where the occupied cells form a full rectangle is maximized, modulo 1e9+7.Hard8CombinatoricsDynamic programming+2No attempts yet2s256 MBJudgeable
ChampionshipsFind the largest set of vertices in an undirected graph that is connected and where every vertex has at least d neighbors inside the set.Hard8GraphImplementation+2No attempts yet2s512 MBJudgeable
JOI FlagFill and fix a 2^K by 2^K grid so it follows the recursive quadrant rule for JOI flags, minimizing the number of already-written cells whose character must change.Hard8Divide and conquerDynamic programming+2No attempts yet3s512 MBJudgeable
Estate AgentGiven directed offers between families with amounts, pick a subset of disjoint cycles so the total sum of offer amounts is maximized, then output 5% of it.Hard8GraphDynamic programming+2No attempts yet2s512 MBJudgeable
Grand Central StationGiven a tree, find the minimum number of distinct map designs (rooted drawings) such that every vertex can be the center of one design after relabeling.Hard8TreeDFS+2No attempts yet2s512 MBJudgeable
Hat StandPlace c-1 spare hats on hooks so the total walking distance over a given sequence of n hats is minimized, then output the best arrangement.Hard8GreedyDynamic programming+2No attempts yet2s512 MBJudgeable
Dice YutnoriGiven 10 die rolls, move one of four pieces around a branching Yutnori board each turn and maximize the score collected from numbered squares.Hard8BacktrackingSimulation+2No attempts yet2s512 MBJudgeable
Lion and RabbitCount the ordered pairs of distinct vertices in a connected undirected graph for which the lion can never catch the rabbit under simultaneous blind moves.Hard8GraphBFS+2No attempts yet1s256 MBJudgeable
Cheese, If You PleaseGiven limited pounds of n cheese types and m blends with fixed percentage recipes and per-pound profits, find the maximum achievable profit and round it to the nearest cent.Hard8MathGreedy+2No attempts yet2s512 MBJudgeable
Just Passing ThroughGrid path from the west edge to the east edge moving east, northeast, or southeast, crossing exactly n passes, minimizing total elevation.Hard8Dynamic programmingMatrix+2No attempts yet2s512 MBJudgeable
Where Have You Bin?Given a row of bins labeled by company, delete the listed bins, add the requested new bins, and find the minimum total item cost to keep every company's bins contiguous.Hard8Dynamic programmingImplementation+2No attempts yet1s512 MBJudgeable
Integers in Rational BasesGiven coprime p and q, write a positive integer n in the unique base p/q expansion whose digits are all at most p-1, printing digits 0-9, A-Z, a-z.Hard8Number theoryMath+2No attempts yet1s512 MBJudgeable
HogwartsGiven two edge-labelled 4-out graphs on n rooms, decide whether every instruction sequence that walks from room 1 to room n in the old graph also walks from 1 to n in the new graph.Hard8GraphBFS+2No attempts yet1s512 MBJudgeable
MoleculesGiven a connected graph with some vertex positions fixed, find positions for the rest so each unknown vertex sits at the average of its neighbors; any valid solution is accepted.Hard8GraphMath+2No attempts yet2s512 MBJudgeable
Pairing SocksGiven a sequence of 2n socks, find the minimum number of moves to pair all socks using two stacks with three allowed operations, or report impossible.Hard8StackGreedy+2No attempts yet1s512 MBJudgeable
Tree HuggingGiven 2(n-1) edges on n points, decide whether they can be split into a left-rooted increasing tree and a right-rooted decreasing tree, and output one such labeling.Hard8GraphGreedy+2No attempts yet2s512 MBJudgeable
Counting Permutations with a Given Greedily Increasing SubsequenceCount the permutations of 1 to N whose greedily increasing subsequence equals a given sequence G, modulo 1e9+7.Hard8CombinatoricsMath+2No attempts yet1s512 MBJudgeable
Ranch CCTVFor each query, sheep in a grid shift one cell per day in a fixed direction for K days; report the XOR of the daily maximum over the CCTV rectangle.Hard8Prefix sumMatrix+2No attempts yet2s256 MBJudgeable
Max or MinGiven numbers on a circle and min/max operations over a value and its two neighbors, find for each x the least minutes to make all values equal x, or -1.Hard8ImplementationGreedy+2No attempts yet1s256 MBJudgeable
EquilibriumGiven a tree, order its vertices to minimize the sum over vertices of the absolute difference between neighbors placed after and before them.Hard8TreeDFS+2No attempts yet1s512 MBJudgeable
Computer CacheMaintain a mutable byte array over m pieces, support range increments modulo 256 on a piece, cache loads of whole pieces into fixed cache positions, and point queries of cache bytes.Hard8Segment treeArray+2No attempts yet5s512 MBJudgeable
Glow, Pixel, Glow!Given horizontal and vertical pulses crossing a grid of wires, count the pixels where current passes through both intersecting wires at the same time.Hard8SortingImplementation+2No attempts yet2s512 MBJudgeable
Cocoa CoalitionBreak an n by m chocolate bar with straight-line cuts into pieces that can be grouped into one pile of a cells and one of b cells, minimizing the number of cuts.Hard8Dynamic programmingGreedy+2No attempts yet1s512 MBJudgeable
Cut Inequality DownFor many range queries [B,E] and starting wealth X, simulate monthly income with wealth clamped into [L,U] after each month and report the final wealth.Hard8Segment treeImplementation+2No attempts yet0.7s512 MBJudgeable
Dazzling StarsGiven N stars with coordinates and brightness, decide whether some rotation of the picture makes brighter stars print no later than dimmer ones, where printing goes top to bottom.Hard8GeometrySorting+2No attempts yet0.2s512 MBJudgeable
Game of Falling BlocksSimulate a simplified Tetris game that uses bag randomization of the seven tetrominoes, and decide for each piece where to place it to complete at least one row before the game is lost.Hard8SimulationGreedy+2No attempts yet1s512 MBJudgeable
PopcountGiven N and K, produce a MalnarScript program of at most K commands that computes the popcount of an N-bit input using one variable.Hard8Bit manipulationDivide and conquer+2No attempts yet1s512 MBJudgeable
Great Farmer Kim SanghyukChoose a radius r to maximize the daily profit from crops inside the circle (each worth wi times its distance to the boundary) minus the management cost A*r^2.Hard8GeometryMath+2No attempts yet2s1024 MBJudgeable
Optimal SelectionGiven n <= 8 numbers and some known pairwise order relations, find the worst-case minimum number of comparisons an optimal comparison-based algorithm needs to output the k-th smallest.Hard8Divide and conquerGame theory+2No attempts yet8s1024 MBJudgeable
True/False WorksheetCount binary strings of length n that satisfy range hints, where each hint says a range is all equal or not all equal, modulo 1e9+7.Hard8Dynamic programmingPrefix sum+2No attempts yet2s512 MBJudgeable
Sink the Billiard BallA point ball bounces off the edges of an A by B table with velocity (p,q); count edge hits until it reaches a corner, or print -1 if it never stops.Hard8MathNumber theory+2No attempts yet1s256 MBJudgeable
Who Has Not Read the Message?Given each message's sender and the count of people who had not read it, count the possible sets of unread people per message, modulo 1e9+7.Hard8CombinatoricsDynamic programming+2No attempts yet1s256 MBJudgeable
Water Tanks of Seongdae CountryA tree of water tanks rooted at a capital. Adding water at city A adds 1,2,3,... along the root-to-A path. Answer queries about how much water a given city currently holds.Hard8TreeDFS+2No attempts yet1s256 MBJudgeable