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,786 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Making a TriangleGiven up to 40 sticks, partition all of them into three groups whose summed lengths form a triangle, maximizing the triangle's area via Heron's formula.Medium6Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Nonlinear SequencesCount and list increasing length-L sequences from 1..M containing no three-term arithmetic progression, printing the first three lexicographically and the total count.Medium6BacktrackingCombinatorics+1No attempts yet2s128 MBJudgeable
Seat ArrangementCount the ways to seat N-1 ticket holders into N seats, given one free seat, so that each person sits in their own, adjacent, or the free seat.Medium6Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Mayor Election PostersGiven n posters pasted in order over intervals on a huge wall, count how many posters remain at least partially visible after later posters overlap earlier ones.Medium6Segment treeCombinatorics+2No attempts yet1s192 MBJudgeable
Collecting ItemsCount monotone right/up paths from bottom-left to top-right on a grid that must pass through every item cell and avoid obstacle cells.Medium6CombinatoricsDynamic programming+1No attempts yet2s128 MBJudgeable
Pebble Game of ChanceCount the sequences of N wheel spins whose cumulative pebble cost never exceeds K, modulo 42043.Medium6Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
Building ColumnsCount distinct stacked-cube columns from four dice-like cubes where each column's four side faces show all four colors, up to rotation about the vertical axis.Medium6Brute forceCombinatorics+1No attempts yet1s128 MBJudgeable
Rascal TriangleGiven a recursively defined 'Rascal triangle' with a division-based rule, compute R(n,m) efficiently for n,m up to 50,000 across up to 1000 queries.Medium6MathCombinatorics+1No attempts yet1s128 MBJudgeable
Maximum Cycle Value of 1Given n and k, count permutations of 1..n whose cycle containing element 1 has maximum element exactly k.Medium6CombinatoricsMath+1No attempts yet1s128 MBJudgeable
Recursive Palindrome PartitionsCount recursive palindrome partitions of N, where a partition is valid if it is a palindrome and both halves are recursively valid.Medium6Dynamic programmingRecursion+2No attempts yet1s128 MBJudgeable
Tile FillingCount the number of ways to tile a 4×N board with 2×1 dominoes for multiple queries, bounded so the answer fits in a 32-bit integer.Medium6Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
Press to UnlockCount the number of ordered sequences of disjoint nonempty subsets (a set partition of any subset of buttons into an ordered sequence of blocks) for given B up to 11.Medium6CombinatoricsMath+1No attempts yet1s128 MBJudgeable
No-Fold Hold'emGiven hole cards and four community cards in Texas Hold'em, find which possible river cards make you win, or otherwise tie, else print LOSER.Medium6Brute forceSimulation+2No attempts yet1s128 MBJudgeable
Childhood Toy BoxesCount subsets of N boxes (as bitmasks over M<=20 toy types) whose union covers all M types, modulo 1e9+7.Medium6Bit manipulationDynamic programming+2No attempts yet2s128 MBJudgeable
Square CrosswordCount distinct ways to pick four distinct equal-length words to fill a square crossword so top/bottom rows and left/right columns match corner letters.Medium6Hash mapBrute force+2No 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
Difficulty-Based Problem SelectionCount ways to pick exactly one problem per difficulty level 1..N given fixed-difficulty and flexible dual-difficulty problem pools, modulo 1e9+7.Medium6Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Digit Sum in an IntervalCount integers in [A,B] with a given digit sum and output the smallest such integer, for bounds up to 10^15.Medium6Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
ConfusionCount permutations of 1..N with exactly C inversions, modulo 1e9+7, using DP with prefix sums for the given constraints.Medium6Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
Agent Mission AssignmentGiven an N x N matrix of success percentages, assign one mission per agent to maximize the product of chosen probabilities, essentially an assignment problem with a product (log-sum) objective.Medium6Dynamic programmingBit manipulation+1No attempts yet1s128 MBJudgeable
LadderGiven a target permutation for a ladder game, find the minimum number of horizontal rungs (adjacent-position swaps) needed to realize it.Medium6GreedyCombinatorics+1No attempts yet1s128 MBJudgeable
Tournament Rank RangeGiven a single-elimination bracket's match winners, determine each queried player's best possible and worst possible final ranking consistent with the known beat relations.Medium6TreeDFS+1No attempts yet1s128 MBJudgeable
Beautiful NamesCount the number of orderings of N distinct strings such that all strings sharing a common prefix always form a contiguous block, modulo 1e9+7.Medium6TrieCombinatorics+1No attempts yet1s512 MBJudgeable
Grid Job SchedulingGiven an N x N grid where cell (x,y) needs its left and top neighbors done first and K computers process jobs in parallel, compute the minimum total seconds to finish all cells.Medium6MathCombinatorics+1No attempts yet1s128 MBJudgeable
Permutation RankGiven a permutation and many swap queries, compute the lexicographic rank modulo 1e9+7 for each swapped permutation efficiently.Medium6CombinatoricsSegment tree+1No attempts yet2s128 MBJudgeable
Vandalized ChessboardGiven a board size and a blackened row, column, and two diagonals, compute the number of distinct blackened cells and how many should be repainted grey versus white based on the checkerboard color rule.Medium6MathCombinatorics+1No attempts yet1s128 MBJudgeable
BingoGiven a fixed call sequence, place numbers 1..N^2 on an NxN board to maximize how many rows exactly match some N-length window of consecutive calls in order.Medium6CombinatoricsBrute force+1No attempts yet1s128 MBJudgeable
PatternCount unit squares with max(x,y) odd inside a large rectangle using a closed-form counting formula instead of brute force.Medium6MathCombinatorics+1No attempts yet1s128 MBJudgeable
Pizza DeliveryChoose at most K of M candidate sites to maximize the total population within radius R, counting each building once even if covered multiple times.Medium6CombinatoricsBrute force+1No attempts yet1s128 MBJudgeable
TeamsCount ways to split N players into two equal-size teams so that no player shares a team with anyone on his exclusion list, treating the two teams as unordered.Medium6Union-findCombinatorics+1No attempts yet1s128 MBJudgeable
Arranging CardsGiven C≤4 colors with N cards each in a hand sequence, find the minimum number of single-card moves to reach some arrangement where colors form contiguous ascending-value blocks in any color order.Medium6Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
A Huge TowerCount the number of orderings of N distinct blocks into a tower, respecting a size-tolerance stacking rule, modulo 1e9+9.Medium6SortingCombinatorics+1No attempts yet1s128 MBJudgeable
Tennis ClubGiven each player's required match count, decide if a simple graph (no self loops, no repeated edges) with that exact degree sequence exists, typically via the Erdős–Gallai theorem.Medium6GreedyMath+1No attempts yet1s128 MBJudgeable
ExpressionsCount balanced parenthesis strings of a given total length that have exactly a given maximum nesting depth.Medium6Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Stack Machine ProgrammerGenerate a stack-machine program that maps up to five given small input-output integer pairs to their exact outputs under strict operand and stack constraints.Medium6SimulationMath+2No attempts yet1s128 MBJudgeable
Justice for AllGiven a k x k 0/1 trust matrix (k up to 20), count the number of perfect matchings between knights and horses, i.e. the permanent of the matrix.Medium6Dynamic programmingBit manipulation+1No attempts yet1s128 MBJudgeable
The Game of Master-MindGiven past Mastermind guesses and their black/white hints, find the lexicographically smallest secret code consistent with all hints or report impossibility.Medium6Brute forceCombinatorics+1No attempts yet1s128 MBJudgeable
Commedia dell'arteDetermine whether a 3D M^3 sliding puzzle can be restored to its solved state given its parity/permutation solvability rules.Medium6MathCombinatorics+1No attempts yet1s128 MBJudgeable
Cube ColoringGiven six unordered face-vision descriptions of a cube, reconstruct the lexicographically smallest assignment of colors to the six numbered faces that reproduces the vision multiset, or report impossibility.Medium6Brute forceCombinatorics+1No attempts yet2s512 MBJudgeable
Java CertificationGiven rounded per-category percentages and totals, find n_i and w_i values reproducing them while minimizing the spread between the largest and smallest category size.Medium6Brute forceMath+1No attempts yet1s128 MBJudgeable
Unit Squares Along a DiagonalGiven N, count unordered integer side pairs (a,b) such that a+b-gcd(a,b) equals N, using the diagonal-crossing formula for a grid rectangle.Medium6Number theoryMath+1No attempts yet1s128 MBJudgeable
ExpectationCompute the exact expected value (as a reduced fraction) of the XOR of two independent uniform random integers in [0, n-1), for up to 1000 values of n up to 1e9.Medium6Bit manipulationMath+1No attempts yet2s64 MBJudgeable
TichuGiven a 13-card Tichu hand, compute the minimum number of legal combinations (singles, pairs, triples, quads, full houses, straights) that partition the hand.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Video PokerGiven a poker payout table and a five-card hand, compute the exact fraction expected value of the best discard strategy over all 32 subsets of held cards.Medium6Brute forceCombinatorics+2No attempts yet1s128 MBJudgeable
Youth Hostel DormFind the maximum number of beds that can be placed in an l by w grid so every bed stays reachable from a single boundary entrance via floor tiles.Medium6CombinatoricsGreedy+1No attempts yet1s128 MBJudgeable
Sudoku TransformationDetermine whether a completed sudoku board can be turned into another via rotations, band/stack swaps, row/column swaps, and digit relabeling.Medium6Brute forceSimulation+1No attempts yet1s128 MBJudgeable
The Lucky NumbersCount lucky numbers (digits 4 and 7 only) in [A,B], plus lucky numbers outside the range whose digit-reversal lands inside it, for B up to 10^47.Medium6CombinatoricsMath+1No attempts yet1s128 MBJudgeable
The RobberyGiven N item types where type k has exactly k identical copies, pick copies within a weight budget M to maximize total value (bounded knapsack with huge M and small N).Medium6Dynamic programmingCombinatorics+1No attempts yet3s128 MBJudgeable
Sky CodeGiven up to 10000 star IDs, count the 4-element subsets whose greatest common divisor equals 1, using Mobius inversion over divisor counts.Medium6Number theoryCombinatorics+1No attempts yet1s128 MBJudgeable
Lucky NumbersCount numbers in [A,B] up to 10^12 expressible as products of one or more lucky numbers made only of digits 4 and 7, across many queries.Medium6MathNumber theory+1No attempts yet1s128 MBJudgeable
Determinant of the GCD MatrixGiven a divisor-closed set of numbers, compute the determinant of the pairwise-gcd matrix modulo 1e9+7 using Smith's theorem via Euler's totient function.Medium6Number theoryMath+1No attempts yet1s128 MBJudgeable
Crazy Tea PartyGiven n people seated around a circular table, compute the minimum number of adjacent swaps needed to reverse the circular seating order, for many test cases.Medium6MathCombinatorics+1No attempts yet1s128 MBJudgeable
Binary PolynomialsGiven a Boolean function's polynomial coefficients over n variables, count vectors with exactly k ones that make the function evaluate to 1.Medium6Bit manipulationCombinatorics+2No attempts yet1s128 MBJudgeable
CountdownFind the closest achievable value to a target by combining six given numbers with the four operations, keeping intermediate results positive integers.Medium6Brute forceRecursion+1No attempts yet1s128 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
Colored CubesGiven up to four cubes with colored faces, find the minimum number of face repaints so all cubes become identical under rotation.Medium6Brute forceSimulation+1No attempts yet3s128 MBJudgeable
Hongjun's Royal GuardCount permutations of N distinct elements where every interior element is a local extremum (both neighbors larger or both smaller); N is at most 20.Medium6Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Powers of ThreeGiven n, list the elements of the n-th smallest subset of powers of 3 when subsets are ordered by their sums.Medium6MathCombinatorics+2No attempts yet1s128 MBJudgeable
Sang-geun's LockCount the number of height-balanced binary trees with N nodes, print the last 9 digits padded to width 9.Medium6Dynamic programmingRecursion+1No attempts yet1s128 MBJudgeable
I'm Attacking the Darkness!Parse a dice expression with up to six dice and integer modifiers, then compute the reduced fraction of outcomes whose total meets or beats a target value.Medium6Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
Bingo!Given column draw counts and X candidate 5x5 patterns, combine any Y of them into winning patterns and find the fewest additional draws that make some pattern fully markable.Medium6Brute forceCombinatorics+2No attempts yet1s128 MBJudgeable
Black ViennaGiven each player's hand, the hidden gang, and records of interrogations, find the earliest turn after which at least one player can deduce the gang from their own cards and the answers.Medium6Brute forceCombinatorics+2No attempts yet1s128 MBJudgeable
RobotsGiven garbage cells in a grid, robots walk from the northwest corner to the southeast corner moving only east or south; find the fewest robots that collect all garbage.Medium6Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
Not One Bit MoreCount integers in [LO, HI] whose repeated popcount chain reaches 1 at exactly step X, with LO up to 1e18 and X up to 10.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
StringerGiven fixed counts of each of N letters, find the K-th string in alphabetical order among all arrangements, without listing them.Medium6CombinatoricsMath+2No attempts yet1s128 MBJudgeable
PillsCount how many distinct sequences of W and H can appear as a bottle of N pills is emptied, two halves per pill.Medium6Dynamic programmingCombinatoricsNo attempts yet1s256 MBJudgeable
KnotsFor each even N up to 100, find the probability that two random perfect matchings on N points form a single cycle.Medium6CombinatoricsMath+1No attempts yet1s128 MBJudgeable
Complaint SortGiven a sequence of n values, count the strictly decreasing subsequence triples (i < j < k with a_i > a_j > a_k).Medium6ArrayCombinatorics+2No attempts yet1s256 MBJudgeable
Sanggeun Trapped in a MazeCount closed walks of length n on an infinite hexagonal lattice starting and ending at one room.Medium6CombinatoricsDynamic programming+1No attempts yet1s128 MBJudgeable
Beach PartyGiven preference orders over music styles, assign distinct styles to s stages so that the most people share the stage you attend.Medium6Brute forceCombinatorics+2No attempts yet1s128 MBJudgeable
Average Value SequenceGiven a non-decreasing average sequence m of length n, count the integer sequences s of length n+1 whose adjacent averages equal m.Medium6MathCombinatorics+2No attempts yet5s256 MBJudgeable
Car ParkingGiven a row of cars and W workers, find the minimum number of cars that must change places so the types are sorted ascending.Medium6GreedyDynamic programming+1No attempts yet1s128 MBJudgeable
Binary MatrixGiven a binary matrix, flip the fewest entries so every row has the same number of 1s and every column has the same number of 1s, or report that it is impossible.Medium6GreedyCombinatorics+2No attempts yet5s128 MBJudgeable
Counting DigitsFor each query range [A, B], count how many times each decimal digit 0 through 9 appears in all integers written out from A to B.Medium6MathImplementation+2No attempts yet1s128 MBJudgeable
Drop the TriplesPlayers alternate drawing cards from a stock and may drop valid triples; each maximizes perfect triples then common triples. Report the winner or a tie.Medium6GreedyDynamic programming+2No attempts yet1s128 MBJudgeable
Balanced Cow BreedsCount the ways to 2-color the parentheses in a string so that each color class, read in order, forms a balanced parenthesis sequence.Medium6Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Dividing the GoldGiven N coins with values, find the minimum difference between two piles and count the subsets forming the lighter pile, modulo 1,000,000.Medium6Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Mixed Up CowsCount permutations of N serial numbers (N at most 16) where every adjacent pair differs by more than K.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
ChocolateFor C equally likely colors, after N draws where matching pairs are eaten, find the probability that exactly M colors remain on the table.Medium6Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Bulls and CowsCount binary sequences of length N where every pair of bulls has at least K cows between them, modulo 5000011.Medium6Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Cow Frisbee TeamCount the nonempty subsets of N cows whose rating sum is divisible by F, modulo 100000000.Medium6Dynamic programmingMath+2No attempts yet1s128 MBJudgeable
Round NumbersCount integers in [Start, Finish] whose binary form has at least as many zeroes as ones.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
New Cow BrandsGiven each position's allowed distinct letters, list the codes ranked from start to finish in lexicographic order, where no letter repeats inside a code.Medium6BacktrackingCombinatorics+2No attempts yet1s128 MBJudgeable
Ranking the CowsGiven partial comparison results between N cows with distinct milk rates, find the minimum number of additional pairwise comparisons needed to determine the full ranking.Medium6GraphTopological sort+2No attempts yet1s128 MBJudgeable
Xavier Is Learning to CountGiven m distinct positive integers and a size p (at most 5), count for every attainable sum the number of p-element subsets that add up to it, listing sums in increasing order.Medium6Dynamic programmingCombinatorics+2No attempts yet5s512 MBJudgeable
Bonus BondsGiven the next serial number in a region and a digit position, count how many already-sold serials have each digit 0-9 at that position.Medium6MathCombinatorics+1No attempts yet1s128 MBJudgeable
AnagramFor each given word, print every distinct string formed by rearranging its letters, in lexicographic order with duplicates removed.Medium6BacktrackingSorting+2No attempts yet1s128 MBJudgeable
Dihedral GroupsNormalize a run-length abbreviated string of rotations r and reflections m into the unique shortest equivalent sequence under the dihedral group of order 2n.Medium6MathString+2No attempts yet1s128 MBJudgeable
California Jones and the Gate to FreedomGiven n stones and a binary index b, decide whether the chosen n/2 stones are exactly the combination at lexicographic rank b among all size-n/2 subsets.Medium6CombinatoricsMath+2No attempts yet1s128 MBJudgeable
Parallelogram CountingGiven n points, count how many 4-point subsets form a parallelogram by pairing points that share a midpoint.Medium6Hash mapGeometry+2No attempts yet1s128 MBJudgeable
Football LeagueGiven an even number of teams playing a single round-robin over n-1 turns, find the minimum total number of same-venue consecutive pairs across all teams.Medium6MathCombinatorics+2No attempts yet1s128 MBJudgeable
A Decorative FenceGiven N and a rank C, output the C-th alternating (zigzag) permutation of 1..N in lexicographic order.Medium6Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
CouplesGiven N parties and their attendees, count pairs of people who appear together at more than K parties.Medium6Hash mapCombinatoricsNo attempts yet5s128 MBJudgeable
Cutting Out of FactorialsGiven k from 2 to 500, remove the fewest of 1!, 2!, ..., k! so the remaining product is a perfect square, and report that count.Medium6MathNumber theory+2No attempts yet1s128 MBJudgeable
BacteriaEach adult produces one young per second while young mature into adults; find the total population after T seconds modulo K, given initial counts.Medium6MathCombinatorics+2No attempts yet1s1024 MBJudgeable
Burger, French Fries, Soft DrinkCount the ways to cut a B/F/S stream into N consecutive blocks where every block has equal positive counts of each letter, or report Impossible.Medium6Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Add Them UpGiven counts of each digit 1-9, sum every distinct number formable using each digit at most as often as it appears, modulo 1e9+7.Medium6CombinatoricsDynamic programming+2No attempts yet1s128 MBJudgeable
Jack's SocksGiven an undirected graph of similar socks, decide whether a perfect matching exists and is unique, and print that matching if it is.Medium6GraphDFS+2No attempts yet1s512 MBJudgeable
The Fifth DimensionCount ordered simple paths with 6 distinct vertices and 5 edges in an undirected graph.Medium6GraphCombinatoricsNo attempts yet1s128 MBJudgeable
Highway Racing TracksCount the 5-vertex paths (chains of four edges on five distinct vertices) in a simple graph, treating each path as unordered.Medium6GraphCombinatoricsNo attempts yet1s128 MBJudgeable