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
Which is NextGiven a binary tree's numeric identifier under a bijective encoding, compute the identifier of the next tree in a defined ordering among same-size trees, wrapping around if it is the largest.Medium7RecursionMath+1No attempts yet1s128 MBJudgeable
Complicated ExpressionsParse an arithmetic expression with parentheses and reprint it with every redundant parenthesis removed while preserving exact operator precedence and associativity semantics.Medium7StringRecursion+1No attempts yet1s128 MBJudgeable
Auxiliary Question of the UniverseGiven a fragment of an arithmetic expression grammar (numbers, plus, parentheses), find the minimum insertions needed to make it a valid expression while keeping the fragment as a subsequence.Medium7Dynamic programmingString+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
Castle GuardsGiven a recursively described tree of small buildings connected by corridors, compute the minimum vertex cover (guard placement) that watches every corridor in the whole castle.Medium7Dynamic programmingTree+2No attempts yet2s128 MBJudgeable
MobileGiven a recursively nested mobile of weighted objects, find the minimum number of object weights to change so every rod balances left and right.Medium7TreeDynamic programming+1No attempts yet1s128 MBJudgeable
Common PolynomialParse two polynomial expressions with parentheses and exponents, expand them, then compute and print the normalized greatest common divisor polynomial.Medium7MathRecursion+1No attempts yet1s128 MBJudgeable
The Best Name for Your BabyGiven a context-free grammar-like rewriting rule set, find the lexicographically smallest terminal string of exactly length l derivable from start symbol S.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
MobileGiven a full binary tree of rods and toys, find the minimum number of left-right child swaps so that all toys sit at depths differing by at most 1, with deeper toys to the left.Medium7TreeGreedy+2No attempts yet1s128 MBJudgeable
A Foldy but a GoodyFold a paper strip n times by upper and lower folds, unfold it into right angles, and find the coordinates of the m-th point along it.Medium7RecursionDivide and conquer+2No attempts yet1s128 MBJudgeable
BurnoutGiven a nested repeating on/off pattern and a target on-time N, find the elapsed time when total on-time first reaches N.Medium7RecursionSimulation+2No attempts yet1s128 MBJudgeable
Preorder and PostorderCount how many m-ary trees share the given pre-order and post-order traversals.Medium7TreeDynamic programming+2No attempts yet1s128 MBJudgeable
OrigamiGiven up to 8 folds of a square sheet, count how many layers of paper a query point pierces, ignoring points on edges.Medium7GeometrySimulation+2No attempts yet1s128 MBJudgeable
Lightbulb TestingGiven a bulb life n and a periodic on/off pattern (with nested repeating groups), find the real time elapsed when total on-time reaches n.Medium7ImplementationMath+2No attempts yet1s128 MBJudgeable
Syntax IncludedParse each HTML-like string against the given grammar and decide whether it is syntactically valid.Medium7StringRecursion+2No attempts yet1s128 MBJudgeable
Tournament BracketsGiven team pairings listed in column-major order and the champion, reconstruct the tournament bracket and render it with slashes, backslashes, and underscores.Medium7ImplementationSimulation+2No attempts yet1s128 MBJudgeable
Apply a Cold CompressDecode each compression-expression into its smallest pixel picture by parsing split tags and computing the relative scaling of the two halves, then draw the framed grid.Medium7RecursionDivide and conquer+2No attempts yet1s128 MBJudgeable
Walsh MatrixSum entries in one row of a Walsh matrix over columns S through E, where the matrix size 2^N can reach 2^60.Medium7Divide and conquerRecursion+2No attempts yet1s128 MBJudgeable
Functional Programming CountsImplement an interpreter for a tiny functional language with variables, single-parameter functions, and call-count profiling per definition line.Medium7ImplementationSimulation+2No attempts yet1s128 MBJudgeable
Protect Our Treasure!Given each pirate's set of keys, list every minimal group whose union covers all locks, ordered by size then lexicographically.Medium7CombinatoricsBrute force+2No attempts yet1s128 MBJudgeable
Nim/3Three-player Nim where each player has a preferred winner; find player 1's optimal move with smallest stack then smallest count.Medium7Game theoryDynamic programming+2No attempts yet1s128 MBJudgeable
Myth BustersFor each city's list of four-digit carriage IDs, decide whether every ID can reach the value 10 by permuting its digits and inserting +, -, *, / with parentheses.Medium7Brute forceRecursion+2No attempts yet1s128 MBJudgeable
Surveillance CamerasGiven up to 50,000 distinct grid points, decide whether three axis-parallel lines (full rows or columns) can cover all of them.Medium7Brute forceRecursion+2No attempts yet1s128 MBJudgeable
Dreisam EquationsInsert +, -, and * into a number-and-parenthesis equation so it holds under strict left-to-right evaluation, choosing the lexicographically smallest valid string.Medium7BacktrackingImplementation+2No attempts yet1s128 MBJudgeable
Picture PuzzleCount the number of ways to place and rotate nine square pieces into a 3x3 grid so every touching edge pair matches (same letter, one L half and one R half).Medium7BacktrackingBrute force+2No attempts yet1s128 MBJudgeable
Calculator LanguageEvaluate expressions in a tiny language with right-associative equal-precedence operators, assignment, and right-to-left operand evaluation, then report changed variables.Medium7ImplementationRecursion+2No attempts yet1s128 MBJudgeable
Peter's CalculatorParse assignment, PRINT, and RESET statements, evaluate expressions with variables, detect cycles or undefined references, and print values or UNDEF.Medium7ImplementationRecursion+2No attempts yet1s128 MBJudgeable
ExpressionsGiven a postfix expression, produce another postfix expression that the same algorithm evaluates to the same value when a queue replaces the stack.Medium7StackQueue+2No attempts yet1s128 MBJudgeable
Binary Search Heap ConstructionGiven label/priority pairs, build the unique treap (a binary search tree on labels and a max-heap on priorities) and print it in nested parenthesized form.Medium7TreeStack+2No attempts yet1s128 MBJudgeable
Sylvester constructionGiven a Hadamard matrix built by the Sylvester doubling rule, print a small rectangular sub-matrix specified by its top-left corner.Medium7Divide and conquerRecursion+2No attempts yet1s128 MBJudgeable
Lazy and Strict EvaluationGiven function definitions in a small Lisp-like language, count how many times each arithmetic operation runs under lazy (memoized) versus strict evaluation, skipping non-terminating tests.Medium7ImplementationRecursion+2No attempts yet1s128 MBJudgeable
Simplified λ-evaluationsEvaluate simplified lambda-calculus expressions by substitution, stopping after 1000 applications and printing unterminated if it does not finish.Medium7ImplementationSimulation+2No attempts yet1s128 MBJudgeable
S and KGiven binary trees written with S and K, repeatedly apply the two rewrite rules until no rule fires, then print the final tree string.Medium7ImplementationSimulation+2No attempts yet3s128 MBJudgeable
Snowball FightGiven fixed alternating throwing order and hit probabilities, players choose targets to maximize their team's win chance; compute win and draw probabilities under optimal play.Medium7Game theoryProbability+2No attempts yet1s128 MBJudgeable
QuadTreesGiven pre-order strings of two quadtrees for N x N binary images, count the nodes in the quadtree of their pixelwise AND intersection, collapsing uniform quadrants.Medium7TreeDivide and conquer+2No attempts yet1s128 MBJudgeable
Cake CuttingCount the distinct rectangular pieces that can be left after repeatedly halving a cake into two equal halves with equal candle counts.Medium7Divide and conquerRecursion+1No attempts yet1s1024 MBJudgeable
DictionaryGiven a list of words, insert leading spaces so the list satisfies a recursive definition: every maximal run of words sharing a first letter must, after removing the first word and that letter, again be a dictionary.Medium7TrieRecursion+2No attempts yet1s128 MBJudgeable
List CalculatorImplement an interpreter for a small list language with slicing, unary and binary elementwise operators, concatenation, and single-character variable assignment.Medium7ImplementationRecursion+2No attempts yet1s128 MBJudgeable
Bargain or No BargainGiven prize values and a budget M, decide whether optimal play maximizing expected log utility yields expected prize money above M.Medium7Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
Counting Satisfying AssignmentsParse one logical formula and count how many of the 4096 assignments to twelve variables make it true.Medium7ImplementationSimulation+2No attempts yet2s256 MBJudgeable
FloorsGuillotine-cut a rectangle tiled by disjoint rectangles into the smallest possible pieces and output the largest piece's area.Medium7Divide and conquerGeometry+2No attempts yet1s128 MBJudgeable
Printed-Circuit BoardsGiven a series-parallel circuit described recursively, find the minimum number of connections that must be routed on the top side so every unit is reached from the top.Medium7TreeDynamic programming+2No attempts yet3s128 MBJudgeable
ChainGiven which rings of a bytish chain are on a bar, find the minimum number of legal put-on/take-off moves to remove all rings.Medium7Dynamic programmingRecursion+2No attempts yet3s512 MBJudgeable
Binary Search Tree CodeGiven n and k, output the n-th preorder string among all BSTs built from the first k letters, listed in alphabetical order.Medium7TreeRecursion+2No attempts yet1s128 MBJudgeable
The Number of Symmetrical ChoicesGiven two word sequences of length n, count how many of the 2^n ways of picking one word per index produce a palindrome when concatenated.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
TreesGiven a sequence of leaf levels, decide whether it is a valid complete binary tree; if so, output the genealogical and bracket representations.Medium7TreeRecursion+2No attempts yet1s128 MBJudgeable
Algorithm SpeedupDecide whether a recursively defined Boolean function F on two sequences returns 1 or 0, where F strips the longest prefix and suffix that drop some value.Medium7RecursionHash map+2No attempts yet8s128 MBJudgeable
Two-Colored Towers of HanoiThe task is to compute the minimum moves to gather odd disks on peg B and even disks on peg C under Hanoi rules.Medium7Dynamic programmingRecursion+1No attempts yet1s128 MBJudgeable
Up a TreeGiven three garbled preorder, inorder and postorder outputs from mixed-up recursive calls, list every call assignment and the smallest tree that fits each one.Medium7TreeBacktracking+2No attempts yet6s128 MBJudgeable
ChonSuGiven the distances between consecutive leaves of an unknown full binary tree, compute the distance between two specified leaves.Medium7TreeDivide and conquer+1No attempts yet1s128 MBJudgeable
King and PawnPredict whether the king captures the pawn or the pawn escapes on an 8x8 board with forbidden and danger cells when both play best.Medium7Game theoryRecursion+1No attempts yet1s128 MBJudgeable
Making S with two cellsYou start with cells holding a and b, repeatedly add one cell to the other, and must decide whether the value S can ever appear in either cell.Medium7Number theoryMath+1No attempts yet2s128 MBJudgeable
Digital Content ProtectionGiven the hacked leaves of a complete binary key tree, print the identifiers of the smallest set of unexposed node keys covering every intact player.Medium7GreedyTree+1No attempts yet2s128 MBJudgeable
Nested PalindromeFill each question mark with a digit to build the k-th smallest nested palindrome with no equal adjacent digits, or print -1.Medium7RecursionCombinatorics+1No attempts yet2s128 MBJudgeable
Decoding the HallwayFor each query, decide whether the given string appears as a contiguous substring of the turn record built after n hallway walks.Medium7StringRecursion+2No attempts yet1s128 MBJudgeable
Super AntsAn ant on a grid cell collects its value and spawns clones along eight rays within the remaining time, and you compute the total score modulo 1e9+7.Medium7Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
Switch ArrayFind the fewest restricted toggles that turn each given bit string into all zeros.Medium7RecursionDynamic programming+1No attempts yet1s256 MBJudgeable
Generalized Roman NumeralsGiven a string of Roman letters, list every distinct value it can take under all parenthesizations of the subtract-when-smaller rule.Medium7Dynamic programmingIntervals+1No attempts yet3s256 MBJudgeable
Recursive Function zYou evaluate the recursive function at n/m by tracing its arguments into a repeating cycle and solving the linear equations exactly.Medium7MathGraph+1No attempts yet5s256 MBJudgeable
LRFill each ? with an allowed character to form a valid L and R expression with the largest possible value, or report invalid.Medium7Dynamic programmingString+1No attempts yet2s128 MBJudgeable
Guillotine Card GameCompute each player's final score in a three-player card game where one player secretly plays to minimize another player's score.Medium7Game theoryBacktracking+1No attempts yet3s128 MBJudgeable
Ancient Commemorative MonolithThe program parses each bitmap into nested boxes and glyphs and prints the bracketed transliteration with mirror reading resolved.Medium7MatrixRecursion+2No attempts yet8s256 MBJudgeable
Cutting an L-shaped paperThe program cuts the given L-shaped sheet with guillotine cuts into integer-sided squares with the fewest pieces.Medium7Dynamic programmingGeometry+1No attempts yet2s256 MBJudgeable
Array splittingRepeatedly quarter an N by M array until a side reaches 1, then list each distinct strip length with its count modulo 1234567891.Medium7Divide and conquerRecursion+2No attempts yet1s256 MBJudgeable
Dragon curveReport the cursor position after the Xth drawn segment of the order N dragon curve generated by the given rewriting rules.Medium7RecursionDivide and conquer+2No attempts yet1s256 MBJudgeable
Cutting BrowniesGiven a B by D brownie sheet where Harry cuts depth and Vicky cuts breadth, decide if the named starting player has a forced win.Medium7Game theoryDynamic programming+1No attempts yet2s256 MBJudgeable
Counting Odd Binomial CoefficientsCount the pairs (m, k) with m below n whose binomial coefficient is odd.Medium7Number theoryBit manipulation+2No attempts yet1s256 MBJudgeable
Word by mouthSimulate the recursive WBM(m) vote, where faulty friends always forward cat, and report each loyal friend's majority word.Medium7SimulationDynamic programming+1No attempts yet3s256 MBJudgeable
Hacking the ScreenParse an arithmetic formula with square roots and fractions drawn as ASCII art up to three lines high and print its integer value.Medium7ImplementationRecursion+1No attempts yet1s256 MBJudgeable
Symmetric Trees (Large)Decide whether a color-painted tree can be drawn in the plane with a vertical line of symmetry.Medium7TreeRecursion+2No attempts yet5s512 MBJudgeable
Bacteria Growth (Small)Apply the map x to x^x exactly B times starting from A and report the result modulo C.Medium7Number theoryRecursionNo attempts yet5s512 MBJudgeable
Bacteria Growth (Large)Starting from A bacteria that grow from x to x^x each hour, compute the count after B hours modulo C.Medium7Number theoryRecursion+1No attempts yet5s512 MBJudgeable
Number GameCount the pairs in the given rectangle from which the first player wins the subtraction game where moving to zero or below loses.Medium7Game theoryNumber theory+2No attempts yet5s512 MBJudgeable
Bribe the Prisoners (Small)Choose the release order of Q prisoners out of P cells to minimize total bribes, where each release bribes every still-occupied prisoner reachable from it until a boundary or empty cell.Medium7Dynamic programmingDivide and conquer+2No attempts yet5s512 MBJudgeable
Bribe the Prisoners (Large)Given prison cells in a row and a set of cells to release one per day, choose the release order that minimizes total bribes paid to prisoners who hear the news.Medium7Dynamic programmingDivide and conquer+2No attempts yet5s512 MBJudgeable
Sum of matrix powersCompute A + A^2 + ... + A^B for an N by N matrix A, with B up to 1e11, printing every entry modulo 1000.Medium7Divide and conquerMatrix+1No attempts yet2s512 MBJudgeable
Stephen CookTwo players alternately assign truth values to variables of a boolean formula; Cook moves first and wins if the formula ends true. Decide the winner under optimal play.Medium7Game theoryDynamic programming+2No attempts yet3s256 MBJudgeable
Merging treesGiven a left-handed and a right-handed ternary tree, find the minimum number of vertices in a ternary tree that is a superposition of both.Medium7TreeDynamic programming+1No attempts yet1s512 MBJudgeable
Folding MachineGiven two integer tapes, decide whether folding one tape can ever produce the other.Medium7Divide and conquerRecursion+2No attempts yet2s512 MBJudgeable
Crystal JailsGiven up to 27 small polycube blocks that may be rotated but not reflected, decide whether they tile a W x D x H box exactly.Medium7BacktrackingRecursionNo attempts yet8s512 MBJudgeable
Reading DigitsDecode the given run-length-encoded string k times, then report the digit at index pos of the original string s.Medium7StringImplementation+1No attempts yet0.1s256 MBJudgeable
Combining RiceballsGiven a row of riceballs, merge equal adjacent pairs or equal pairs with one ball between them, and find the largest size reachable.Medium7Dynamic programmingIntervals+2No attempts yet2s512 MBJudgeable
Rather Perplexing Showdown (Large)Find the alphabetically earliest lineup of R, P and S players that lets a single-elimination tournament finish without any tie match.Medium7BacktrackingDivide and conquer+2No attempts yet5s512 MBJudgeable
Mahjong Waiting TilesGiven a 13 tile mahjong hand numbered 1 to 9, list every tile still available that completes the hand into one head plus four bodies, or into seven distinct heads.Medium7BacktrackingRecursion+2No attempts yet1s256 MBJudgeable
Tiling the Shower Floor (Small)Cover a 2^K by 2^K grid with L-shaped trominoes leaving one drain cell open, choosing the lexicographically smallest numbering.Medium7Divide and conquerRecursion+1No attempts yet2s512 MBJudgeable
Grasshopper RouteGiven a tree and two vertices s and t, construct the specific valid Grasshopper route defined by a recursive rule on the path components.Medium7TreeDFS+2No attempts yet1s512 MBJudgeable
Folding SheetsGiven a number X or a position P, determine its counterpart in the sequence produced by folding an N x N sheet in half alternating bottom-over-top and right-over-left until 1 x 1, then reading the resulting column bottom to top. N is 2^K, K up to 31, and there are up to 10000 queries.Medium7RecursionDivide and conquer+2No attempts yet1s32 MBJudgeable
Quick sort cnt++Count the comparisons made by a quicksort that splits each subarray around its middle-index pivot and recurses only on strictly smaller and larger elements.Medium7Divide and conquerRecursion+2No attempts yet2s1024 MBJudgeable
Folding a RibbonGiven the layer index and part index of a marked spot on a ribbon folded n times, output the unique sequence of left and right folds.Medium7RecursionDivide and conquer+2No attempts yet2s512 MBJudgeable
That's One Hanoi-ed TeacherGiven a legal Tower of Hanoi layout, decide whether it lies on the optimal solution path and if so output the remaining moves to the goal.Medium7RecursionDivide and conquer+1No attempts yet2s512 MBJudgeable
ASCII Art TreesFor each prefix-encoded binary tree, draw its ASCII layout using the given slash, bar, and spacing rules and print the resulting character grid.Medium7TreeRecursion+2No attempts yet2s512 MBJudgeable
Vera and SortingCount permutations of size N for which a recursive quicksort-like routine performs exactly K comparison steps, modulo 1e9+7.Medium7Dynamic programmingCombinatorics+2No attempts yet2s256 MBJudgeable
Equals are EqualsParse multivariate polynomial expressions with integer coefficients and decide whether each student answer is equivalent to the reference expression.Medium7StringImplementation+2No attempts yet2s512 MBJudgeable
Balanced TreesCount perfectly balanced trees of weight N, where a tree splits into k identical subtrees each of the largest weight summing within the parent's weight.Medium7TreeNumber theory+2No attempts yet2s512 MBJudgeable
Line-upCount for each soldier, looking left or right, how many nearer soldiers are visible past blocking heights.Medium7StackDivide and conquer+1No attempts yet2s512 MBJudgeable
Nice NumberGiven n up to 10^18, find the smallest integer greater than n with no two equal consecutive digits.Medium7GreedyRecursion+1No attempts yet2s512 MBJudgeable
Hawawa College Student-chan Goes to Hawaii~Count the ways to start at island 1 and visit all n islands exactly once using steps +1, +2, or -1 to new islands, modulo 1,000,000,009.Medium7Dynamic programmingMath+1No attempts yet1s256 MBJudgeable
Arithmetic Without ParenthesesGiven an arithmetic expression without parentheses where all four operators have equal precedence, find the minimum and maximum results over all evaluation orders, using custom integer division rules.Medium7Dynamic programmingRecursion+1No attempts yet1s512 MBJudgeable
Hano-Sam TowerGiven a Hanoi variant with one of three move rules, output the peg holding each disk after K seconds of the optimal solution.Medium7RecursionMath+2No attempts yet1s256 MBJudgeable
Cow EvolutionGiven N distinct feature sets for cow sub-populations, decide whether they can arise from an evolutionary tree in which every feature first appears on exactly one edge.Medium7TreeRecursion+2No attempts yet2s512 MBJudgeable