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
Counting four cyclesCount ordered 4-vertex cycles in an undirected graph given as an N by N adjacency matrix with N up to 250.Medium5GraphCombinatorics+1No attempts yet2s128 MBJudgeable
Dreary DesignCount RGB triples with components from 0 to K whose largest pairwise difference is at most V.Medium5CombinatoricsMathNo attempts yet5s512 MBJudgeable
Password Attacker (Large)Count length-N strings over M symbols that use every symbol at least once, modulo 1e9+7.Medium5CombinatoricsMathNo attempts yet5s512 MBJudgeable
Parentheses Order (Small)Print the k-th valid parentheses string of n pairs in lexicographic order for each test case, or report that it does not exist.Medium5Dynamic programmingCombinatoricsNo attempts yet5s512 MBJudgeable
Parentheses Order (Large)Given n and k, output the k-th valid parentheses string of n pairs in lexicographic order, or Doesn't Exist! when fewer than k exist.Medium5Dynamic programmingCombinatorics+1No attempts yet5s512 MBJudgeable
Trie Sharding (Small)Split up to 8 strings across labeled servers to maximize the summed trie node counts and count the optimal splits.Medium5Brute forceTrie+1No attempts yet5s512 MBJudgeable
Consonants (Large)Count the substrings of each given name that contain at least n consecutive consonants.Medium5StringCombinatoricsNo attempts yet5s512 MBJudgeable
Arithmetic Digit Numbers 2Count the integers from 1 to N, with N up to 10^18, whose decimal digits form an arithmetic sequence.Medium5BacktrackingCombinatorics+1No attempts yet0.5s512 MBJudgeable
Handing out candiesFor every K, count the ways to choose one candy of each brand 1 through K, and print the total over all K.Medium5Dynamic programmingCombinatoricsNo attempts yet2s512 MBJudgeable
Trees and Path Lengths 2Find leaf counts p, q, r on a fixed 4-vertex path so the tree has exactly S length-3 paths, minimizing N then (p,q,r).Medium5MathImplementation+2No attempts yet2s512 MBJudgeable
pqrCount index triples p<q<r whose product A[p]*A[q]*A[r] is divisible by K, for N up to 2000.Medium5CombinatoricsNumber theory+1No attempts yet2s512 MBJudgeable
Counting Music ScoresCount scores over two pitches and two durations with n seconds total, balanced pitch counts, at least as many long notes as short, and alternating pitches starting low.Medium5CombinatoricsDynamic programming+1No attempts yet2s512 MBJudgeable
Distinct rational numbersCount distinct values of a/b with 0 <= a <= b <= N, i.e. fractions in [0,1] with reduced denominator at most N.Medium5MathNumber theory+2No attempts yet2s512 MBJudgeable
WindowPick a uniformly random axis-aligned subrectangle of an H by W grid; find the expected number of cells times 9, modulo 1e9+7.Medium5MathCombinatorics+2No attempts yet1s512 MBJudgeable
Lucky TicketsCount digit strings of length 2N whose first N digits sum to the same value as the last N digits, modulo 1e9+7.Medium5Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
EcologyCompute the probability that exactly M of N birds wear a tracker after D days of catching C random birds each day.Medium5Dynamic programmingProbability+1No attempts yet2s512 MBJudgeable
Fibonacci ChickenGiven N, split it into Fibonacci-derived (people, chicken) pairs whose people counts sum to N, and report the minimum and maximum total chickens.Medium5Dynamic programmingMath+2No attempts yet1s128 MBJudgeable
Hamming EllipsesCount words of length n over a q-symbol alphabet whose Hamming distances to two given words sum to exactly D.Medium5CombinatoricsMath+2No attempts yet5s512 MBJudgeable
Fleecing the RaffleAdd k slips with your name to a box of n slips so the chance your name is drawn exactly once among p draws is maximized.Medium5MathCombinatorics+2No attempts yet2s512 MBJudgeable
Jewelry StoreWith unlimited gems of each of N kinds, list all total values obtainable by choosing exactly K gems.Medium5Dynamic programmingCombinatoricsNo attempts yet5s512 MBJudgeable
Winner of the Bubble GameTwo players alternately swap adjacent out-of-order pairs until the permutation is sorted; the one who cannot move loses. Decide the winner.Medium5CombinatoricsGame theory+1No attempts yet2s512 MBJudgeable
Sum Decomposition 2Count ordered K-tuples of integers between 0 and N whose sum is N, modulo 1,000,000,000.Medium5Dynamic programmingCombinatorics+1No attempts yet1s512 MBJudgeable
Good Positions in a PermutationCount permutations of 1..N whose number of positions i with |P_i - i| = 1 equals a given K, modulo 1e9+7.Medium5CombinatoricsDynamic programming+1No attempts yet2s512 MBJudgeable
LettersGiven index i, return the uppercase letter at position i in the concatenation of all uppercase strings ordered by length then lexicographically.Medium5CombinatoricsMathNo attempts yet0.2s256 MBJudgeable
m-ary PartitionsCount the partitions of n into powers of m, for up to 1000 queries with n up to 10000.Medium5Dynamic programmingMath+2No attempts yet2s512 MBJudgeable
PasswordCount n-digit strings over 0-9 that contain every one of the m given digits at least once.Medium5CombinatoricsMathNo attempts yet1s64 MBJudgeable
Binomial coefficient queriesGiven M pairs N and K, print the binomial coefficient C(N, K) modulo 1,000,000,007.Medium5CombinatoricsMath+1No attempts yet1s512 MBJudgeable
Cities and StatesGiven up to 200,000 cities with names and two-letter state codes, count unordered pairs whose first two name letters match the other city's state code and vice versa, with different states.Medium5Hash mapString+2No attempts yet2s512 MBJudgeable
Vote (Large)Given N supporters of A and M of B in random arrival order, find the probability A leads after every vote; a ballot-problem computation.Medium5CombinatoricsProbability+2No attempts yet5s512 MBJudgeable
Codejamon Cipher (Small)For each enciphered string, count the sentences of vocabulary words whose letter multisets concatenate to it, modulo 1e9+7.Medium5Dynamic programmingHash map+1No attempts yet5s512 MBJudgeable
Sherlock and Parentheses (Small)Given L left and R right parentheses, arrange all of them to maximize the count of balanced non-empty substrings, counted by position.Medium5GreedyMath+2No attempts yet5s512 MBJudgeable
Slides! (Small)Given B up to 6 and M up to 20, decide if exactly M paths from building 1 to B exist, and print the fixed-rule matrix when possible.Medium5CombinatoricsDynamic programming+1No attempts yet5s512 MBJudgeable
What Is Dynamic Programming?Count paths from the top-left cell to the bottom-right cell of an n by m grid when each step moves right, down, or diagonally down-right, printed modulo 1e9+7.Medium5Dynamic programmingMatrix+1No attempts yet2s512 MBJudgeable
Tiling a 2 by N wallCount the ways to tile a 2 by N wall with 2x1, 1x2, and 1x1 tiles, modulo 1e9+7.Medium5Dynamic programmingCombinatoricsNo attempts yet2s512 MBJudgeable
DespojadosCount the divisors of N that are squarefree and have at least two prime factors.Medium5Number theoryCombinatorics+1No attempts yet1s1024 MBJudgeable
TilingCount the ways to tile a 3 by W rectangle with 2 by 1 dominoes, printing the result modulo 1e9+7.Medium5Dynamic programmingCombinatorics+2No attempts yet2s512 MBJudgeable
Birthday CakeGiven up to 50 candle points and up to 15 cuts, decide whether the cuts carve the cake so that every resulting piece holds exactly one candle.Medium5GeometryBit manipulation+2No attempts yet2s512 MBJudgeable
Counting a^i b^j c^k subsequencesCount subsequences of a string of a, b, c that read as some positive number of a's, then b's, then c's, modulo 1e9+7.Medium5Dynamic programmingString+1No attempts yet2s512 MBJudgeable
Xayahh-Rakann at Moloco (Hard)Given n jars with m inseparable pairs, decide whether exactly k jars can be placed in one building so that no inseparable pair is split across the two buildings.Medium5GraphUnion-find+2No attempts yet2s512 MBJudgeable
DunglishGiven a Dutch sentence and per-word dictionary options marked correct or incorrect, output the unique translation and its status, or counts of correct and incorrect translations.Medium5ImplementationMath+1No attempts yet2s512 MBJudgeable
Drain PipesCount the number of ways to pick quantities of each pipe type, within the given stock, so the chosen pipes sum to exactly x.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Uks Is an Apple Fan!!Count the number of paths on an N by M grid where each cell directs movement right, down, or both, and every path must end at cell (N, M).Medium5Dynamic programmingCombinatorics+1No attempts yet2s512 MBJudgeable
1, 2, 3 Sum 5Count the ordered sums of 1, 2, and 3 that add to n, with no equal value adjacent, modulo 1,000,000,009.Medium5Dynamic programmingMath+2No attempts yet1s512 MBJudgeable
1, 2, 3 Addition 7Count ordered compositions of n into exactly m parts, where each part is 1, 2, or 3, modulo 1,000,000,009.Medium5Dynamic programmingCombinatorics+2No attempts yet0.25s512 MBJudgeable
Adding 1, 2, 3 (9)Count ordered compositions of n into parts 1, 2, and 3 that use at most m terms, and output each count modulo 1,000,000,009.Medium5Dynamic programmingCombinatorics+2No attempts yet1s512 MBJudgeable
Magic WeaponCount triples of details, one per color, where the red number's first and last digits match the green's last digit and the blue's first digit, and all three model numbers differ.Medium5CombinatoricsMath+2No attempts yet2s512 MBJudgeable
Building a Symmetric StairGiven n unit cubes, build a symmetric stair (Ferrers diagram symmetric across the diagonal) using all n cubes, or report it is impossible.Medium5MathImplementation+2No attempts yet3s512 MBJudgeable
Making the Number NCount how many digit-by-digit sequences build the number N when each new digit is attached to the left or right end.Medium5Dynamic programmingString+2No attempts yet1s256 MBJudgeable
League of Legends (Large)Count the sequences of skills A (1 second) and B (M seconds) that fill exactly N seconds with no idle time, modulo 1e9+7.Medium5Dynamic programmingCombinatorics+1No attempts yet3s256 MBJudgeable
Tribal WarGiven N tribes where listed pairs are allied and all other pairs are hostile, count the number of triples that are all allied or all hostile.Medium5CombinatoricsMath+2No attempts yet3s512 MBJudgeable
Code WordCount length-l digit sequences on an r by c grid where no two consecutive presses are orthogonally or diagonally adjacent, mod 1e9+7.Medium5Dynamic programmingMatrix+2No attempts yet1s512 MBJudgeable
Summer TripGiven a string of event types, count contiguous substrings of length at least two whose first and last characters are distinct and each appears only once in the substring.Medium5StringTwo pointers+2No attempts yet3s1024 MBJudgeable
Rainbow StringsCount subsequences of a string in which no letter repeats, distinguishing them by position, modulo 11092019.Medium5Dynamic programmingMath+2No attempts yet1s512 MBJudgeable
Managing DifficultiesCount triples of increasing indices i < j < k where a[j] - a[i] equals a[k] - a[j], so a[i] + a[k] = 2*a[j].Medium5Hash mapCombinatorics+2No attempts yet2s512 MBJudgeable
Big ChangesOn N labeled cities, count the spanning trees whose maximum degree is as large as possible, i.e. the star trees.Medium5CombinatoricsTree+2No attempts yet2s512 MBJudgeable
Number Baseball FGuess a secret N-digit number with distinct digits by asking strike/ball queries, for up to 5040 games.Medium5Brute forceImplementation+1No attempts yet2s512 MBJudgeable
Stacking Blocks TogetherEach of N students offers a set of distinct block sizes, at most one block per student is used, and we count subsets of students whose chosen blocks sum to exactly H modulo 10007.Medium5Dynamic programmingPrefix sum+2No attempts yet1s256 MBJudgeable
BinomialGiven a sequence, count ordered pairs (i, j) where the binomial coefficient C(a_i, a_j) is odd, using the Lucas theorem bit condition.Medium5CombinatoricsBit manipulation+2No attempts yet5s512 MBJudgeable
Keep On MovinGiven counts of several character types, split all characters into palindromic strings so that the shortest palindrome is as long as possible.Medium5GreedyMath+2No attempts yet1s64 MBJudgeable
MountainsCount triples x < y < z where the middle mountain y is strictly taller than both mountain x and mountain z.Medium5ArrayCombinatorics+2No attempts yet2s256 MBJudgeable
Mysterious EquationCount ordered pairs of non-negative integers (x, y) with x + y + xy = n, where n can be as large as 10^9.Medium5MathNumber theory+2No attempts yet2s512 MBJudgeable
BarbellsSplit the weights 1 through n into three groups of equal total weight, or report that no such split exists.Medium5MathGreedy+2No attempts yet2s512 MBJudgeable
Decreasing NumberGiven N, find the N-th smallest non-negative integer whose digits strictly decrease from left to right, or output -1 if none exists.Medium6CombinatoricsGreedy+2No attempts yet1s512 MBJudgeable
Park Seongwon's ProbabilityCount permutations of up to 15 numbers whose concatenation is divisible by K, and output the probability as a reduced fraction.Medium6Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
Card Organization 1Each box lists counts per card color; find the minimum number of box-to-box transfers so at most one mixed box remains and every other color sits in a single box.Medium6GreedyImplementation+2No attempts yet2s128 MBJudgeable
Zigzag LineupCount permutations of N distinct heights where adjacent comparisons strictly alternate, modulo 1,000,000.Medium6Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Student ShuffleCount permutations of up to 16 students so that every pair of adjacent heights differs by more than a given value K.Medium6Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
Code CollectionGiven N possible codes and target K distinct codes, compute the expected number of independent uniform draws needed to collect at least K distinct codes, with N up to 10^18.Medium6ProbabilityMath+1No attempts yet2s256 MBJudgeable
NMKConstruct a permutation of 1..N whose longest increasing subsequence is exactly M and longest decreasing subsequence is exactly K, or report impossible.Medium6CombinatoricsGreedy+2No attempts yet2s128 MBJudgeable
Christmas TreeCount the ways to decorate an N-level tree where level k needs k ornaments split evenly among chosen colors, given limited red, green and blue ornaments.Medium6Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Problem AssignmentGiven an N x N matrix of student-problem times, find the minimum-cost perfect matching assigning one distinct problem to each student.Medium6Dynamic programmingGraph+2No attempts yet5s128 MBJudgeable
Restricted PermutationsCount permutations of 1..N where every element differs from its index by at most K, using a bitmask DP over a sliding window.Medium6Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
TheaterConstruct the longest sequence of distinct nonempty actor subsets where consecutive scenes differ by exactly one actor and the play starts and ends with a single actor.Medium6Bit manipulationCombinatorics+2No attempts yet2s128 MBJudgeable
PokerCompute the exact probability of each of 12 six-card poker hand rankings, including custom back straight and royal straight flush definitions, as reduced fractions.Medium6CombinatoricsBrute force+2No attempts yet2s128 MBJudgeable
Guitar ChordGiven each guitar string's open note and a target chord, choose which chord note each string plays to minimize the pressed-fret range needed to cover all chord notes.Medium6MathGreedy+2No attempts yet2s128 MBJudgeable
CandyGiven candy prices, count the distinct ways to pick a multiset of candies whose price sum is a prime number.Medium6Dynamic programmingNumber theory+2No attempts yet2s128 MBJudgeable
Counting Divisible NumbersCount integers in a range that are divisible by at least one element of a given array using inclusion-exclusion over subsets and LCM.Medium6CombinatoricsMath+2No attempts yet2s128 MBJudgeable
Anti-PalindromeRearrange all characters of a string to form the lexicographically smallest anti-palindrome, where each pair of symmetric positions must differ, or report impossible.Medium6GreedyString+2No attempts yet2s128 MBJudgeable
Making PrimesCombine all N (up to 6) given numbers with +,-,*,/ and parentheses in every possible way to find the smallest and largest prime value obtainable.Medium6BacktrackingBrute force+2No attempts yet2s128 MBJudgeable
Tree EncodingGiven N and an index, find the k-th lexicographically smallest preorder traversal string among all binary search trees built from the first N letters, using Catalan number counting.Medium6CombinatoricsMath+2No attempts yet2s128 MBJudgeable
Sequences of 1 and -1Given M sequences of 1 and -1 of even length N, construct for each one a partner sequence whose elementwise product sums to zero, using at most N distinct partner sequences overall.Medium6CombinatoricsPrefix sum+2No attempts yet2s128 MBJudgeable
Tiling a GridCount the ways to fully tile an N by M grid (N, M up to 14) with 2x1 dominoes, modulo 9901.Medium6Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
Resident Registration NumberGiven a 19-digit ID pattern with some digits erased, count completions that form a valid birth date and satisfy the modular checksum rule for the last digit.Medium6CombinatoricsMath+2No attempts yet2s128 MBJudgeable
Tile CodesCount distinct tilings of a 2xN board using 1x2, 2x1, and 2x2 tiles, where mirror-image tilings under left-right flip count as one.Medium6Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Count Selections with GCD 1Given up to 50 integers, count non-empty subsets whose greatest common divisor equals 1, modulo 10,000,003.Medium6Number theoryCombinatorics+1No attempts yet2s128 MBJudgeable
Mirror NumbersCount how many numbers between A and B (up to 10^18) read the same when reflected in a mirror, using only digits 0,1,2,5,8 with 2 and 5 swapped.Medium6CombinatoricsString+2No attempts yet1s64 MBJudgeable
Counting Ordered Pairs with a Given GCDCount ordered pairs (x, y) with x <= a, y <= b and gcd(x, y) = d for up to 50,000 queries.Medium6Number theoryMath+1No attempts yet2s128 MBJudgeable
Making a RectangleGiven up to 16 sticks, choose four disjoint groups forming two equal-length pairs of sides to maximize the rectangle's area, or return -1 if impossible.Medium6Bit manipulationDynamic programming+2No attempts yet2s256 MBJudgeable
Partitioning for Fun and ProfitGiven m, n and k, output the k-th lexicographically smallest partition of m into n non-decreasing positive parts.Medium6CombinatoricsDynamic programming+2No attempts yet2s128 MBJudgeable
Counting Full Binary TreesCount full binary trees with exactly n nodes and height exactly k, modulo 9901, using a height-bounded DP and subtraction trick.Medium6Dynamic programmingTree+2No attempts yet2s128 MBJudgeable
Cow PizzaCount subsets of up to 20 toppings that avoid containing every topping of any given forbidden constraint set, using inclusion-exclusion or bitmask enumeration.Medium6Bit manipulationCombinatorics+1No attempts yet2s128 MBJudgeable
Rock-Paper-ScissorsCompute, as a reduced fraction, the probability that Hangseung reaches K round wins before Dongju in at most N rounds of rock-paper-scissors with ties possible.Medium6Dynamic programmingProbability+1No attempts yet2s128 MBJudgeable
Trailing Zeros in a CombinationCompute the count of trailing zeros in C(n, m) for n up to 2 billion using prime factor exponents of 2 and 5 via Legendre's formula.Medium6Number theoryMath+1No attempts yet2s128 MBJudgeable
Counting Grid TrianglesCount triangles with positive area formed by choosing three distinct lattice points from an (N+1) by (M+1) grid.Medium6CombinatoricsMath+1No attempts yet2s128 MBJudgeable
Baby Goat LineupGiven binary labels A through B, find the X-th label when ordered first by popcount then by numeric value.Medium6CombinatoricsBit manipulation+1No attempts yet2s128 MBJudgeable
Degree SequenceGiven a target degree sequence for N vertices, construct any simple graph's adjacency matrix matching it exactly, or report impossibility.Medium6GreedyGraph+2No attempts yet2s128 MBJudgeable
Number of MultisetsGiven multiplicities of values from 1 to T among A numbers, count multisets of size K for S≤K≤B modulo 1,000,000.Medium6Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Cactus GraphGiven a graph described by edge-paths, verify it is a cactus and count connected spanning subgraphs that remain cactus graphs.Medium6GraphDFS+1No attempts yet2s128 MBJudgeable
Find the K-th Pinary NumberGiven K up to 10^18, output the K-th smallest binary string with no leading zero and no two consecutive 1s, treated as a number by value order.Medium6Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Circular NetworkGiven a cycle of N nodes and P path requests, choose a direction for each request to minimize the total number of distinct cycle edges converted.Medium6GreedyBit manipulation+1No attempts yet2s128 MBJudgeable