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 results514 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
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
Knapsack PackingGiven the multiset of all 2^n subset sums of n unknown non-negative weights, reconstruct the weights in non-decreasing order or report impossible.Medium7SortingGreedy+2No attempts yet2s512 MBJudgeable
Know your AliensGiven a human/alien label for each even number 2 to 2N, build the lowest-degree monic or anti-monic integer polynomial whose sign at 2i matches the label.Medium7MathDivide and conquer+2No attempts yet2s512 MBJudgeable
Insertion OrderFind a permutation of 1 to n whose insertion order into an unbalanced BST yields a tree of height exactly k, or report impossible.Medium7TreeGreedy+2No attempts yet2s512 MBJudgeable
ShuffleApply a recursive shuffle to a deck of 2^n cards t times and print the final card order.Medium7Divide and conquerBit manipulation+2No attempts yet1s256 MBJudgeable
Shortest Accepted WordParse a regular expression over a, b, c and $ into a tree, then compute the shortest lexicographically smallest string each node accepts.Medium7Dynamic programmingString+2No attempts yet1s256 MBJudgeable
Binary and Ternary Search Game 3For each query N, compute the maximum number of array elements compared in binary search and in ternary search over all positions in a sorted array of size N.Medium7Binary searchDivide and conquer+2No attempts yet2s256 MBJudgeable
Dividing the KingdomGiven n distinct integer-half points in the plane, output at most n-1 axis-parallel lines at integer coordinates so that no two points share a region.Medium7Divide and conquerGeometry+2No attempts yet2s512 MBJudgeable
Make a NumberStarting from 1, find the minimum number of +1, -1, and power operations needed to reach a target N up to 10^18.Hard8Number theoryMath+2No attempts yet2s128 MBJudgeable
Two-Bill PurchaseGiven a target amount D and two bill denominations P and Q, find the minimum total payment at least D achievable using nonnegative counts of each bill.Hard8Number theoryMath+2No attempts yet0.5s128 MBJudgeable
FractionsGiven a fraction a/b and a bound c, find fractions a1/b1 <= a/b <= a2/b2 with denominators at most c that minimize a2/b2 - a1/b1.Hard8Number theoryMath+2No attempts yet2s128 MBJudgeable
Minimum Resistor NetworkFind the minimum number of 1-ohm or 2-ohm resistors combined via series and parallel connections to achieve an exact resistance a/b, capped at 16 or else -1.Hard8MathRecursion+2No attempts yet2s128 MBJudgeable
Monkey TowerCompute the minimum number of moves to solve a 4-peg Tower of Hanoi with up to one million disks, using the Frame-Stewart recurrence modulo 9901.Hard8Dynamic programmingMath+2No attempts yet2s128 MBJudgeable
Complete Binary TreeGiven two same-height complete binary trees whose leaves carry a permutation of labels, find the largest label subset whose pairwise leaf distances match in both trees.Hard8Dynamic programmingTree+2No attempts yet5s128 MBJudgeable
Marble SlabsFind the minimum wasted area when guillotine-cutting a rectangular slab into a set of allowed non-rotatable rectangle sizes.Hard8Dynamic programmingDivide and conquer+2No attempts yet2s128 MBJudgeable
Palindrome EncodingGiven a binary string, repeatedly delete the second half of any even-length palindromic substring and find the minimum length achievable.Hard8Dynamic programmingString+2No attempts yet2s128 MBJudgeable
Banknotes for a New GameChoose K denominations starting at 1 won where each next one is 2, 3, 4, or 5 times the previous, to minimize the number of banknotes summing to N won.Hard8Dynamic programmingMath+2No attempts yet2s128 MBJudgeable
Broadcast NetworkPick which edges of a rooted tree to install so that total user fees minus installation cost stays non-negative while maximizing the number of served users, solved with tree knapsack DP.Hard8Dynamic programmingTree+2No attempts yet2s128 MBJudgeable
PrevtreeGiven the display code sequence (leaf-counts of root and left-children) of a strict binary tree, reconstruct the tree and output the lexicographically previous valid display code with the same leaf count, or 0 if none exists.Hard8TreeRecursion+2No attempts yet2s128 MBJudgeable
Tower of HanoiGiven Tower of Hanoi disks split validly across three rods, find the target rod and minimum moves (mod 1,000,000) to gather all disks on one rod.Hard8GreedyMath+1No attempts yet2s128 MBJudgeable
Here-ThereGiven a Sierpinski-carpet-like fractal board built by recursively removing center squares, compute the shortest grid path length between two given cells avoiding removed regions.Hard8BFSRecursion+2No attempts yet2s128 MBJudgeable
Number of Expression ValuesCount the distinct values an unspaced digit/operator string can yield when each subexpression is parsed as prefix, infix, or postfix.Hard8Dynamic programmingString+2No attempts yet2s128 MBJudgeable
Cutting the Stone SlabCount the number of ways to repeatedly cut an N x N stone slab with alternating horizontal/vertical straight cuts so every final piece has no impurity and exactly one crystal.Hard8Dynamic programmingRecursion+2No attempts yet2s128 MBJudgeable
Last Non-Zero Factorial Digit 2Compute the last nonzero digit of N! for an N with up to 100 digits, requiring a modular recursive formula rather than direct computation.Hard8MathNumber theory+1No attempts yet1s128 MBJudgeable
Antarctic ScientistsCompute the exact character count needed to render an ASCII family tree with fixed box drawing and branching link rules given a forest with up to two children per node.Hard8TreeRecursion+2No attempts yet1s128 MBJudgeable
Repetition-Free FormulaParse a Boolean formula that may repeat variables, determine if the underlying function is read-once, and if so print its canonical repetition-free formula.Hard8RecursionString+2No attempts yet2s64 MBJudgeable
Billing TablesGiven an ordered old billing table with range-based prefix rules, build the minimal prefix-only dictionary table (no prefix a prefix of another) that reproduces exactly the same plan decisions for all 11-digit numbers.Hard8TrieGreedy+2No attempts yet1s128 MBJudgeable
Hardwood CuttingGiven a labeled grid board, compute the maximum number of pieces separable by straight guillotine-style cuts starting from exposed edges, accounting for pieces that interlock and cannot be separated.Hard8SimulationRecursion+2No attempts yet1s128 MBJudgeable
Telephone NetworkRoute m disjoint input-output requests through a recursive Clos-like network of binary switches, choosing at each layer the lexicographically smallest routing bit string.Hard8GraphGreedy+2No attempts yet2s128 MBJudgeable
Term GeneratorParse a formula, convert it to a normal form by expanding nested sums and products according to given rewriting rules, then implement a cyclic generator that outputs requested numbers of terms, some possibly skipped without printing, based on huge signed counters.Hard8String matchingRecursion+2No attempts yet1s128 MBJudgeable
Proof GeneratorConvert a logical formula to a canonical disjunctive normal form using given rewrite rules, then cyclically output the k-th next satisfying terms under given axioms for a sequence of queries.Hard8String matchingRecursion+2No attempts yet1s128 MBJudgeable
Matrix CalculatorParse and evaluate a matrix expression language with block matrices, transpose, indexing, and modular arithmetic, printing each assignment's resulting matrix.Hard8RecursionMatrix+2No attempts yet1s128 MBJudgeable
Mobile ComputingBuild every possible binary mobile from given stone weights and pick the widest one whose width is strictly less than a given room width, output as reduced fraction.Hard8RecursionBacktracking+2No attempts yet1s128 MBJudgeable
Rotate to RootGiven a binary tree, compute the height of the tree after each node is rotated to the root one at a time.Hard8TreeDFS+2No attempts yet1s128 MBJudgeable
GangsRank all lattice paths of E and S steps from (1,1) to the diagonal at (N,N) by a recursive 'OG' order, and output the run at rank M or ERROR.Hard8CombinatoricsDynamic programming+2No attempts yet1s128 MBJudgeable
TreequivalenceGiven two textual tree notations, decide whether they describe the same unrooted planar drawing, allowing any root and cyclic order around each vertex.Hard8TreeHash map+2No attempts yet1s128 MBJudgeable
Hilbert CurveCount how many points the n-th Hilbert curve shares with a given horizontal segment whose endpoints are grid multiples of 1/2^n.Hard8RecursionDivide and conquer+2No attempts yet1s128 MBJudgeable
Split WindowsGiven a preorder traversal of a split tree, draw the minimum-sized grid whose boundaries match the layout, applying proportional rounding at each split.Hard8TreeRecursion+2No attempts yet1s128 MBJudgeable
Function OverloadingParse nested overloaded function calls; for each, determine whether resolution is unique, impossible, or ambiguous, counting ambiguity cases up to 1000.Hard8Dynamic programmingImplementation+2No attempts yet2s128 MBJudgeable
ASCII ExpressionParse a multi-line monospace arithmetic expression into its syntax tree, then evaluate it modulo the prime 2011 with modular inverses for fractions.Hard8ImplementationRecursion+2No attempts yet1s128 MBJudgeable
Dr. Podboq, or: How We Became AsymmetricRead a binary tree of cells, define each cell's left-right similarity by shared subtree shapes up to child swaps, then reorder children by asymmetry and print the normalized tree.Hard8TreeDFS+2No attempts yet1s128 MBJudgeable
VectorsParse and evaluate a small language over scalars and 3D vectors, including mixed operators and bracket styles that can close several open groups at once.Hard8ImplementationRecursion+2No attempts yet1s128 MBJudgeable
FoldGiven the sequence of A/V fold directions along an unfolded paper strip, find the minimum number of all-layer folding steps that produce it.Hard8Dynamic programmingRecursion+2No attempts yet1s128 MBJudgeable
Tree InsertionsCount how many permutations of a given sequence build the same binary search tree; values may repeat and answers need big integers.Hard8TreeCombinatorics+2No attempts yet1s128 MBJudgeable
Manelzuma's RevengeGiven a recursive square-substitution rule, answer queries that print a rectangular window of one generated fractal iteration.Hard8RecursionDivide and conquerNo attempts yet1s128 MBJudgeable
Conditional StatementsParse a small nested if language, then for each checkpoint decide which variable assignments can reach it and print the forced true/false variables or unreachable.Hard8SimulationImplementation+2No attempts yet10s128 MBJudgeable
Order of TreesGiven n, print the n-th binary tree under a canonical ordering by node count and by (left subtree number, right subtree number) recursively.Hard8CombinatoricsDynamic programming+2No attempts yet1s128 MBJudgeable
ExpressionsFor each range of digits and target, print every fully bracketed expression over the digits in order that evaluates to the target. (Note: summary must be one sentence, at most 160 chars.)Hard8BacktrackingRecursion+2No attempts yet1s128 MBJudgeable
Tree SimilarityGiven two ordered rooted trees, find the minimum number of node relabel, delete, and insert operations to turn the first tree into the second.Hard8Dynamic programmingTree+2No attempts yet3s128 MBJudgeable
WalawehEach Walaweh list W_L is built from W_{L-1} by a fixed 8-step cycle of append/prepend and optional reversal operations; convert between (length, index) and the binary string. The recursion only needs O(log N) work per level, but the reversal and leading-zero handling make the index bit-mapping non-obvious.Hard8RecursionBit manipulation+2No attempts yet1s128 MBJudgeable
Ternary TreesLabel the leaves of a complete ternary tree so that, given a fixed query order, the leaf values stay hidden until every leaf is asked.Hard8TreeRecursion+2No attempts yet1s128 MBJudgeable
C-algaeDecide whether each given undirected graph can be built from single vertices by disjoint union and complete join.Hard8GraphDivide and conquer+2No attempts yet3s128 MBJudgeable
Painter's StudioCount the number of positions where a hole in one self-similar fractal matrix coincides with a hole in the same matrix shifted by (x, y).Hard8Divide and conquerRecursion+2No attempts yet1s128 MBJudgeable
Words 2Given exponents k1..kn, find the smallest m such that the concatenation of h_k(0) is a substring of h_m(0), or report NIE.Hard8StringRecursion+2No attempts yet1s128 MBJudgeable
WordsGiven indices k_i, decide whether the concatenation of the words h^{k_i}(0) appears as a substring of some h^m(0).Hard8StringDynamic programming+2No attempts yet1s128 MBJudgeable
Tree Rotations 2Given a binary tree with distinct leaf labels, rotations swap children at any node; find the minimum possible inversion count of the leaf sequence.Hard8Divide and conquerRecursion+2No attempts yet1s128 MBJudgeable
Fibonacci RepresentationFor each query k, find the fewest Fibonacci numbers whose signed sum (plus or minus, repeats allowed) equals k.Hard8Dynamic programmingMath+2No attempts yet3s128 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
TrailsFor each axis-aligned unit-height tape, count the connected pieces of the bytecurve of order n that lie inside the rectangle.Hard8Divide and conquerRecursion+2No attempts yet1s128 MBJudgeable
DivisorsGiven n and an expression built from divisors of n with gcd and lcm, decide whether the expression's value is the same for every assignment of variables.Hard8Number theoryTree+2No attempts yet2s512 MBJudgeable
Hossa (Bull Market)Given a hossa permutation, output the next hossa in the defined recursive order.Hard8CombinatoricsRecursionNo attempts yet1s128 MBJudgeable
HarvardAssign each variable of a program with nested repeats to a memory bank within capacity to minimize access and select costs.Hard8BacktrackingDynamic programming+1No attempts yet10s128 MBJudgeable
Digital OnionGiven a balanced parentheses string, output the string that comes next in the defined price order.Hard8CombinatoricsRecursion+1No attempts yet1s128 MBJudgeable
Exponential TowersGiven a power tower a^(b^c), count the towers of height at least 3 with bases above 1 that evaluate to the same value.Hard8Number theoryCombinatorics+1No attempts yet2s128 MBJudgeable
Euler's ProblemGiven n, list every x with Euler phi(x) equal to n in increasing order, or report none.Hard8Number theoryBacktracking+1No attempts yet1s128 MBJudgeable
Cactus GeneratorParse the SCGL definition, build the cactus it describes with merged vertices renumbered, and print the counts, path cover number, and sorted edges.Hard8GraphUnion-find+2No attempts yet1s256 MBJudgeable
Make a superpalindromeGiven a lowercase string, find the smallest superpalindrome of the same length that comes after it in lexicographic order.Hard8StringRecursion+1No attempts yet1s16 MBJudgeable
Last eight digits of a power towerGiven a and b, print the last eight digits of the b-level power tower of a, keeping leading zeros for large values.Hard8Number theoryMath+1No attempts yet1s256 MBJudgeable
Birthday Numbers IIAdd up the products of every neighboring pair among the integers between x and y that use only the digits 3, 5 and 8, and report the total modulo 19980305.Hard8MathRecursion+2No attempts yet1s256 MBJudgeable
Googlander (Large)Count the distinct self-avoiding walks on an R by C grid that start at the bottom left facing up and at each step go straight or turn right.Hard8Dynamic programmingRecursion+1No attempts yet5s512 MBJudgeable
Power SwapperCount the ordered sequences of aligned block swaps, using each size at most once, that sort the given permutation.Hard8Divide and conquerRecursion+1No attempts yet5s512 MBJudgeable
Alternative Bracket NotationConvert a balanced bracket string into the shortest alternative notation, where each pair's header gives absolute start and end indices of its contents.Hard8Dynamic programmingTree+2No attempts yet10s512 MBJudgeable
XOR SequenceChoose B in [0, N-1] to XOR every element of A, then find the maximum possible count of index pairs i < j with C_i < C_j.Hard8Divide and conquerBit manipulation+2No attempts yet2s512 MBJudgeable
ExponialCompute n^(n-1)^(...^1) modulo m for n and m up to 1e9, a tower too tall to build.Hard8Number theoryRecursion+1No attempts yet2s512 MBJudgeable
Memory CellBuild the expression tree, find the largest pair of disjoint identical subtrees, and print the loser's postfix in lexicographic order.Hard8StackTree+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
Power towersGiven lists of positive integers, compute each power tower modulo M, where the tower can be astronomically large.Hard8Number theoryRecursion+2No attempts yet2s512 MBJudgeable
WalkA fractal tiling is built by repeated splits; given a start cell and a walk, report for each move whether he crossed between tiles.Hard8Divide and conquerRecursion+2No attempts yet2s512 MBJudgeable
ExpressionParse a two-dimensional rendering of nested fractions, additions, multiplications, and divisions, then print the reduced value as a fraction.Hard8ImplementationRecursion+2No attempts yet2s512 MBJudgeable
String TableBuild a table whose cells are huge concatenated strings defined by comparing neighbors, then print 50 characters from a given position of the final cell.Hard8Dynamic programmingString+2No attempts yet2s512 MBJudgeable
ProtocolStarting from one wire of capacity N, each year every wire splits into two wires transformed by two quadratic polynomials, and after M years we need the sum of 112345 raised to each wire's capacity, mod 1e9+9.Hard8MathDivide and conquer+2No attempts yet2s256 MBJudgeable
Alien microbesCount the breeding patterns over H days starting from one microbe, where each day the microbes alive produce children with a total of at most W.Hard8Dynamic programmingCombinatorics+2No attempts yet2s256 MBJudgeable
Booming BusinessCount ordered rooted trees with exactly w nodes and height exactly h, modulo 1e9+7, where children of each node are an ordered sequence.Hard8Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Balloon WarehouseSimulate repeated insertions into an infinite balloon line, then report the colors at positions l to r-1 after all instructions.Hard8TreeDFS+2No attempts yet7s512 MBJudgeable
Boom!Count the ways to fold a strip of N segments so that no two chemically coated faces touch.Hard8Dynamic programmingCombinatorics+1No attempts yet2s512 MBJudgeable
POPABuild a binary tree on indices with inorder order 0..N-1 and parent weights dividing child weights, using at most Q gcd-equality queries on hidden subarrays.Hard8Divide and conquerTree+2No attempts yet1s512 MBJudgeable
ParenthesesClassify a C arithmetic expression as error, proper, or improper depending on validity and the minimality of its parentheses.Hard8StackRecursion+2No attempts yet1s512 MBJudgeable
Adding ParenthesesParenthesize a single-digit expression with non-nested single-operator parentheses to maximize its left-to-right value.Hard8Dynamic programmingRecursion+2No attempts yet0.5s512 MBJudgeable
Add Parentheses 3Parenthesize an alternating digit and +,-,* expression of length up to 19 to maximize its value, respecting left-to-right and multiplication-first rules.Hard8Divide and conquerDynamic programming+2No attempts yet1.5s512 MBJudgeable
Identity FunctionGiven N, find the smallest positive k with every iterate F_k(a)=a for 1<=a<N under f(a)=a^N mod N, or output -1.Hard8MathNumber theory+1No attempts yet5s512 MBJudgeable
Pear-wise VotingGiven ranked ballots and a selectable candidate order, decide for each candidate whether some agenda makes that candidate win sequential pairwise contests.Hard8Bit manipulationDynamic programming+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
String ProcessingDecide whether a recursive split-and-swap program can turn string S into T, and if so output the 2^k - 1 bit program.Hard8Divide and conquerString+2No attempts yet2s512 MBJudgeable
QuadtreeGiven a 2^n by 2^n binary matrix and a budget k, flip at most k entries so the resulting matrix has a quadtree with the fewest possible cells.Hard8TreeDynamic programming+2No attempts yet2s512 MBJudgeable
Tree RotationCompute the minimum number of restricted tree rotations (at the root or root's right child) to transform one 0-2 binary tree's shape into another and output a valid rotation sequence.Hard9TreeGraph+2No attempts yet1s128 MBJudgeable
Ground WorksSimulate water filling inside the region enclosed by a rotated Hilbert curve fractal against a tilted ground line, accounting for trapped air pockets, and output the flooded area to four decimals.Hard9GeometrySimulation+2No attempts yet3s256 MBJudgeable
K’ak’-u-pakal and the Maya ScriptParse a recursive grammar for Maya glyph compositions and render a minimal-size ASCII-art box layout respecting horizontal/vertical grouping and bracket-doubling size rules.Hard9RecursionString+2No attempts yet1s128 MBJudgeable
Beneš Network RoutingGiven a required permutation between top and bottom computers of a recursively defined Beneš network, determine the lexicographically smallest sequence of switch settings that realizes it.Hard9Divide and conquerGraph+2No attempts yet1s128 MBJudgeable
Very Boring HomeworkInsert N keys into a BST, lay out its ASCII drawing, and report up to 5 small rectangular fragments of the picture.Hard9TreeImplementation+1No attempts yet2s128 MBJudgeable
Structural IsomersCount the number of distinct alkane carbon skeletons (free trees in which every node has degree at most 4) with n carbon atoms.Hard9Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable