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 results868 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Coin FlippingGiven an N by N grid of H/T coins (N up to 20), find the minimum number of tails achievable by flipping any subset of rows and columns.Medium6Bit manipulationBrute force+2No attempts yet6s128 MBJudgeable
Assigning Tasks 1Given an N by N cost matrix, assign each person exactly one task to minimize the total assignment cost.Medium6Dynamic programmingBit manipulation+1No attempts yet1s512 MBJudgeable
Coin Flips IIGiven an N by M grid of coins, find the minimum number of top-left rectangle flips needed to turn every coin to heads.Medium6MatrixGreedy+1No attempts yet2s128 MBJudgeable
Shom SquareConstruct the lexicographically smallest N by N grid using digits 0 to D-1 so every row and column contains all D values at least once.Medium6BacktrackingGreedy+1No attempts yet2s128 MBJudgeable
Turning On the LightsFind the minimum number of bulb presses, each flipping a cell and its 8 neighbors, needed to turn all bulbs on an N×M grid (N,M ≤ 8) on, or report impossibility.Medium6Bit manipulationBrute force+2No attempts yet2s128 MBJudgeable
Minho's CuriosityGiven an all-pairs shortest-time matrix for N cities, reconstruct the minimum-edge road network with the same shortest times and output the total edge weight, or -1 if impossible.Medium6Shortest pathGraph+1No attempts yet2s128 MBJudgeable
Dongmin SequenceCount sequences of lucky numbers (digits 4/7 only) chosen from a given list of length L, where consecutive elements share first/last digit, modulo 1,234,567,891.Medium6MatrixDynamic programming+2No attempts yet2s128 MBJudgeable
Position ExchangeFind the minimum number of simultaneous turns for two players on a grid to swap starting cells, moving in 8 directions while avoiding walls, collisions, and direct swaps, using BFS over joint position states.Medium6BFSGraph+2No attempts yet2s128 MBJudgeable
Escape the Hazard ZonesGiven overlapping rectangular zones on a 501x501 grid marking safe, dangerous, and blocked cells, find the minimum life lost moving from (0,0) to (500,500).Medium6BFSGraph+2No attempts yet2s128 MBJudgeable
Monkey Who Wants to Move Like a HorseFind the minimum number of moves for a monkey to reach the bottom-right cell of a grid using normal steps and at most K knight-like jumps over obstacles.Medium6BFSShortest path+2No attempts yet2s256 MBJudgeable
Coin FlipsFind the minimum number of row and column flips on an odd N by M 0/1 grid so every row and column has an even count of 1s, or output -1.Medium6MathBit manipulation+2No attempts yet2s128 MBJudgeable
Largest Zero SubmatrixGiven a binary matrix, find the maximum area rectangle of consecutive rows and columns that contains only zeros.Medium6StackDynamic programming+2No attempts yet2s128 MBJudgeable
Box PuzzlePlace n^2 rotatable cube boxes into an n by n grid so touching side faces match and outward faces show 0, then output the arrangement and rotation counts.Medium6BacktrackingMatrix+2No attempts yet2s128 MBJudgeable
Maximum Submatrix SumGiven an N by M integer matrix, find the maximum possible sum over all contiguous rectangular submatrices.Medium6Dynamic programmingMatrix+2No attempts yet2s128 MBJudgeable
Finding the Maximum Score PathFind the maximum-score simple path from the top-left to bottom-right cell of an N x N grid moving only in four directions without revisiting cells.Medium6BacktrackingDFS+2No attempts yet2s128 MBJudgeable
Greedy PandaFind the longest strictly increasing path through adjacent cells in an n x n grid using memoized DFS.Medium6DFSDynamic programming+1No attempts yet2s256 MBJudgeable
Matrix ConstructionGiven target row sums and column sums, construct any 0/1 n x n matrix satisfying both, or report impossibility.Medium6GreedyMatrix+1No attempts yet2s128 MBJudgeable
Submatrix Range QueriesGiven an N x N matrix and K fixed-size BxB submatrix queries, output the max minus min value for each queried window efficiently.Medium6Sliding windowMatrix+1No attempts yet2s128 MBJudgeable
MinecraftGiven three 2D projections of a 3D 0/1 grid, construct any consistent 3D grid or report impossibility.Medium6MatrixGreedy+1No attempts yet1.52s1024 MBJudgeable
Largest L ShapeGiven a binary grid, find the maximum-area L-shape (union of two rectangles sharing a lower-left corner, wider base and taller top) made entirely of 1-cells.Medium6Dynamic programmingMatrix+1No attempts yet2s128 MBJudgeable
Go TerritoryReconstruct a unique black/white Go board from row, column, and both diagonal stone counts, then flood-fill empty regions to count enclosed territory.Medium6Brute forceBFS+1No attempts yet2s128 MBJudgeable
Nth Largest NumberGiven an N x N matrix where each column is sorted top to bottom, find the Nth largest value among all N^2 entries efficiently.Medium6Binary searchMatrix+1No attempts yet1s12 MBJudgeable
Game of DeathGiven a directed graph where each of N people points to two others, determine for M queries if b can be reached from a in exactly K steps.Medium6GraphMatrix+1No attempts yet3s256 MBJudgeable
GalleryGiven a grid of walls and empty cells, compute the maximum number of double-cell-length pictures that can be hung on wall faces adjacent to empty space without overlapping.Medium6GreedyMatrix+1No attempts yet2s128 MBJudgeable
Robot NavigationGiven an N x M grid, find the maximum sum path from top-left to bottom-right moving only left, right, or down without revisiting cells.Medium6Dynamic programmingMatrix+1No attempts yet1s512 MBJudgeable
Palindrome PathsCount length-L walks on an N x N grid with 8-directional moves whose visited digit sequence forms a palindrome.Medium6Dynamic programmingMatrix+1No attempts yet2s128 MBJudgeable
Matchsticks and SquaresGiven a grid of matchsticks drawn with horizontal and vertical line segments, count all squares of any size whose four full sides are present.Medium6MatrixBrute force+1No attempts yet1s128 MBJudgeable
SudokuSolve a given 9x9 Sudoku puzzle via backtracking and output the lexicographically smallest completed board if multiple solutions exist.Medium6BacktrackingMatrix+1No attempts yet2s256 MBJudgeable
Water FillingGiven a grid of terrain heights, compute the maximum water volume trapped inside using a boundary-based priority-queue flood fill (trapping rain water 2D).Medium6HeapMatrix+1No attempts yet2s128 MBJudgeable
Mirror RaysSimulate light rays reflecting off '/' mirrors in an N×M grid and report, for each numbered border hole, which hole the ray exits from.Medium6SimulationMatrix+1No attempts yet2s256 MBJudgeable
Automatic SprinklersReconstruct the placement of fertilizer and herbicide sprinklers on an 8x8 grid given the resulting yields per row and column effects, along with the sprinkler count.Medium6MatrixMath+1No attempts yet1s128 MBJudgeable
SudokuSolve a standard 9x9 sudoku puzzle by filling empty cells so every row, column, and 3x3 box contains digits 1 through 9, using backtracking search.Medium6BacktrackingMatrix+1No attempts yet1s256 MBJudgeable
Police CarsAssign a sequence of incidents to one of two police cars moving along Manhattan-distance shortest paths so that total travel distance is minimized, and output the assignment.Medium6Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
CheeseSimulate hourly melting of cheese cells on a grid, where a cell melts if at least two sides touch outside air reachable via BFS/flood fill, and output total hours until all cheese disappears.Medium6BFSSimulation+1No attempts yet1s128 MBJudgeable
Beautiful MatrixGiven an N x N matrix (N up to 400), find the maximum difference between the main diagonal sum and anti-diagonal sum over all possible square submatrices.Medium6MatrixPrefix sum+1No attempts yet1s128 MBJudgeable
Counting Pipe InstallationsCount the ways to lay a single connected pipe path with six pipe shapes from the top-left entry to the bottom-right exit through a grid with blocked cells, modulo 10007.Medium6Dynamic programmingMatrix+1No attempts yet2s128 MBJudgeable
45-Degree RotationRotate a character grid clockwise by a multiple of 45 degrees, including diagonal renderings, keeping letters upright and output compact.Medium6SimulationMatrix+1No attempts yet1s128 MBJudgeable
Stone DroppingSimulate stones falling one at a time down a grid with walls, sliding left or right when blocked, and print the final board.Medium6SimulationMatrix+1No attempts yet1s128 MBJudgeable
Number of PlusesCount all plus-shaped patterns of odd size at least 3 in an N x N binary matrix, where every cell outside the cross must be 0.Medium6Dynamic programmingMatrix+1No attempts yet1s128 MBJudgeable
Apples and BananasFind a monotone down/right/diagonal path in an RxC grid to maximize apples below plus bananas above it, with R,C up to 1500.Medium6Dynamic programmingMatrix+1No attempts yet1s256 MBJudgeable
Minimum Trailing Zeros PathFind a path from top-left to bottom-right of an N×N grid, avoiding zero cells, that minimizes trailing zeros in the product of visited cells.Medium6Dynamic programmingMatrix+1No attempts yet1s128 MBJudgeable
An Arithmetic RectangleDetermine whether missing cells in a grid can be filled with rationals so every row and column becomes an arithmetic progression.Medium6MathMatrix+1No attempts yet1s128 MBJudgeable
GamersFor a grid where each cell must visit every other cell offering a different game via round trips through its own home, compute the total travel cost summed over all cells.Medium6MatrixMath+1No attempts yet5s128 MBJudgeable
Row and Column Deletion GameGiven an n x n matrix where players alternately remove the last row or column if its sum is even, determine which player wins with optimal play across possibly many test cases up to n=1000.Medium6Game theoryDynamic programming+1No attempts yet1s128 MBJudgeable
16x16 SudokuSolve a given 16x16 Sudoku puzzle so each row, column, and 4x4 box contains letters A to P exactly once, given a unique solution exists.Medium6BacktrackingMatrix+1No attempts yet3s128 MBJudgeable
City GameGiven several grid maps of free and reserved cells, find the largest all-free rectangle in each grid and print its area times three.Medium6StackDynamic programming+1No attempts yet1s128 MBJudgeable
One-Dimensional Cellular AutomatonSimulate a linear recurrence over N cells modulo M for up to 1e9 steps using fast matrix exponentiation.Medium6MatrixMath+1No attempts yet2s128 MBJudgeable
Fake ScoreboardReconstruct a binary team-by-problem matrix matching given row and column sums, outputting the lexicographically smallest valid matrix or reporting impossibility (Gale-Ryser style bipartite degree sequence problem).Medium6GreedyCombinatorics+1No attempts yet2s128 MBJudgeable
Production ProcessGiven a matrix chain-like joining table for pieces, find the minimum-time parenthesization to assemble a given string, breaking ties by piece order.Medium6Dynamic programmingString+1No attempts yet5s128 MBJudgeable
Where's WallyDecode base64-like bit matrices for an image and a square pattern, then count all image squares matching the pattern under any rotation or mirror flip.Medium6MatrixString matching+2No attempts yet4s128 MBJudgeable
Cubist ArtworkGiven front and side view maximum heights for a grid of cube piles, find the minimum total number of cubes consistent with both views.Medium6GreedyMatrix+1No attempts yet1s128 MBJudgeable
Flip It!Simulate a sequence of row and column flips that collapse a grid of cards into one pile, then list the face-up cards from the bottom.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
Tic-Tac-ToeGiven an n by n tic-tac-toe board with win length m, decide if the state is in progress, finished (X, O, or draw), or impossible.Medium6ImplementationSimulation+2No attempts yet1s128 MBJudgeable
Fire!Given a grid with walls, one starting cell, and burning cells, find the earliest minute Jihoon can step off the edge, given the fire spreads one cell per minute.Medium6BFSGraph+2No attempts yet1s256 MBJudgeable
Janken TacticsOn a hex grid with terrain costs and enemy-threat rules, validate a sequence of moves by finding the cheapest legal path and reporting leftover movement points.Medium6GraphShortest path+2No attempts yet1s128 MBJudgeable
Don't Get RookedFind the maximum number of non-attacking rooks on a board up to 4x4 where walls block rook attacks.Medium6BacktrackingBrute force+2No attempts yet1s128 MBJudgeable
A Puzzling ProblemPlace up to 5 fixed-orientation polyomino pieces, each labeled by index, to tile a 4x4 square exactly, printing the lexicographically smallest labeled grid or a failure message.Medium6BacktrackingBrute force+2No attempts yet1s128 MBJudgeable
Doggone MolesTrack which grid cells the mole could occupy across observed terrier moves, since standing on or beside a terrier means capture.Medium6SimulationMatrix+1No attempts yet1s128 MBJudgeable
Cliff ClimbingFind the minimum total time for Jack to climb a grid, moving feet alternately under distance constraints, from a bottom S block to a top T block.Medium6Shortest pathGraph+2No attempts yet1s128 MBJudgeable
Rotation MazeGiven a maze where a ball falls under gravity, find the shortest sequence of 90-degree left and right rotations that brings the ball to rest on the goal.Medium6BFSSimulation+2No attempts yet1s128 MBJudgeable
CubingSimulate a sequence of Rubik's cube face turns from a solved state and print the colors on the up face.Medium6ImplementationSimulation+2No attempts yet1s128 MBJudgeable
Drawing with XOREach XOR call flips a rectangle anchored at the bottom right, so the number of calls equals the count of pixels that differ from the pixel below and the pixel to the right, plus the bottom-right pixel.Medium6ArrayMatrix+2No attempts yet1s512 MBJudgeable
Starry NightFind 8-connected star clusters in a grid and assign the same letter to clusters that match under rotation and reflection.Medium6DFSMatrix+2No attempts yet1s128 MBJudgeable
SenbeiGiven a binary R x C grid with R at most 10, choose one subset of rows and one subset of columns to flip so the number of 1s is maximized.Medium6Brute forceGreedy+2No attempts yet1s128 MBJudgeable
Finding SeatsGiven an R by C grid of free and taken seats, place K people on free seats so the bounding rectangle has the smallest area.Medium6Two pointersBinary search+2No attempts yet1s128 MBJudgeable
Grandpa's Rubik CubeGiven a Rubik's cube configuration and a list of face rotations, decide whether applying them all yields a solved cube with each face a single color.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
RobberyGiven time-stamped rectangular exclusions, find the robber's position at each time step where it is uniquely determined, moving at most one cell per step.Medium6Dynamic programmingSimulation+1No attempts yet1s128 MBJudgeable
The GameFor each pair of pieces on a grid, decide if an orthogonal path can join them without crossing others, and give the minimum number of straight segments.Medium6BFSGraph+2No attempts yet1s128 MBJudgeable
Plato's BlocksGiven three n by n shadow patterns, decide whether one connected solid built from unit cubes can cast all three shadows simultaneously.Medium6BacktrackingBrute force+2No attempts yet1s128 MBJudgeable
Paper FoldingDraw the dragon curve made by folding a strip of paper N times and opening each crease to 90 degrees, using underscores and bars.Medium6ImplementationSimulation+2No attempts yet1s128 MBJudgeable
Homogeneous SquareGiven an n by n grid, decide whether every choice of n cells with distinct rows and distinct columns has the same sum.Medium6MathMatrix+2No attempts yet1s128 MBJudgeable
Interesting Maze GameGiven a 7x7 labyrinth and one extra card, decide whether inserting and rotating that card lets the piece walk to the target in a single move.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
Cross SpiralTrace a clockwise inward spiral walk on a cross-shaped tile grid and report the column and row after S steps, or where she gets trapped.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
Number MatrixGiven a digit grid, find the lexicographically smallest set of three digits such that some 4-directional path uses only those digits from row 1 to row M.Medium6GraphBFS+2No attempts yet2s512 MBJudgeable
BlindfoldGiven a grid with obstacles and a fixed sequence of forward/turn moves, mark every walkable square that can be a final position for some unknown start and heading.Medium6SimulationBit manipulation+2No attempts yet1s128 MBJudgeable
Stacking CubesGiven a stacking pattern as non-increasing rows with non-increasing columns, print its left and right rotations as corner stackings.Medium6ArrayImplementation+2No attempts yet1s128 MBJudgeable
Street NetworkDecide whether a directed multigraph has an Eulerian trail, count possible start nodes, and for S at most 3 count closed walks of length S from each node, sorted.Medium6GraphImplementation+2No attempts yet1s128 MBJudgeable
Heating MainCount the ways to lay a single non-crossing path of four fixed pipe shapes from the top-left top side to the bottom-right right side, respecting fixed pipes and blocked garden cells on a grid of at most 10 by 10.Medium6BacktrackingDFS+2No attempts yet1s128 MBJudgeable
Swimming PoolGiven an m by n grid of tower heights, find the total volume of water trapped among the towers when the grid is flooded from the outside.Medium6HeapBFS+2No attempts yet1s128 MBJudgeable
Alphariz Table CollapseGiven a letter grid and a list of chosen cells, repeatedly erase each chosen cell's 4-connected equal-letter region, then slide rows left and columns down, deleting empty rows and columns.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
Space Station ShieldingGiven occupied unit cells of a connected 3D station, count faces on the external surface, where enclosed hollow pockets do not count.Medium6BFSImplementation+2No attempts yet1s128 MBJudgeable
Square IceGiven an alternating sign matrix, render the corresponding square ice grid using H, O, dashes, bars, and an asterisk border.Medium6ImplementationMatrix+2No attempts yet1s128 MBJudgeable
SudokuFill every empty cell of a 9x9 Sudoku grid so each row, column, and 3x3 box contains the digits 1 through 9 exactly once.Medium6BacktrackingMatrixNo attempts yet1s128 MBJudgeable
SkewersCount strings of length n over p letters that avoid a given set of forbidden bigrams and trigrams, modulo m.Medium6Dynamic programmingMatrixNo attempts yet1s128 MBJudgeable
WaterGiven a grid of cuboid heights, find the total volume of water trapped in the depressions after rain, where water cannot escape past the grid boundary.Medium6HeapBFS+2No attempts yet3s128 MBJudgeable
The Right-Turn Drivers' ClubOn a grid with blocked cells, find the shortest A-to-B path that never turns left or makes a U-turn, counting squares visited.Medium6BFSGraph+2No attempts yet1s128 MBJudgeable
MapGiven an n by m grid and q queries, each comparing two h by w subrectangles, decide if at most k corresponding cells differ.Medium6Prefix sumMatrix+1No attempts yet1s128 MBJudgeable
Magic SquareFill in the n missing cells, one per row and column, so all rows, columns, and both diagonals add to the same total.Medium6MathMatrixNo attempts yet1s512 MBJudgeable
KlasyPrint the requested subrectangle of an n by n grid filled in spiral order from a corner by a walk that turns only right or only left.Medium6SimulationMath+1No attempts yet1s512 MBJudgeable
AquaparkSum the grid values inside the Manhattan diamond of radius l_i around each lifeguard.Medium6Prefix sumMatrixNo attempts yet1s512 MBJudgeable
Paweł i GawełTwo players alternate moving a pawn across a grid, swapping floors whenever it enters a marked cell, each trying to hold the upper floor at the end.Medium6Game theoryDynamic programming+1No attempts yet3s128 MBJudgeable
Art classGiven red, green, and blue values for each pixel of a painting, decide which of four described art styles it belongs to and print its number.Medium6SimulationMatrix+1No attempts yet5s256 MBJudgeable
Pile of CubesFind the largest number of cubes in a gravity-respecting pile that matches the given top, front, and right views, or report -1 when no pile fits.Medium6GreedyMatrixNo attempts yet1s128 MBJudgeable
If only I could think Linearly...Given a matrix M and output vector y, find the three nonzero entries of the input vector x with Mx equal to y.Medium6MatrixBrute forceNo attempts yet1s128 MBJudgeable
Unscrambling ImagesThe solver recovers the hidden child order at each quadtree node from the test encoding and restores the secret image.Medium6TreeRecursion+1No attempts yet1s128 MBJudgeable
GoSimulate simplified Go on boards up to 20 by 20, reject the first stone placed on an occupied point, and count each side's stones plus surrounded empty points.Medium6SimulationBFS+1No attempts yet1s128 MBJudgeable
Omar Loves CandiesFind the largest sum of any non-empty sub-rectangle in a grid whose rows and columns strictly increase.Medium6Prefix sumGreedy+1No attempts yet3s128 MBJudgeable
CubeDecide whether six numbered cells in a 6 by 6 grid fold into a cube and report the face opposite face 1.Medium6SimulationBFS+1No attempts yet2s1024 MBJudgeable
OrchardPick one rectangle for Bert to minimize the bananas left outside it plus the apples inside it.Medium6MatrixPrefix sum+1No attempts yet2s512 MBJudgeable
Quality of LivingFind the smallest median among all H by W subrectangles of a grid holding the numbers 1 to R times C.Medium6Binary searchPrefix sum+1No attempts yet5s256 MBJudgeable