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,012 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Faulty RobotGiven a directed graph where at most one designated forced edge leaves each node, count the nodes where the robot can end up stopping if it breaks the forced rule at most once along the way.Medium6GraphDFS+2No attempts yet2s512 MBJudgeable
Loading CargoDecide whether N capsules can be split between two compartments of capacities L and R so that no conflicting pair shares a compartment.Medium6GraphDFS+2No attempts yet3s512 MBJudgeable
Leveling the TilesGiven a grid of heights, each impact lowers one tile and all tiles connected to it at the same height; find the minimum impacts to make every tile equal.Medium6GraphBFS+2No attempts yet5s512 MBJudgeable
Balanced TreeGiven a tree whose vertices each hold A or B, swap characters along edges so no edge joins equal letters, using the fewest swaps, or report -1.Medium6TreeDFS+2No attempts yet1s512 MBJudgeable
Hidden HierarchyBuild a directory tree from file paths, and print the smallest set of directories (expanding or collapsing as needed) that covers every directory whose total size is at least t.Medium6TreeHash map+2No attempts yet1s512 MBJudgeable
Flow FreeGiven a 4x4 Flow Free board with 3 or 4 color pairs, decide whether all cells can be covered by non-crossing paths joining matching endpoints.Medium6BacktrackingDFS+1No attempts yet2s512 MBJudgeable
The Components GameFor each board, pick the single column to turn entirely black that maximizes the total number of same-color connected regions, breaking ties by more white regions.Medium6GraphDFS+2No attempts yet2s512 MBJudgeable
Barn PaintingCount the proper 3-colorings of a tree consistent with some pre-colored nodes, modulo 1e9+7.Medium6TreeDynamic programming+2No attempts yet2s512 MBJudgeable
The Bovine ShuffleGiven a functional graph where each position i sends its cow to a_i, count the positions that hold at least one cow no matter how many shuffles are applied.Medium6GraphDFS+2No attempts yet2s512 MBJudgeable
Tournament ChartParse a knockout bracket given as a string and decide whether the reported win counts for all players can be consistent with some assignment of match winners.Medium6TreeDFS+2No attempts yet2s512 MBJudgeable
Anagram Pyramids (Hard)Given a dictionary and query word pairs, decide whether an anagram pyramid can be built from the top word down to the bottom word.Medium6GraphDFS+1No attempts yet10s512 MBJudgeable
MooTube (Silver)Given a weighted tree, for each query (k, v) count the vertices whose bottleneck distance (minimum edge on the path) from v is at least k.Medium6GraphDFS+1No attempts yet2s512 MBJudgeable
Pepper WreathGiven a tree whose vertices carry non-negative weights and a cap k, find the minimum number of edges to cut so every resulting component has total weight at most k.Medium6TreeDFS+2No attempts yet1s1024 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
Sejin VirusGiven a directed graph of facilities and pipes, find the minimum number of starting nodes from which all nodes are reachable.Medium6GraphDFS+1No attempts yet1s512 MBJudgeable
Tree Country Tour GuideGiven the move sequence of a shortest round trip that visits every node of an unknown rooted tree, reconstruct each city's parent.Medium6StackTree+1No attempts yet1s512 MBJudgeable
You on That DayGiven measured environmental factors and one-operation definitions, compute each factor's partial derivative of HAPPY and print it as a reduced fraction.Medium6Dynamic programmingDFS+2No attempts yet1s512 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
Two RobotsOn a weighted tree, two robots at given nodes must meet on some edge or its endpoints; find the minimum combined distance traveled.Medium6TreeDFS+2No attempts yet2s512 MBJudgeable
Mosaic Logic PuzzleGiven clue numbers on a border-extended grid saying how many of the 3x3 neighbors are black, color cells black or report impossibility.Medium6BacktrackingDFS+2No attempts yet2s512 MBJudgeable
ParadeGiven an undirected graph with V vertices and E edges, decide whether it has an Eulerian circuit that traverses every edge exactly once.Medium6GraphUnion-find+2No attempts yet2s128 MBJudgeable
Is-A? Has-A? Who Knowz-A?Given is-a and has-a edges between classes, answer queries whether one class is-a or has-a another using inheritance and field transitivity.Medium6GraphBFS+2No attempts yet2s512 MBJudgeable
DebloGiven a tree with numbers on its nodes, add up the XOR of every node-value along every path between two nodes, counting single-node paths too.Medium6TreeBit manipulation+2No attempts yet1s512 MBJudgeable
Hotel ManagementEach room belongs to exactly two switches; find whether pressing some subset of switches turns every room's lock state to open.Medium6GraphDFS+2No attempts yet2s512 MBJudgeable
Making a ShapeIn a grid of 0s and 1s, find the largest connected group of 1s obtainable by flipping exactly one 0 cell to 1.Medium6GraphDFS+2No attempts yet2s512 MBJudgeable
Ball on a ChessboardEach cell of an R by C board holds a distinct number; every ball rolls to the smallest neighbor until it reaches a local minimum, and we must count how many balls stop on each cell.Medium6GraphDynamic programming+2No attempts yet2s512 MBJudgeable
DFS Special JudgeGiven a tree and a permutation of its vertices, decide whether that permutation can be the DFS visit order starting from vertex 1.Medium6DFSTree+2No attempts yet2s512 MBJudgeable
The Great Revegetation (Silver)Count the binary assignments of grass types to N pastures that satisfy M same-or-different constraints on pairs, and print the count in binary.Medium6Union-findGraph+2No attempts yet2s512 MBJudgeable
Exits in ExcessGiven a directed graph, choose at most half of its edges to delete so that the remaining graph has no directed cycle.Medium6GraphDFS+2No attempts yet2s512 MBJudgeable
Finding the RankGiven a set of pairwise comparisons among N students, find the best and worst possible rank of student X over all total orders consistent with the comparisons.Medium6GraphDFS+2No attempts yet1s512 MBJudgeable
StrapsChoose a set of straps forming a rooted tree: each strap occupies one port of its parent, one strap hangs from the phone, and total happiness is maximized.Medium6Dynamic programmingTree+2No attempts yet1s512 MBJudgeable
Improve SPAMGiven nested mailing lists, count how many messages reach client emails before deduplication and how many distinct emails are reached, both modulo 1e9+7.Medium6GraphDFS+2No attempts yet0.3s512 MBJudgeable
A Water Slide at Catholic University??Given a directed graph, find the minimum number of starting vertices whose reachable sets cover every vertex.Medium6GraphBFS+2No attempts yet1s1024 MBJudgeable
Bob in WonderlandGiven a tree of N connected links, find the minimum number of link reconnections needed to turn it into a path (each vertex has degree at most two).Medium6TreeGreedy+1No attempts yet2s512 MBJudgeable
Railway TourGiven an undirected graph, find the minimum number of edge-disjoint trails needed to cover every edge exactly once.Medium6GraphDFS+2No attempts yet1s512 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
PasswordCount the Android-style 3x3 patterns whose segment directions match a given string, allowing any segment lengths, with no self-intersection allowed.Medium6DFSBacktracking+2No attempts yet2s512 MBJudgeable
Nested Set ModelRoot an undirected tree at S, traverse children in ascending order, and label each node with nested left/right interval numbers.Medium6DFSTree+2No attempts yet1s1024 MBJudgeable
MafiaGiven guilt scores and a reaction matrix, the mafia Eunjin picks one night victim at a time and must survive as long as possible, returning the maximum number of nights.Medium7Bit manipulationDFS+2No attempts yet2s128 MBJudgeable
Coin Board GameA coin on a grid jumps exactly the digit on its cell in one of four directions; find the maximum number of moves before it leaves the board or hits a hole, or -1 if it can move forever.Medium7Dynamic programmingDFS+2No attempts yet2s512 MBJudgeable
Number of Vertex Cactus ComponentsGiven a graph, count connected components that are vertex cacti, meaning every vertex lies in at most one simple cycle.Medium7GraphDFS+1No attempts yet2s128 MBJudgeable
MafiaGiven a graph of tollgates and highways, choose a minimum-cost set of intermediate tollgates whose removal disconnects the start from the destination, solved via vertex-split min-cut/max-flow.Medium7GraphBFS+1No attempts yet2s128 MBJudgeable
Oh Min-sik's WorryFind the maximum money achievable traveling from city A to city B using weighted directed edges and city rewards, detecting infinite gain via positive cycles.Medium7GraphShortest path+2No attempts yet2s128 MBJudgeable
Special NodesIn a rooted tree where child weights exceed parent weights, mark vertices special or ordinary to minimize the total of each ordinary vertex's weight minus its nearest special ancestor's weight.Medium7Dynamic programmingTree+2No attempts yet2s128 MBJudgeable
Group Word ReconstructionReconstruct the unique group word, where every letter forms one contiguous block, by arranging all given unordered pieces, or report impossibility or multiple solutions.Medium7GraphString+2No attempts yet2s128 MBJudgeable
Finding Domino TilingsCount the ways to tile a fixed 8x7 numeric grid with all 28 distinct dominoes so that each domino's pair matches the covered cell values.Medium7BacktrackingBit manipulation+2No attempts yet2s128 MBJudgeable
Rook AttackGiven an R by C board with N unusable squares, find the maximum number of non-attacking rooks that can be placed on the remaining squares.Medium7GraphBFS+2No attempts yet2s128 MBJudgeable
GraduationMatch already-taken and newly taken courses to graduation requirements via bipartite matching, minimizing extra courses and finding the lexicographically smallest such set.Medium7GraphGreedy+2No attempts yet2s128 MBJudgeable
PasturesGroup adjacent rectangular pastures into connected clusters, find the cluster with the largest bounding-box gap, then pick the smallest pasture whose removal keeps that cluster connected.Medium7DFSGraph+2No attempts yet2s128 MBJudgeable
Drum MessageGiven K and M, construct a de Bruijn sequence of length K^M on a drum so every length-M string over digits 0..K-1 appears exactly once, or print -1 if impossible.Medium7GraphDFS+2No attempts yet5s512 MBJudgeable
BishopsGiven an N by N board with some cells forbidden, find the maximum number of bishops that can be placed so no two attack each other along diagonals.Medium7GraphDFS+2No attempts yet10s128 MBJudgeable
Removing StonesGiven stones on an n by n grid, find the minimum number of row or column sweeps needed to remove every stone, which reduces to minimum vertex cover in a bipartite graph.Medium7GraphDFS+2No attempts yet2s128 MBJudgeable
Treasure HuntGiven a tree of rooms, compute the minimum worst-case number of queries needed to locate a hidden treasure using an optimal centroid-based questioning strategy.Medium7TreeDivide and conquer+2No attempts yet2s128 MBJudgeable
Winning PracticeGiven a graph, assign each vertex to one of two groups so that every vertex has an even number of same-group neighbors, and output one valid group.Medium7GraphDFS+1No attempts yet2s128 MBJudgeable
Tree Path PartitionGiven a tree and integer K, find the minimum number of vertex-disjoint paths of length at most K that cover all vertices.Medium7TreeGreedy+1No attempts yet1s128 MBJudgeable
Car RaceGiven a directed graph with no cycles avoiding vertex 1, find the maximum-score simple route from checkpoint 1 back to checkpoint 1 and print it.Medium7GraphDynamic programming+1No attempts yet1s128 MBJudgeable
TrampolineGiven building heights, adjacency-based jump rules, and trampolines that allow teleporting anywhere, find the maximum number of distinct buildings reachable starting from building K.Medium7GraphDFS+1No attempts yet1s128 MBJudgeable
Road RepairGiven a tree with per-edge reducible travel times and a total repair budget, minimize the maximum distance from city 1 to any other city by optimally allocating budget across edges.Medium7Binary searchTree+2No attempts yet2s128 MBJudgeable
Two Snow PlowsGiven a tree rooted at S, find minimum total edge traversal cost for two walks starting at S that together cover every edge, without returning to S.Medium7TreeDynamic programming+1No attempts yet1s128 MBJudgeable
LinkGiven a functional graph where each node has exactly one outgoing edge, find the minimum number of edges to add so every node is reachable from node 1 within K hops.Medium7GraphGreedy+1No attempts yet2s64 MBJudgeable
Alice and BobGiven all polygon sides and non-crossing diagonals as an unordered edge list, reconstruct the convex polygon's cyclic vertex order.Medium7GraphDFS+1No attempts yet1s128 MBJudgeable
InspectionGiven a DAG representing ski slopes, find the minimum number of downhill paths needed to cover every edge, which reduces to a minimum path cover via bipartite matching.Medium7GraphDFS+1No attempts yet1s128 MBJudgeable
Kripke ModelGiven a Kripke model with n up to 10000 states, compute the set of states satisfying the CTL formula E(x U (AG y)) using fixed-point graph algorithms.Medium7GraphDFS+2No attempts yet1s128 MBJudgeable
Lucky CitiesGiven an undirected graph, count vertices that lie on at least one simple cycle of odd length.Medium7GraphDFS+1No attempts yet1s128 MBJudgeable
Locks and KeysDetermine reachability on a tree with colored locks and single-use keys held one at a time, requiring a search over reachable key/room states.Medium7DFSGraph+1No attempts yet2s128 MBJudgeable
Last Minute ConstructionsGiven a forest of undirected roads plus a set of directed tunnels that must all be used, decide whether a simple path exists from a start to an end village that uses exactly those tunnels.Medium7GraphDFS+2No attempts yet1s128 MBJudgeable
The Worm TurnsFind a start cell and first direction that maximize how many food pieces a self-avoiding worm eats, turning only when blocked.Medium7DFSBrute force+2No attempts yet3s128 MBJudgeable
Family FortuneChoose K nodes in a rooted tree, no one an ancestor of another, maximizing the sum of weights; print 0 if impossible.Medium7Dynamic programmingTree+1No attempts yet10s128 MBJudgeable
Prime-Free SequenceFind the lexicographically smallest permutation of n..m where sums of any 2 to d consecutive numbers are all non-prime, or report none.Medium7BacktrackingDFS+2No attempts yet1s128 MBJudgeable
XYZZYGiven rooms with energy values and one-way doors, decide if the player can reach room n from room 1 while energy stays above zero, where rooms may repeat.Medium7GraphShortest path+1No attempts yet1s128 MBJudgeable
PegsGiven a 5x5 peg solitaire board with empty, peg, and blocked cells, find the minimum number of pegs reachable by any sequence of horizontal or vertical jumps.Medium7DFSBacktracking+2No attempts yet1s128 MBJudgeable
Hex Tile EquationsFind the unique Hamiltonian path through a small hex grid of digit and operator tiles that spells a valid left-to-right equation with both sides equal.Medium7BacktrackingDFS+2No attempts yet1s128 MBJudgeable
Trie, Again TrieGiven trees encoded in preorder, find the repeated subtree whose replacement by one shared copy saves the most nodes, breaking ties by size then preorder.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
MobilesGiven a mobile tree with one unknown object weight, find the weight that balances every bar and check that no two bars collide when they rotate.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Wealthy FamilyGiven a rooted tree with a weight on each node, pick exactly k nodes with no ancestor relation between any two, maximizing the total weight, over multiple test cases.Medium7TreeDynamic programming+2No attempts yet1s128 MBJudgeable
Jonny Hates MathSplit a digit string into positive addends of at most 5 digits with no leading zeros that sum to a given total, minimizing the number of plus signs and breaking ties lexicographically.Medium7DFSBacktracking+2No attempts yet5s128 MBJudgeable
Identically Colored Panels ConnectionOn a grid of up to 8 by 8 panels in six colors, the upper-left connected region changes color five times, absorbing same-colored neighbors; maximize the final region of the target color.Medium7DFSBFS+2No attempts yet1s128 MBJudgeable
Discrete SpeedFind the fastest route from a start to a goal city where a car enters each road at an integer speed, changes speed by at most 1 per city, starts and ends at speed 1, and cannot U-turn.Medium7GraphShortest path+2No attempts yet8s128 MBJudgeable
Gokigen NanameFill an n by n grid with one diagonal per cell so each numbered lattice point has exactly that many diagonal endpoints and no diagonal cycle forms.Medium7BacktrackingDFS+2No attempts yet1s128 MBJudgeable
Social Network VaccinationsGiven a graph with n at most 30 and D at most 6, choose D vertices to vaccinate so that the largest connected component remaining is as small as possible.Medium7GraphBrute force+2No attempts yet2s128 MBJudgeable
GearboxGiven gears of unknown teeth counts grouped on rods and pairs of interlocked gears, decide whether every rod can turn for any assignment of teeth counts to gear types.Medium7GraphDFS+2No attempts yet1s128 MBJudgeable
MondriaanGiven non-overlapping rectangles that tile a big rectangle, count the 3-colorings of the adjacency graph where orthogonally touching regions differ and white is a fourth free option.Medium7GeometryGraph+2No attempts yet1s128 MBJudgeable
Type PrinterFind the minimum number of add, remove, and print operations to type N distinct words on a printer that keeps a single editable string, with any print order allowed.Medium7TrieDFS+2No attempts yet1s128 MBJudgeable
Santa Claus and RudolphCount the closed tours that start and end at the single church, visiting every house once, where each move is a straight horizontal or vertical glide that may not pass over an already visited house.Medium7BacktrackingDFS+2No attempts yet12s128 MBJudgeable
The Lightest MobileGiven a tree of balanced rods with integer lever ratios, assign positive integer masses to all weights so every rod balances and the total mass is minimized.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
The Longest ChainGiven n strings, each with labeled rings a and b at its ends, find the number of vertices in the longest trail in the resulting multigraph.Medium7GraphDFS+2No attempts yet1s128 MBJudgeable
Traveling ShoemakerCities each belong to one or two color confederations; moving between cities consumes and produces tickets. Decide if a start city exists to visit every city exactly once.Medium7GraphDFS+2No attempts yet1s128 MBJudgeable
AcquapiaMultiple test cases give several river trees; for each city pair, report whether a route exists and, if so, the unique city where the ship must switch from upstream to downstream.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
X-MartGiven customers who each vote for up to two products to keep and against up to two to drop, decide whether some keep/drop assignment pleases all of them.Medium7GraphDFS+2No attempts yet1s128 MBJudgeable
Telecommunication PartnersGiven an undirected graph and K, find the largest connected vertex set where each vertex has degree at least K inside the set.Medium7GraphGreedy+1No attempts yet1s128 MBJudgeable
Running Away From the BarnFor every node in a weighted tree rooted at node 1, count the descendants within total distance L along the downward path, including the node itself.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Bovine AllianceCount assignments of each of M trails to one of its two endpoint farms so that no farm builds more than one trail, modulo 1e9+7.Medium7GraphCombinatorics+2No attempts yet1s128 MBJudgeable
Cow CalisthenicsRemove exactly S edges from a tree so that the largest diameter among the resulting components is as small as possible, and output that minimum diameter.Medium7TreeBinary search+2No attempts yet2s128 MBJudgeable
Tree DecorationPlace a minimum-cost number of ornaments on each node of a rooted tree so every subtree holds at least its required count, given per-node unit costs.Medium7TreeGreedy+2No attempts yet1s128 MBJudgeable
Slowing downFor each cow in order, count how many pastures already occupied by earlier cows lie on the tree path from node 1 to that cow's pasture.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Cow PoliticsGiven a tree with each node belonging to one of K parties, find the diameter (greatest distance between any two nodes) of the nodes in each party.Medium7TreeDFS+2No attempts yet2s128 MBJudgeable
Maximum FlowCompute the maximum flow from node A to node Z through a network of pipes with given capacities, using series and parallel reductions.Medium7GraphImplementation+2No attempts yet1s128 MBJudgeable
Corrupted BSTGiven a binary tree with distinct integer keys, find the minimum number of node keys to change so the tree satisfies the BST ordering, keeping its shape fixed.Medium7TreeDynamic programming+2No attempts yet1s128 MBJudgeable
PipesGiven net volume changes at each vertex of a connected graph, decide whether the flow on every edge is uniquely determined and print those flows if so.Medium7GraphDFS+2No attempts yet1s128 MBJudgeable
Slash MazeCount the closed loops in a grid of slash and backslash walls and report the longest loop's length, where each cell splits into two triangles.Medium7GraphDFS+2No attempts yet1s128 MBJudgeable