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
Tiling a 3-by-N WallCount the number of ways to tile a 3-by-N wall using 2x1 dominoes, for N up to 30.Medium4Dynamic programmingCombinatoricsNo attempts yet2s128 MBJudgeable
Find the Binary NumberGiven N, L, and I, output the I-th binary string of length N (with at most L ones) in increasing numeric order.Medium4CombinatoricsBinary search+1No attempts yet2s128 MBJudgeable
Color WheelCount the ways to choose K non-adjacent colors from N colors arranged in a circle, modulo 1,000,000,003.Medium4CombinatoricsMath+1No attempts yet1s128 MBJudgeable
Nondecreasing NumbersCount the number of n-digit strings (digits 0-9, leading zeros allowed) that are nondecreasing, for n up to 64 requiring big integers.Medium4CombinatoricsMathNo attempts yet1s128 MBJudgeable
Number of Points Visible from the OriginCount lattice points (x,y) with 0<=x,y<=N visible from the origin, meaning gcd(x,y)=1 or one coordinate is 0/1 edge case.Medium4Number theoryMath+1No attempts yet1s128 MBJudgeable
LottoCount n-element increasing subsequences from 1..m where each next number is at least double the previous, using combinatorics or DP.Medium4Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Horizontal and Vertical PuzzleGiven 6 three-letter words, choose 3 as rows and 3 as columns so the grid's columns also match the remaining words, outputting the lexicographically smallest valid arrangement.Medium4Brute forceString+1No attempts yet1s128 MBJudgeable
Planet X3Given up to a million numbers, compute the sum over all pairs of the XOR of their values by counting set bits per bit position.Medium4Bit manipulationMath+1No attempts yet1s192 MBJudgeable
4 and 7Given K, output the K-th smallest positive integer whose digits are only 4 or 7, using a binary-representation-like construction.Medium4MathBit manipulation+1No attempts yet1s128 MBJudgeable
Leonardo's NotebookDetermine whether a given permutation of the alphabet can be expressed as some permutation applied twice (its functional square).Medium4MathCombinatorics+1No attempts yet1s128 MBJudgeable
Expected AllowanceGiven n m-sided dice and a cutback k, compute the exact reduced fraction for the expected value of max(1, sum of dice - k).Medium4Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
Lagrange's Four-Square TheoremFor each input number, count the unordered ways to express it as a sum of one to four positive perfect squares.Medium4Brute forceMath+1No attempts yet2s128 MBJudgeable
Pen CountsCount the number of triangles with integer side lengths summing to N, where rotations count as the same and reflections differ.Medium4MathCombinatorics+1No attempts yet1s128 MBJudgeable
Suit DistributionFor each pair (a, b), compute the probability that the opponents' a+b cards of one suit split a and b between them.Medium4CombinatoricsMath+2No attempts yet1s128 MBJudgeable
BlackjackGiven n decks and three visible cards, compute the probability that the player's two-card hand beats the dealer's two-card hand.Medium4MathCombinatorics+2No attempts yet1s128 MBJudgeable
Road ShopCount the number of ways to choose bead counts for n colors summing to r, with at least m beads of each color.Medium4CombinatoricsMath+1No attempts yet1s128 MBJudgeable
Hexagonal TilesCount the sequences of increasing tile numbers from the start tile to tile N, where each move goes forward by 1 or 2.Medium4Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Make a GuessGiven MasterMind guesses and their excellent/good counts, decide for each position whether every consistent password shares the same character, else print '?'.Medium4Brute forceImplementation+1No attempts yet1s128 MBJudgeable
DartsCount unordered triples of dart hits (single, double, treble regions, bulls, or misses) whose scores sum to a given turn score.Medium4Brute forceImplementation+2No attempts yet1s128 MBJudgeable
Dairy QueenCount the number of ways to make N cents using unlimited coins of the given C denominations, ignoring order.Medium4Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Barbara Bennett's Wild NumbersGiven a wild number W with digit and ? positions and a same-length number X, count the length-n digit strings matching W that are strictly greater than X.Medium4CombinatoricsMath+2No attempts yet1s128 MBJudgeable
Binomial ShowdownFor each pair (n, k), print the binomial coefficient C(n, k), stopping at the terminating pair 0 0.Medium4MathCombinatorics+1No attempts yet1s128 MBJudgeable
LottoFor each set of k numbers in ascending order, print all 6-element subsets in lexicographic order, separated by blank lines.Medium4BacktrackingRecursion+1No attempts yet1s128 MBJudgeable
ParliamentSplit N delegates into groups of distinct sizes so that the product of the sizes is maximized, and print the sizes in ascending order.Medium4MathGreedy+1No attempts yet1s128 MBJudgeable
Dart ChallengeFor each dartboard, count how many distinct total scores k darts can produce, where each dart misses or scores s_i, 2s_i, or 3s_i (no triple on the top area).Medium4Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
IndomieEach of the N people ahead takes a uniformly random remaining item among rice, sugar, and Indomie (Indomie limited to S). Find the probability Indomie remains for Felix, as a percentage.Medium4ProbabilityCombinatorics+2No attempts yet1s128 MBJudgeable
Sultan's LandGiven P pillars on an N by N grid, count how many sets of four pillars form the corners of an axis-aligned rectangle.Medium4ArrayHash map+2No attempts yet1s128 MBJudgeable
BalanceCount the orders and pan choices for placing n distinct weights so the left pan is never heavier than the right at any step.Medium4Brute forceBacktracking+2No attempts yet2s128 MBJudgeable
HandshakesCount the matchings of a path with n vertices, then print the last digit of that count.Medium4Dynamic programmingCombinatorics+1No attempts yet1s256 MBJudgeable
Byteland LotteryGiven up to 10^6 ball labels, compute the digital root of the sum of products over all non-empty subsets.Medium4MathNumber theory+2No attempts yet1s128 MBJudgeable
HyperclockGiven the cycle sizes of N clocks, the tour visits every configuration once; its length is the number of configurations, the product of the sizes.Medium4MathCombinatoricsNo attempts yet1s128 MBJudgeable
CoinsCount the ways to place coins of sizes 1 to n into slots with capacities a_i so every coin fits, modulo 1000000007.Medium4SortingCombinatorics+1No attempts yet1s512 MBJudgeable
SoldiersCount the monotonic lineups of n distinguishable soldiers by height and output the last four digits of the count.Medium4CombinatoricsMath+1No attempts yet1s512 MBJudgeable
CoinsCount the unordered combinations of up to 20 coin values that sum to the target amount M.Medium4Dynamic programmingCombinatoricsNo attempts yet1s128 MBJudgeable
A Card TrickGiven five cards, pick the hidden card and the order of the other four to satisfy the decoding rule, choosing the lexicographically smallest arrangement.Medium4Brute forceCombinatorics+1No attempts yet1s128 MBJudgeable
Lock Patterns and Spanning TreesCount the spanning trees of an m by m king-move grid for m up to 6 by evaluating a cofactor of its Laplacian matrix.Medium4MatrixMath+2No attempts yet1s128 MBJudgeable
Tree ColoringCount colorings of an N-node tree with K colors so adjacent nodes differ, modulo 93563.Medium4Dynamic programmingTree+1No attempts yet1s128 MBJudgeable
Sums of Distinct Natural NumbersCount the partitions of each given N into distinct positive integers, including N itself, modulo 100999.Medium4Dynamic programmingCombinatoricsNo attempts yet7s128 MBJudgeable
Coding of PermutationsThe task gives a permutation of 1 to n and asks for its 1-based rank among all permutations in lexicographic order.Medium4CombinatoricsMathNo attempts yet1s128 MBJudgeable
HousingCount the unordered splits of n into parts of at least 5 for n between 5 and 100.Medium4Dynamic programmingCombinatoricsNo attempts yet2s512 MBJudgeable
LexicalGiven n and a permutation of 0 to n-1, compute its 1-based position in lexicographic order.Medium4CombinatoricsMathNo attempts yet2s1024 MBJudgeable
Triangles made from linesCount how many triples of the given lines form a triangle by removing triples that contain parallel lines.Medium4Hash mapCombinatorics+1No attempts yet1s128 MBJudgeable
Bessie Goes MooCount assignments of listed values to seven variables that make (B+E+S+S+I+E)(G+O+E+S)(M+O+O) a multiple of 7.Medium4MathBrute force+1No attempts yet1s256 MBJudgeable
Dormitory ReassignmentCount the permutations of N students to rooms in which no student keeps the same room.Medium4CombinatoricsDynamic programmingNo attempts yet1s128 MBJudgeable
Binomial Coefficient 3Compute the binomial coefficient C(N, K) modulo 1,000,000,007 for N up to 4,000,000.Medium4CombinatoricsNumber theoryNo attempts yet1s256 MBJudgeable
Polynomial GameFor each test case, compute the coefficient of x^N in the product of (1+x+...+x^i) for i from 1 to k.Medium4Dynamic programmingCombinatoricsNo attempts yet1s256 MBJudgeable
Kitchen CombinatoricsCount compatible starter, main and dessert triples weighted by brand choices over shared ingredients, printing too many above 10^18.Medium4Brute forceCombinatoricsNo attempts yet4s256 MBJudgeable
Star trianglesFor each star taken as the right-angle vertex, multiply the counts of other stars sharing its column and its row, then add the products.Medium4Hash mapCombinatoricsNo attempts yet2s256 MBJudgeable
Collecting Stamps 2Insert one J, O, or I stamp at any position to maximize the number of triples that read J, O, I in order.Medium4Prefix sumCombinatoricsNo attempts yet2s256 MBJudgeable
Password Attacker (Small)Count length-N strings over M given symbols that use every symbol at least once, modulo 1e9+7.Medium4CombinatoricsMathNo attempts yet5s512 MBJudgeable
Number card trickChoose the sorted N-number multiset bounded by M whose subset product counts give the largest posterior weight.Medium4Brute forceCombinatoricsNo attempts yet5s512 MBJudgeable
Crop Triangles (Small)Count triples of generated tree points whose coordinate sums are divisible by 3 in both axes.Medium4CombinatoricsNumber theory+1No attempts yet5s512 MBJudgeable
CandySum 2^K over all subsets of N candies with K elements, where the empty subset contributes 0, modulo 1,000,000,007.Medium4CombinatoricsMath+2No attempts yet2s512 MBJudgeable
Tree and paths of length twoDecide whether some tree on N nodes has exactly S simple paths of length 2.Medium4TreeCombinatorics+1No attempts yet2s512 MBJudgeable
ABCFind the lexicographically smallest length-N string over A, B, C that has exactly K pairs i < j with S[i] < S[j].Medium4GreedyCombinatorics+1No attempts yet2s512 MBJudgeable
AB StringFind the length-N A/B string whose number of (A before B) pairs equals K, choosing the lexicographically smallest such string.Medium4GreedyCombinatorics+1No attempts yet2s512 MBJudgeable
Partitioning a QueueCount compositions of n whose parts avoid the arithmetic progression m, m+k, m+2k, with n up to 30 and up to 10000 test cases.Medium4Dynamic programmingCombinatorics+1No attempts yet2s512 MBJudgeable
Disposable CupGiven A, B, and N, find every total height achievable by stacking N cups, where same-facing neighbors add A and opposite-facing ones add A+B.Medium4CombinatoricsMathNo attempts yet1s32 MBJudgeable
CombinationsGiven up to 1000 pairs (n, k), compute the binomial coefficient C(n, k) modulo 10^9+7 for each pair.Medium4CombinatoricsMath+2No attempts yet2s512 MBJudgeable
Drawing PebblesGiven pebble counts per color, compute the probability that K randomly drawn distinct pebbles all share one color, printed to 10 decimals.Medium4CombinatoricsMath+2No attempts yet2s512 MBJudgeable
Minimum overtakesGiven a starting order and a finishing order of up to 24 cars, print the minimum number of adjacent swaps that turn the start into the finish.Medium4SortingArray+1No attempts yet2s512 MBJudgeable
HyperloopFor odd N, print (N-1)/2 Hamiltonian cycles on the complete graph of N cities that partition all edges, using the given seat-walk construction.Medium4GreedyMath+2No attempts yet1s128 MBJudgeable
Packing snack sticksGiven n and m, decide whether an n by m grid can be tiled exactly with 3-cell straight bars and L trominoes that may be rotated.Medium4MathGreedy+2No attempts yet2s512 MBJudgeable
Bovine Genomics (Silver)Count triples of genome positions where no spotty cow and plain cow share the same three characters.Medium4Brute forceHash map+2No attempts yet2s512 MBJudgeable
Pizza (Large)Split a tower of N into unit towers, scoring the product of the two parts at each split, and maximize the total score.Medium4GreedyMath+2No attempts yet1s512 MBJudgeable
Multiples of three from 0, 1, and 2 (Large)Count N-digit numbers made only of the digits 0, 1, and 2 that are divisible by 3, with no leading zero, modulo 1e9+9.Medium4Dynamic programmingCombinatorics+1No attempts yet2s256 MBJudgeable
Ample Syrup (Small)Choose K pancakes from at most 10 to stack largest radius on the bottom, maximizing the exposed surface area divided by pi.Medium4Brute forceSorting+2No attempts yet5s512 MBJudgeable
Go Northwest!Given N distinct points, find the probability that two independently drawn points lie on a 45-degree diagonal from each other.Medium4Hash mapMath+1No attempts yet2s512 MBJudgeable
Clever TitleFor each uppercase word, count how many orderings of the n author names let you pick one uppercase letter from each name, left to right, to spell the word.Medium4BacktrackingBrute force+2No attempts yet5s512 MBJudgeable
Secret of Chocolate PolesCount sequences of dark and white chocolate disks, each 1 cm thick except dark thick disks at k cm, alternating colors, starting and ending dark, with total thickness at most l.Medium4Dynamic programmingCombinatoricsNo attempts yet1s512 MBJudgeable
Counting equilateral trianglesGiven a triangular tower with N layers of unit triangles, count every equilateral triangle of any size, both upward and downward pointing.Medium4MathCombinatorics+2No attempts yet1s128 MBJudgeable
One, Two, Three Plus FourCount the number of unordered sums of 1, 2, and 3 that add up to a given n, for each test case.Medium4Dynamic programmingCombinatorics+2No attempts yet1s512 MBJudgeable
Match PredictionGiven win/draw/loss probabilities for all six matches among four teams, compute each team's probability of finishing in the top two.Medium4ProbabilityBrute force+2No attempts yet1s256 MBJudgeable
CombinationCompute N choose R modulo 1,000,000,007 for 0 ≤ R ≤ N ≤ 1,000,000 using a prime modulus.Medium4MathNumber theory+2No attempts yet1s256 MBJudgeable
Multiples of 3Count ordered triples of multiples of 3 that add to n, with n a multiple of 3 between 3 and 3000.Medium4MathCombinatorics+1No attempts yet0.1s128 MBJudgeable
Plate ParityCount integers in [A, B] whose rightmost nonzero digit is odd versus even, where A and B go up to 10^16.Medium4MathImplementation+2No attempts yet1s512 MBJudgeable
Contest SettingCount the ways to choose k problems whose difficulties are all distinct, given n problems and their difficulty values, modulo 998,244,353.Medium4MathCombinatorics+2No attempts yet1s512 MBJudgeable
Making Roman NumeralsCount how many distinct sums can be formed by choosing N characters from {I, V, X, L} with repetition, where order does not matter.Medium4CombinatoricsMath+2No attempts yet2s512 MBJudgeable
Terraced fieldsCount how many digit characters are 6 or 8 in the decimal numbers written on steps divisible by 8 plus the final step n.Medium4MathImplementation+2No attempts yet8s512 MBJudgeable
Jinwoo's PasswordGiven N and a lowercase password of length at most N, find its 1-based position among all strings of length 1 to N in lexicographic order.Medium4StringMath+2No attempts yet1s256 MBJudgeable
Badugi PokerGiven six distinct cards, each with a number 1 to 15 and a color, sort all 15 pairs by the ranking rules and print the winner first.Medium4SortingImplementation+2No attempts yet1s256 MBJudgeable
Plane DivisionGiven at most N lines with slope -1, 0, or 1, find the maximum number of regions the plane can be divided into.Medium4MathCombinatorics+2No attempts yet1s512 MBJudgeable
Viyott's Stepping Stone CrossingCount the ways to jump from stone 1 to stone N when each jump adds any positive integer, modulo 1e9+7.Medium4MathCombinatorics+2No attempts yet1s256 MBJudgeable
Cow-abunga!Given at most 9 cow weights, choose M of them and print every prime number that appears as a subset sum, in increasing order.Medium4Brute forceCombinatorics+2No attempts yet1s1024 MBJudgeable
Isosceles trianglesCount the isosceles triangles whose three vertices are vertices of a regular n-gon, for n up to 1e9.Medium4CombinatoricsMath+2No attempts yet1s512 MBJudgeable
Misha's ProductGiven n distinct integers, concatenate every ordered pair of them and report the sum of all these concatenations modulo 1e9+7.Medium4MathArray+2No attempts yet1s512 MBJudgeable
Two MeasurementsCount pairs of hours i < j in [l, r] whose difference is a multiple of the rotation period a.Medium4MathCombinatorics+1No attempts yet2s512 MBJudgeable
Expandable Beautiful TrianglesCount the RGB-colored triangles on an N by M grid that share two vertices with another RGB triangle of strictly larger area.Medium5Brute forceGeometry+2No attempts yet2s128 MBJudgeable
Tower Floor DisplayGiven an N-digit floor number shown on a lamp display where off lamps may be broken, compute the average of every floor number consistent with the lit lamps.Medium5MathCombinatorics+2No attempts yet2s128 MBJudgeable
Decreasing NumbersGiven N, output the N-th smallest number whose decimal digits strictly decrease left to right, or -1 if it does not exist.Medium5CombinatoricsMath+1No attempts yet2s128 MBJudgeable
DictionaryConstruct the K-th lexicographically smallest string made of N 'a's and M 'z's using combinatorial counting, or report -1 if K exceeds the total count.Medium5CombinatoricsGreedy+1No attempts yet2s128 MBJudgeable
Partial RectanglesGiven an N x M grid doubled into a 2N x 2M grid, count how many times each letter appears summed over every possible subrectangle.Medium5CombinatoricsMath+2No attempts yet2s128 MBJudgeable
Sevi GameGiven one roll of five dice, pick at least two dice to reroll so the expected score of a poker-dice scoring system is minimized, with ties broken lexicographically.Medium5ProbabilityBrute force+2No attempts yet2s128 MBJudgeable
Gap Pair SequenceConstruct the lexicographically smallest sequence where each number from a given set appears twice with exactly that many numbers between the two occurrences, or report -1 if impossible.Medium5BacktrackingCombinatorics+1No attempts yet2s128 MBJudgeable
Captain DasomGiven N cannonballs, find the minimum number of tetrahedral-number piles whose sizes sum exactly to N using unbounded coin-change style DP.Medium5Dynamic programmingMath+1No attempts yet2s128 MBJudgeable
Summit Handshakes 2Given N seats around a round table, count the ways N representatives can pair up with non-crossing handshake segments, modulo 987654321.Medium5Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Labels Without a Forbidden DigitGiven N and a forbidden digit L, find the N-th smallest positive integer whose decimal digits never contain L.Medium5MathCombinatorics+2No attempts yet2s128 MBJudgeable
TilingCount the number of ways to tile a 2×n rectangle using 2×1 and 2×2 tiles for multiple values of n up to 250.Medium5Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
Sum of Numbers 6Given N and the bottom value of a Pascal-like sum triangle built from a permutation of 1..N, reconstruct the lexicographically smallest top row.Medium5CombinatoricsBacktracking+2No attempts yet2s128 MBJudgeable
ChariotsConstruct a permutation of size N avoiding both fixed positions on the two main diagonals, or report impossibility for small N.Medium5CombinatoricsMath+1No attempts yet2s128 MBJudgeable