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,390 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
The Byteotian WarBoth players take turns discarding one of their top two cards and passing the other to the opponent; find the final score when both play optimally.Hard8Dynamic programmingGame theory+2No attempts yet1s128 MBJudgeable
ScissorsGiven a rectilinear simple polygon, find the minimum number of drawn segments (each with endpoints on the boundary and interior inside) so that cutting along them makes every piece a rectangle.Hard8GeometryGraph+2No attempts yet1s128 MBJudgeable
FosaGiven horizontal and vertical segments, find the largest axis-aligned square whose entire perimeter lies on those segments, or report that none exists.Hard8GeometrySorting+1No attempts yet1s128 MBJudgeable
TransformationsGiven two binary strings of length n, decide whether disjoint ab and ba fragments can be swapped repeatedly to turn the first string into the second.Hard8StringMath+2No attempts yet1s128 MBJudgeable
Pedestrian CrossingDecide whether a shoe of length s, stepping by k, can cross stripes of given widths while never overlapping a white stripe.Hard8MathNumber theory+2No attempts yet1s128 MBJudgeable
PlotterGiven the recursively defined order-n bytecurve and m integer points, report how many times and at which seconds the pen visits each point.Hard8RecursionDivide and conquer+2No attempts yet5s128 MBJudgeable
Laser PoolA ball bounces elastically around a grid of lit horizontal and vertical laser beams; count how many distinct lit beams it touches during t time units, including the start.Hard8MathSimulation+2No attempts yet5s256 MBJudgeable
The Shortest PeriodDelete exactly one letter from a string to minimize the length of the shortest period of the resulting word.Hard8StringString matching+2No attempts yet5s128 MBJudgeable
MushroomsA walker starts at glade 1, moves one glade every 15 minutes for t moves, picks all mushrooms on arrival, and each glade regrows 30 minutes later; maximize the total harvest.Hard8Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Byteball MatchGiven partial results of a round-robin group, list every team that can still finish first once all remaining matches are played, under points and goal-difference tiebreaks.Hard8GraphBrute force+2No attempts yet2s512 MBJudgeable
StampsDecide whether a two-cell 3x3 stamp (domino in a row or column) plus an s x s all-inside stamp can turn an all-white k x k board into a given black-cell pattern.Hard8MathGreedy+2No attempts yet1s128 MBJudgeable
PermutationsCount completions of a partial permutation on 2n points that is an involution and encodes a correct bracket sequence.Hard8CombinatoricsDynamic programming+2No attempts yet2s512 MBJudgeable
TramFor each junction, find the greatest common divisor of all cycle lengths reachable from and returning to it, or -1 if no return is possible.Hard8GraphDFS+2No attempts yet2s512 MBJudgeable
Paper ClipsFind the minimum number of 180-degree turns needed to separate a chain of clips joined in two possible ways, where clips sit in four orientations.Hard8GreedyDynamic programming+1No attempts yet1s128 MBJudgeable
Idempotent FunctionsGiven f on {1..n}, count pairs (g, h) with g a permutation and h idempotent such that f = h composed with g, modulo 1e9+7.Hard8CombinatoricsMath+2No attempts yet1s128 MBJudgeable
Conference - RectificationChoose a subset of whole reservations to keep so that total income from ticket sales minus room rent is maximized.Hard8Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
CloudsGiven disjoint simple polygons and a fixed wind direction, place a point so the number of polygons that cross the vertical ray above it at some time is maximized.Hard8GeometrySorting+2No attempts yet1s128 MBJudgeable
Almost ConjugatesDecide whether two length-n words are almost conjugates and, if so, list every rotation of the first that differs from the second in exactly one position.Hard8StringString matching+2No attempts yet1s128 MBJudgeable
CrayfishFor each house, count how many turtles are reachable on a round trip that starts and ends moving backward, where special edges flip the direction of travel.Hard8GraphDFS+2No attempts yet1s128 MBJudgeable
Sum of PolygonsAdd two convex polygons by Minkowski sum and print twice the area of the resulting polygon.Hard8GeometryTwo pointers+2No attempts yet1s128 MBJudgeable
Holey ChessboardGiven a K by W board with holes, drill the most hole-free cells while keeping the permanent (count of non-attacking rook placements) unchanged.Hard8CombinatoricsGraph+2No attempts yet1s128 MBJudgeable
Courier ServicesFind all Pareto-optimal (cost, time) pairs among routes from a class-C source to a class-C destination in a network with a special office-class structure and cycles.Hard8GraphShortest path+2No attempts yet1s128 MBJudgeable
Jasiek's DrawingGiven a counter-clockwise walk around a polyomino's border cells, count the total number of blackened cells in the drawing.Hard8GeometryImplementation+1No attempts yet1s128 MBJudgeable
Gordian DancesGiven a sequence of S (string swap) and R (quarter-turn) moves, find the minimum number of further moves that returns the dance to a horizontal, parallel, untangled state.Hard8MathString+2No attempts yet1s128 MBJudgeable
Bachelor PartyGiven a tree and one-way tickets, decide if a vertex-simple walk from s to t uses every ticket exactly once.Hard8GraphDFS+1No attempts yet1s128 MBJudgeable
KeyboardA 1x2 domino slides around a grid through the single uncovered cell; find the fewest moves to uncover every vowel cell at least once.Hard8GraphBFS+2No attempts yet1s128 MBJudgeable
GodzillaEach day Godzilla starts at junction 1, walks a path, eats a building and destroys buildings on the way; each night one person leaves every standing building. Maximize the total eaten.Hard8GraphGreedy+2No attempts yet1s128 MBJudgeable
VirusesGiven up to 24 virus sources with distinct daily hours, determine how many cells each one ends up occupying on an n by n board.Hard8GeometryBFS+2No attempts yet1s128 MBJudgeable
MapsGiven up to a million arbitrarily rotated rectangles, find the number of edges of their common intersection polygon.Hard8GeometryImplementation+2No attempts yet1s128 MBJudgeable
JEvaluate a J-style vector expression over up to 100000 entries using low-degree polynomials per component and output the scalar result modulo 10^9.Hard8MathImplementationNo attempts yet2s256 MBJudgeable
Intuitionistic LogicGiven a DAG and its antichain algebra, test each formula over all variable assignments and report valid or invalid.Hard8Brute forceGraph+2No attempts yet2s128 MBJudgeable
Manifest DestinySimulate turn-by-turn movement, eating, combat, and starvation on a grid, and report each group's size, position, and death year.Hard8SimulationImplementation+2No attempts yet1s128 MBJudgeable
SnakeReconstruct the Hamiltonian path numbering of a 3 by n board from some given cell numbers.Hard8BacktrackingGraph+1No attempts yet3s512 MBJudgeable
The kingdomFollow the fixed DFS, vertex-split, and Euler-circuit steps to output edge-disjoint even-length trails pairing every odd-degree vertex.Hard8GraphDFS+2No attempts yet1s256 MBJudgeable
SaveitDesign encode and decode procedures that compress the all-pairs hub distances of a connected graph into a short bitstream, with decode reconstructing every hub-to-city hop count.Hard8GraphBFS+2No attempts yet2s256 MBJudgeable
Who Do You Think You Are?Read a family tree and answer queries naming the relationship of name1 to name2, including blood, cousin, and in-law terms.Hard8GraphTree+2No attempts yet2s256 MBJudgeable
Watering the fieldsCover every non-scarecrow cell with trominoes of three cells while letting at most R times C trominoes cross field borders.Hard8ImplementationBacktracking+1No attempts yet1s128 MBJudgeable
Yut Nori (Large)You receive every throw in order and the pieces left on the board, and you decide whether the game rules can produce that board.Hard8BacktrackingSimulation+1No attempts yet10s512 MBJudgeable
Polygraph (Large)Each of N people is a truth-teller or a liar; given their statements about who shares which city, mark each person as forced Truthtown, forced Liarville, or undetermined.Hard8Union-findGraph+1No attempts yet5s512 MBJudgeable
MarblesGiven 2n marbles of n colors in a row, find the minimum height of non-crossing paths pairing each color, or -1 if impossible.Hard8Dynamic programmingImplementation+1No attempts yet5s512 MBJudgeable
Two Lights in a Square RoomGiven two point lights and up to 50 circular pillars inside a square, find the area lit by neither, by red only, by green only, and by both.Hard8GeometryImplementation+2No attempts yet40s512 MBJudgeable
EZ-Sokoban (Small)Move at most three magnetized boxes on a grid to their goal cells with the fewest pushes, where boxes must stay connected except for at most one push.Hard8BFSSimulation+2No attempts yet5s512 MBJudgeable
Painting a Fence (Large)Pick the fewest offers from N interval-and-color proposals so every one of 10000 fence sections is covered using at most 3 distinct colors.Hard8IntervalsGreedy+2No attempts yet10s512 MBJudgeable
Apocalypse Soon (Large)On a grid of nations attacking their strongest living neighbor each day, choose your own attacks to maximize how many days your nation survives.Hard8SimulationGreedy+2No attempts yet5s512 MBJudgeable
How Big Are the Pockets? (Large)A run-length-encoded turtle walk traces a simple closed lattice polygon; compute the total area of all points outside it that have boundary both east and west or both north and south.Hard8GeometrySimulation+2No attempts yet5s512 MBJudgeable
PortalFind the fewest moves to reach the cake in a walled grid, where firing a portal gun at walls (free of move cost) lets you teleport between two portal openings.Hard8BFSGraph+2No attempts yet5s512 MBJudgeable
Minimum transmitter powerPlace a flagship in 3D so the maximum weighted Manhattan distance to N ships is minimized, and report that minimum power rounded to six decimals.Hard8GeometryBinary search+2No attempts yet5s512 MBJudgeable
Fly Swatter (Small)Compute the probability that a randomly placed fly disk touches a circular ring crossed by a grid of cylindrical strings, and print it to six decimals.Hard8GeometryMath+2No attempts yet5s512 MBJudgeable
Fly Swatter (Large)Given the racquet geometry, compute the probability that a fly of radius f, centered uniformly in the outer circle, overlaps the ring or any string.Hard8GeometryMath+2No attempts yet20s512 MBJudgeable
BossesBuild a rooted tree on n employees where each node's parent is one of its accepted bosses, then assign minimum positive salaries with every boss exceeding the sum of children.Hard8TreeDynamic programming+2No attempts yet1.5s256 MBJudgeable
Spiral Rectangle SumsIn a counterclockwise spiral of numbers on a (2n+1)x(2n+1) grid centered at 1, answer q queries for the sum inside an axis-aligned rectangle modulo 1e9+7.Hard8MathImplementation+2No attempts yet1.5s256 MBJudgeable
HyperwaysAfter each edge is added to a multigraph, report how many edges became safe, where an edge is safe when it lies on a cycle.Hard8Union-findGraph+2No attempts yet3s1024 MBJudgeable
Next 3-1-2 pattern avoiding permutationGiven a 3-1-2-avoiding permutation of 1 to n, print the next one in lexicographic order.Hard8CombinatoricsGreedy+1No attempts yet0.1s32 MBJudgeable
Hongjun Loves PaintingBricks start with color equal to their index and colorfulness 0; range paint operations add the absolute color change to each brick, and queries ask for the total colorfulness over a range.Hard8Segment treeImplementation+2No attempts yet2s512 MBJudgeable
Finding an integerFind the smallest integer at least N whose decimal digits contain d1 at least c1 times and d2 at least c2 times.Hard8GreedyImplementation+2No attempts yet2s512 MBJudgeable
Maximum substring costGiven a string T, find the maximum of length times number of occurrences over all substrings S of T.Hard8StringSorting+2No attempts yet2s512 MBJudgeable
Block PuzzleOn an N by N grid, roll a 1x1x2 block from any start cell to the goal without falling into holes; find the fewest cells to dig into holes so the goal becomes unreachable.Hard8BFSGraph+2No attempts yet2s512 MBJudgeable
Array GCDDelete one contiguous block and change at most one element by 1 each, so the remaining array has gcd greater than 1, at minimum cost.Hard8Number theoryGreedy+2No attempts yet2s512 MBJudgeable
Points on a CircleGiven n random points on a unit circle and an angle p, compute -log2 of the probability that all n points fit inside some arc of central angle p.Hard8ProbabilityMath+2No attempts yet2s512 MBJudgeable
Fewest letters for a suffix arrayGiven a permutation that is a suffix array, find the minimum number of distinct letters needed for a string that realizes exactly this suffix array.Hard8StringGreedy+2No attempts yet2s512 MBJudgeable
Minho's WishFor each of Q range queries on an array, count how many distinct values occur at least three times within the queried index range.Hard8Segment treePrefix sum+2No attempts yet2s512 MBJudgeable
BarbariansA tree's edges are deleted one by one, each deletion multiplies each vertex's anger by (reachable before) - (reachable after) + 1, and after each deletion the total anger is printed modulo 1e9+7.Hard8TreeUnion-find+2No attempts yet4s512 MBJudgeable
Containers and ReagentsDecide whether all reagents can be fully distributed among containers so each container's volume range and one reagent's minimum percentage are met.Hard8GreedyMath+2No attempts yet2s512 MBJudgeable
Elimination Round, Problem FGiven positive a_i and d, decide whether nonzero x_i exist with sum a_i x_i = d, and if so build the unique sequence defined by the greedy rule minimizing each |D_i|.Hard8Number theoryGreedy+2No attempts yet2s512 MBJudgeable
New Adventure of Marty and DocPlace a recycling plant on one grid cell so a robot carries every part to it with the fewest moves, picking up and dropping one part at a time.Hard8MathPrefix sum+2No attempts yet2s512 MBJudgeable
WhiteboardGiven a path on a grid and a target pattern, find the smallest and largest drying timestep T so the final board matches the target.Hard8SimulationImplementation+2No attempts yet5s512 MBJudgeable
FenceGiven points on grid corners, find the shortest closed fence along cell edges and diagonals that encloses all of them, output as a + b*sqrt(2).Hard8GeometrySorting+1No attempts yet2s512 MBJudgeable
Shortest BridgeGiven two polygonal riverbanks and points s and t on opposite sides, minimize the bridge length between the banks, then the road lengths from s and t to its endpoints.Hard8GeometryBrute force+2No attempts yet5s512 MBJudgeable
Unknown SwitchesGiven switch-operation patterns and resulting bulb states over Q steps, determine which of N switches controls each bulb, or mark it unknown. Standard whiteboard task? No.Hard8Bit manipulationMath+2No attempts yet8s512 MBJudgeable
Scorpion Test for Permutation GraphsAfter each swap in a permutation A, decide whether the permutation graph (edges between crossing chords) is scorpion-like.Hard8GraphSorting+2No attempts yet1s256 MBJudgeable
Router 2Build a unique-path layered router digraph with N inputs and N outputs, at most M_lim edges, node power at most P_lim, printing the lexicographically smallest edge list.Hard8GraphGreedy+2No attempts yet2s512 MBJudgeable
Counting rectangles by distinct numbersCount rectangles of every size by how many distinct numbers they contain, then output a product of those counts modulo 1e9+7.Hard8ImplementationBit manipulation+2No attempts yet3s256 MBJudgeable
Dots and BoxesGiven a Dots and Boxes position with no completed square, find the longest sequence of moves that still avoids closing any square, then print that length plus one.Hard8GraphDynamic programming+2No attempts yet2s512 MBJudgeable
Free DessertsCount pairs a, b with a < b, a + b = P, and no decimal digit repeats across a, b, and P, listing up to 5000 of them.Hard8Bit manipulationBrute force+2No attempts yet2s512 MBJudgeable
PrimonimoFind counts of row/column increments mod prime p that turn all squares into p, choosing the lexicographically smallest solution.Hard8MathNumber theory+2No attempts yet2s512 MBJudgeable
TreeAfter each query asks whether two vertices are still connected, the tree may lose one edge based on the answer, so connectivity must be tracked under online deletions.Hard8TreeUnion-find+2No attempts yet2s512 MBJudgeable
Magic Towers and TeleportationDecide whether repeatedly reflecting the whole set of points across three fixed towers can turn one given point multiset into another, with soldiers considered indistinguishable.Hard8GeometryMath+2No attempts yet2s512 MBJudgeable
Rock BandEach of M members ranks all S songs; a set list is valid if every member plays all songs they rank above any chosen song. Find a shortest valid set list.Hard8GreedySorting+2No attempts yet4s512 MBJudgeable
ArtworkPaint horizontal and vertical black strokes on a grid one at a time, and after each stroke report the number of white connected regions.Hard8Union-findImplementation+2No attempts yet4s512 MBJudgeable
InterceptionPlace the fewest listening devices on the edges of a street-wide phone-line graph so that every given call route is covered.Hard8GraphGreedy+2No attempts yet8s512 MBJudgeable
Keeping the Dogs ApartTwo dogs follow their own polyline routes at the same constant speed; find the minimum distance between them while both are still walking.Hard8GeometryTwo pointers+2No attempts yet6s512 MBJudgeable
Placing Medals on a Binary TreeGiven medals with depths in a pile, decide greedily and incrementally which can be placed on a perfect binary tree so that no placed node is an ancestor of another.Hard8GreedyTree+1No attempts yet4s512 MBJudgeable
Cover the Polygon with Your DiskPlace a fixed-radius disk anywhere on the plane to maximize the area shared with a convex polygon, and print that maximum.Hard8GeometryBinary search+1No attempts yet3s512 MBJudgeable
Sorting GameApply K sets of operations, each sorting a prefix of length A ascending then a prefix of length B descending, and print the final sequence.Hard8SortingImplementation+2No attempts yet1s128 MBJudgeable
Laser TowersOn a grid with directional laser towers and enemy counts, choose which towers fire and at which cell so lasers never intersect, maximizing enemies destroyed.Hard8GreedyBrute force+2No attempts yet2s512 MBJudgeable
Counting ear shapesCount quadruples of red points and pairs of blue points forming an ear shape with angle and containment conditions.Hard8GeometryBrute force+2No attempts yet2s512 MBJudgeable
Edsger DijkstraGiven a program of labeled print statements and if-goto statements with counters that are true for a bounded number of times, decide whether transforming every if-goto into a do-while loop keeps the program's output and compiles.Hard8SimulationImplementation+2No attempts yet2s256 MBJudgeable
Substitution Cipher KeyGiven N distinct words and a target permutation, find the lexicographically smallest substitution cipher key that sorts the encrypted words into that order, or report none.Hard8GreedySorting+2No attempts yet1s64 MBJudgeable
KingN elves each target a dwarf; elves enter one at a time and slide clockwise to the next free spot. Choose the entry order to maximize elven wins.Hard8GreedySorting+2No attempts yet2s128 MBJudgeable
Vertices connected by the same colorProcess color flip and reachability queries on a tree where two vertices are connected if every vertex on their path has the same color.Hard8TreeUnion-find+2No attempts yet2s512 MBJudgeable
K-th smallest weight on a tree pathFor each query, print the k-th smallest vertex weight on the unique tree path between two vertices.Hard8TreeBinary search+2No attempts yet2s512 MBJudgeable
Palindromes and QueriesSupport range character assignments and count palindromic substrings of length at most K inside a queried range.Hard8Segment treeString+2No attempts yet2s512 MBJudgeable
RoomGiven points on the edges of an unknown orthogonal monotone polygon with edge orientations, reconstruct it and output its perimeter or -1 if impossible.Hard8GeometrySorting+2No attempts yet2s512 MBJudgeable
Feasible roundingRound each decimal entry to floor or ceiling so that every row and column sum still matches its stated total, choosing the lexicographically smallest whole table.Hard8GreedyMatrix+2No attempts yet1s512 MBJudgeable
Olympic Gold AthletesEach athlete's skill and fatigue change linearly in time; count those who are the unique max-skill and unique min-fatigue athlete at some time t >= 0.Hard8GeometryBinary search+2No attempts yet1s512 MBJudgeable
OminoboxFor every fixed N-omino placement in a small grid, the drop score is H minus the maximum stack height covered; sum the best placement score over all N-ominoes.Hard8Brute forceImplementation+2No attempts yet10s512 MBJudgeable
Dona MinhocaOn a cactus graph, for each query (entry chamber, worm length) decide whether a closed non-backtracking walk of length at most M exists and give the shortest such distance.Hard8GraphDFS+2No attempts yet2s512 MBJudgeable
Ecology PreserveGiven an N by N grid of tree counts, pick a connected set of exactly M cells (M at most 10) maximizing the total tree count.Hard8Dynamic programmingDFS+2No attempts yet2s512 MBJudgeable
War Among the StarsCompute the shortest distance between two tetrahedra in space, given the coordinates of their eight vertices.Hard8GeometryImplementation+1No attempts yet2s512 MBJudgeable
Scientists' RegattaGiven start, finish, and non-intersecting segment obstacles in the plane, compute the shortest path that never crosses a segment interior.Hard8GeometryShortest path+2No attempts yet2s512 MBJudgeable