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
Number of RectanglesGiven up to 5000 points, count axis-aligned rectangles whose four corners are all present among the points.Medium5Hash mapCombinatorics+1No attempts yet2s128 MBJudgeable
SequenceFind the K-th lexicographically smallest non-decreasing sequence of N positive integers summing to M.Medium5BacktrackingCombinatorics+1No attempts yet2s128 MBJudgeable
Theater SeatsCount permutations where each ticket holder sits in their own or adjacent seat, with VIP seats fixed and splitting the row into independent segments counted by a Fibonacci-like recurrence.Medium5Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Polygon PartitionsCount noncrossing dissections of a regular N-gon into all triangles or all quadrilaterals, modulo 1e9, using Catalan-like combinatorics.Medium5CombinatoricsDynamic programming+1No attempts yet2s128 MBJudgeable
Number of PermutationsGiven a permutation's up-down pattern, count permutations of size n sharing the same pattern, modulo 1,000,000,000.Medium5Dynamic programmingCombinatoricsNo attempts yet2s128 MBJudgeable
Sum of Powers of TwoCount the ways to write N as an unordered sum of powers of two, modulo one billion.Medium5Dynamic programmingMath+1No attempts yet2s128 MBJudgeable
Adjacent Bit Pair CountCount binary strings of length n whose number of adjacent 11-pairs equals a given k, for up to 1000 queries.Medium5Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
A Margarita Today?Count subsets of up to 30 prices whose sum is within budget D and whose leftover money cannot afford any unchosen item.Medium5Brute forceRecursion+1No attempts yet1s128 MBJudgeable
Counting Sanggeun's Digit FriendsGiven up to a million large integers, count pairs that share at least one decimal digit, requiring bitmask digit sets and efficient counting over 1024 subsets.Medium5Bit manipulationCombinatorics+1No attempts yet1s128 MBJudgeable
Pleasant WordCount ways to fill blanks in a word with uppercase letters so it avoids three consecutive vowels or consonants and contains at least one 'L'.Medium5Dynamic programmingString+1No attempts yet1s128 MBJudgeable
Counting Axis-Aligned Right TrianglesCount triangles among N points where the right angle vertex has one point sharing its x-coordinate and another sharing its y-coordinate.Medium5Hash mapMath+1No attempts yet1s128 MBJudgeable
TripletsGiven a grid with letters placed on some cells, count how many triples of letters are collinear.Medium5GeometryCombinatorics+1No attempts yet1s128 MBJudgeable
Film FestivalGiven a bipartite graph of boat connections, count the number of pairs of left villages and pairs of right villages that form a complete K2,2 subgraph.Medium5CombinatoricsHash map+1No attempts yet1s128 MBJudgeable
Handong Does Not Want to Study!Given a functional graph where each node points to exactly one other node, find the starting node whose path visits the most distinct nodes before repeating, breaking ties by smallest index.Medium5GraphDFS+1No attempts yet1s128 MBJudgeable
Friends Calling PlanGiven call minutes between up to 16 employees, pair them all up to minimize total billing cost using bitmask DP over perfect matchings.Medium5Dynamic programmingBit manipulation+1No attempts yet1s128 MBJudgeable
PINCount pairs of 4-character PINs (from a given list) that differ in exactly D of their four positions.Medium5Hash mapCombinatorics+1No attempts yet1s128 MBJudgeable
Hop, HopCount, modulo 1000000, the number of ways to write n as a non-increasing sequence of jumps of length 1, 2, or 3, for n up to 1e9.Medium5MathDynamic programming+1No attempts yet1s128 MBJudgeable
Enchanted MirrorDecide if bricks with fixed (real,mirror) letter pairs can be permuted so the row reads T1 and its mirror reads T2, given initial words S1,S2.Medium5Hash mapString+2No attempts yet3s256 MBJudgeable
History of FootballGiven final points of n (up to 8) football teams under win/draw/loss scoring, count the number of distinct match outcome assignments consistent with those totals.Medium5BacktrackingCombinatorics+1No attempts yet2s64 MBJudgeable
Graph MatchingCount the number of matchings (independent edge sets) of the cycle graph C_n for each given n, likely requiring big-integer arithmetic via a Lucas-sequence style recurrence.Medium5Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
Breaking the CipherGiven plaintext, ciphertext, and block size, count permutations of size k that transform every plaintext block into the matching ciphertext block.Medium5CombinatoricsString+1No attempts yet1s128 MBJudgeable
The Industrial Spy's LetterGiven up to 7 digit shreds, count the distinct primes formable by arranging any subset of them (leading zeros dropped), over up to 200 test cases.Medium5BacktrackingCombinatorics+1No attempts yet1.5s128 MBJudgeable
I've Got Your Back(gammon)Map between 6-tuples of 15 pieces on 6 points, ordered lexicographically, and their index among the 15504 configurations.Medium5CombinatoricsMath+2No attempts yet1s128 MBJudgeable
SkylineCount permutations of 1..N with no increasing subsequence of length 3, modulo 1,000,000, for each N up to 1,000.Medium5Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
MeganominoesFor each query i, count unordered pairs of distinct tiles where one matching pair of ends touches and the two opposite ends sum to i.Medium5Hash mapBrute force+1No attempts yet1s128 MBJudgeable
Frosh WeekGiven n distinct student numbers in a line, find the minimum number of adjacent swaps needed to sort them into increasing order.Medium5SortingDivide and conquer+2No attempts yet1s128 MBJudgeable
Cantor SetGiven a decimal x between 0 and 1 that ends within 6 fractional digits, decide whether x lies in the Cantor set, that is, whether some ternary expansion of x avoids the digit 1.Medium5MathNumber theory+2No attempts yet1s128 MBJudgeable
Team RankingsGiven up to 100 rankings of five teams, find the ranking minimizing the sum of pairwise-order disagreements, breaking ties alphabetically.Medium5Brute forceCombinatorics+2No attempts yet1s128 MBJudgeable
Tight WordsCount words of length n over digits 0..k where adjacent digits differ by at most 1, then print that count as a percentage rounded to five decimals.Medium5Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Know When to Hold ThemRank a set of five-card poker hands from most to least valuable, using nine standard hand categories and their tie-breakers.Medium5SortingImplementation+2No attempts yet1s128 MBJudgeable
PERMSFor each query (n, k), count permutations of 1..n having exactly k inversions, with n up to 18 and k up to 200.Medium5Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Great Geek Game-show 3000!Given a random permutation of N names, each contestant follows its cycle up to K steps; find the probability every cycle has length at most K.Medium5CombinatoricsMath+2No attempts yet1s128 MBJudgeable
SoccerCompute probability distribution of final scores after up to T seconds of a stochastic soccer simulation with passing, stealing, shooting, and absorbing states.Medium5ProbabilityDynamic programming+2No attempts yet2s128 MBJudgeable
Baby's BlocksGiven a multiset of letters, find the 0-based rank of a given distinct permutation among all distinct permutations in lexicographic order.Medium5CombinatoricsString+1No attempts yet1s128 MBJudgeable
JOI FlagCount fillings of an M by N grid with J, O, I (some cells fixed) that contain at least one L shape: J with O to its right and I below, modulo 100000.Medium5Dynamic programmingCombinatorics+2No attempts yet5s128 MBJudgeable
Commute RouteCount monotone lattice paths from (1,1) to (w,h) that never turn at two consecutive intersections, modulo 100000.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Listing Square Arrangements in Lexicographic OrderList every partition of n whose parts are non-increasing, and print the sequences in decreasing lexicographic order.Medium5BacktrackingRecursion+2No attempts yet1s128 MBJudgeable
Odd or EvenPair each red number with a blue number to minimize how many pairs sum to an even value, since Mary wins those.Medium5GreedyMath+2No attempts yet3s128 MBJudgeable
Computer DJGiven N labeled songs, map the k-th character of the infinite string of all words over A..Z in length-then-lex order back to its song title.Medium5MathCombinatorics+2No attempts yet1s128 MBJudgeable
Cow IDsFind the N-th smallest binary number that has exactly K one-bits and no leading zeros, then print it in binary.Medium5CombinatoricsMath+2No attempts yet1s128 MBJudgeable
Cow LineGiven N up to 20, convert between a permutation of 1..N and its lexicographic rank among all permutations, for up to 10000 queries.Medium5CombinatoricsMath+1No attempts yet1s128 MBJudgeable
Bovine Bridge BattleCount sets of four points that are symmetric about some center, where each point pairs with its 180-degree rotation partner.Medium5Hash mapGeometry+2No attempts yet1s128 MBJudgeable
Building a FenceCount the ordered ways to cut a plank of length N into four positive integer pieces whose longest piece is strictly shorter than the other three combined.Medium5CombinatoricsMath+2No attempts yet1s128 MBJudgeable
Cow CashCount the number of unordered ways to make an amount N using V coin denominations, where each coin can be used any number of times.Medium5Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Fence RepairSplit one board into N planks of given lengths; each cut costs the length of the piece being cut, so find the minimum total cost.Medium5GreedyHeap+2No attempts yet1s128 MBJudgeable
ATM PIN TheftGiven a sequence of observed key presses (digits and at most one backspace), count the four-digit PINs that could produce exactly that sequence of pressed keys.Medium5Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Hopeless CoachGiven past win, draw, and loss counts, find the probability that the team earns at least P points over the next N matches.Medium5Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
EntropyFor each line of text, print the fixed 8-bit ASCII bit length, the optimal prefix-free Huffman bit length, and the compression ratio rounded to one decimal.Medium5GreedyHeap+2No attempts yet1s128 MBJudgeable
Extrapolation Using a Difference TableExtend a sequence by k steps using a polynomial difference table, always assuming the highest-order differences stay constant, and print the (n+k)-th term.Medium5MathDynamic programming+2No attempts yet1s128 MBJudgeable
El DoradoCount the increasing subsequences of length exactly k in a sequence of n distinct numbers, for several test cases.Medium5Dynamic programmingArray+1No attempts yet1s128 MBJudgeable
A Game with MarblesEach move takes one marble from a bowl and, if it is not bowl 1, adds one marble to every lower-numbered bowl; count the total moves until all bowls are empty.Medium5Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
Rhinoceros BeetleGiven shared community cards and each player's two hole cards, evaluate every player's best five-card poker hand and print the indices of all winners.Medium5ImplementationSorting+2No attempts yet2s128 MBJudgeable
Pattern GeneratorFor each (n, k) pair, print all n-bit strings with exactly k ones in decreasing numeric order, separated by blank lines.Medium5BacktrackingRecursion+2No attempts yet1s128 MBJudgeable
King Thrór's GoldCount the ways to choose exactly k distinct bar values summing to T, and list all solutions in lexicographic order when there are at most 20.Medium5Dynamic programmingBacktracking+2No attempts yet1s128 MBJudgeable
Wonderful FoursGiven five digits, count unordered triples of distinct permutations (no leading zero) whose sum is a different valid permutation of the same digits.Medium5Brute forceCombinatorics+2No attempts yet1s128 MBJudgeable
GearsCount how many distinct fractions a/b exist with both a and b in the range M to N.Medium5MathNumber theory+2No attempts yet1s1024 MBJudgeable
Geocaching CoordinatesGiven a coordinate formula with lowercase letter slots and rules for each variable's allowed values, print every distinct resulting coordinate in lexicographic order.Medium5Brute forceCombinatorics+2No attempts yet1s1024 MBJudgeable
Diophantus of AlexandriaGiven n, count the pairs (x, y) with x <= y satisfying 1/x + 1/y = 1/n.Medium5Number theoryMath+2No attempts yet1s128 MBJudgeable
Betting SetsPartition an N by M table of probabilities into groups of one cell per column to maximize the expected number of all-heads groups.Medium5Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Digit Sum Over a RangeGiven l and u up to 2e9, find the total of the digit sums of every integer in that inclusive range.Medium5MathDynamic programming+2No attempts yet1s128 MBJudgeable
The History of CottonGiven n, m, and g, print the g-th m-element subset of {1,...,n} in lexicographic order.Medium5CombinatoricsMath+1No attempts yet1s128 MBJudgeable
Yum YumFind the minimum number of straight lines needed to cover every integer-coordinate point in an (n+1) by (m+1) grid, excluding the frog's one starting point.Medium5MathNumber theory+2No attempts yet1s128 MBJudgeable
ProtocolsCount the length-m strings over k symbols with no run of l equal symbols, then output floor((n/m) * log2(count)).Medium5Dynamic programmingCombinatorics+2No attempts yet3s128 MBJudgeable
LollobrigidaGiven a multiset of block heights, decide whether the blocks can be arranged so the sequence alternates up and down at every position.Medium5GreedySorting+2No attempts yet1s128 MBJudgeable
The Number of N-k-special SetsCount subsets of {1,...,n} with no two consecutive numbers whose sum exceeds k, for n up to 100.Medium5Dynamic programmingCombinatoricsNo attempts yet1s128 MBJudgeable
Monochromatic TrianglesGiven n points and a list of red edges (all other pairs are black), count the triangles whose three sides share one color.Medium5CombinatoricsGraph+2No attempts yet1s128 MBJudgeable
MatchesGiven m match lineups that each split n boys into two teams, decide whether every pair of boys is separated at least once.Medium5Bit manipulationCombinatorics+1No attempts yet1s128 MBJudgeable
Rectangles 2Count axis-aligned rectangles with vertices on grid points of an n x m grid whose perimeter is at least p.Medium5MathCombinatorics+2No attempts yet2s512 MBJudgeable
BalloonsGiven stock counts for n balloon colors and m orders, decide whether each child can receive the requested number of distinct-colored balloons.Medium5GreedySorting+2No attempts yet1s128 MBJudgeable
ElectricityGiven k lines between n homes and m windmills on parallel lines, count subsets of non-crossing lines where every home and windmill has degree at most one, modulo r.Medium5Dynamic programmingSorting+1No attempts yet1s128 MBJudgeable
DiceFind the k-th non-decreasing sequence of length m with values from 1 to n, in lexicographic order.Medium5CombinatoricsDynamic programming+2No attempts yet1s128 MBJudgeable
Super-Fast Circular RacesGiven a directed graph where each vertex has out-degree and in-degree at most two, count the ways to cover every vertex with vertex-disjoint simple directed cycles, modulo 10000, or report NIE if impossible.Medium5GraphDFS+2No attempts yet1s128 MBJudgeable
Neon SignCount the triples of vertices whose three connecting tubes all share the same color in a red-blue complete graph.Medium5CombinatoricsGraphNo attempts yet3s256 MBJudgeable
HerbertCount distinct squares a robot starting at the origin can end on within n moves when each step or ninety-degree turn costs one move.Medium5MathCombinatoricsNo attempts yet1s128 MBJudgeable
The Hopeless QueueCount fillings of the movable spots with equal coin totals so every prefix keeps at least as many 50 coins as 100 coins, modulo 1000000.Medium5Dynamic programmingCombinatoricsNo attempts yet2s128 MBJudgeable
Random Walk That Never Goes NegativeCount length-2N walks from 0 back to 0 with steps of plus or minus 1 that never drop below 0, modulo 1,000,000,007.Medium5CombinatoricsMathNo attempts yet2s64 MBJudgeable
The number of studentsFind the smallest numbers of girls and boys whose within-group and cross-group friend counts match the given a, b, c, and d.Medium5MathNumber theory+1No attempts yet2s256 MBJudgeable
Algorithm Final ExamCount permutations of N items in which the first k positions are all wrong.Medium5CombinatoricsMathNo attempts yet1s128 MBJudgeable
Cut the CakeCount into how many regions the given infinite lines divide a circle.Medium5GeometryCombinatoricsNo attempts yet20s128 MBJudgeable
Farmer John has no large brown cowFind the Kth adjective combination in alphabetical order among all combinations except the N forbidden ones.Medium5CombinatoricsSortingNo attempts yet1s128 MBJudgeable
The Alphabet StickerCount completions of a sticker pattern where each question mark becomes a visible letter and every letter forms one contiguous block.Medium5CombinatoricsStringNo attempts yet1s128 MBJudgeable
Charity Booth RentalCount the strictly increasing positive triples GP, GA and PC that sum to T for each query.Medium5CombinatoricsMathNo attempts yet1s128 MBJudgeable
Number of LocksCount length-n strings over heights 1 to 4 that use at least three distinct heights and have an adjacent pair differing by exactly 3.Medium5Dynamic programmingCombinatoricsNo attempts yet1s128 MBJudgeable
OdometerCount the integers between X and Y whose decimal digits use one repeated digit except for a single different digit.Medium5Brute forceCombinatoricsNo attempts yet1s128 MBJudgeable
Club ScheduleCount attendance and key-passing schedules over N days where each day's leader attends and the key stays with attendees.Medium5Dynamic programmingCombinatoricsNo attempts yet1s128 MBJudgeable
Catalan SquareCompute the convolution sum S_n of Catalan numbers for a given n up to 5000 and print the exact integer.Medium5CombinatoricsMathNo attempts yet1s256 MBJudgeable
The Kth Anagram in Alphabetical OrderGiven a word and rank K, print the Kth distinct anagram of the word in alphabetical order.Medium5CombinatoricsStringNo attempts yet1s256 MBJudgeable
Zeroing a Binary SequenceCount ordered flip sequences of exactly K moves that turn a given binary sequence into all zeroes.Medium5CombinatoricsDynamic programmingNo attempts yet1s256 MBJudgeable
Restaurant RatingsCount how many nonnegative score sheets rank no better than the given sheet under total sum first and critic order second.Medium5CombinatoricsDynamic programmingNo attempts yet1s256 MBJudgeable
Pi Day Pie DistributionCount the nondecreasing distributions of n pie pieces among k people with each person getting at least one piece.Medium5Dynamic programmingCombinatoricsNo attempts yet1s256 MBJudgeable
Inherited diseaseFollow the birth-order path down D generations where a generation g member has g+1 children and print each breadth-first number modulo 1000000007.Medium5MathCombinatoricsNo attempts yet1s16 MBJudgeable
Uniting DepartmentsMerge departments pairwise at product-of-sizes cost and report the total cost and the number of ordered merge sequences modulo 1000000007.Medium5MathCombinatoricsNo attempts yet1s256 MBJudgeable
Attendance AwardCount length-N strings over L, O and A with at most one L and no three consecutive As for each N up to 3000.Medium5Dynamic programmingCombinatoricsNo attempts yet1s256 MBJudgeable
Next Unique-Digit NumberFind the smallest integer above N that uses no zero and repeats none of the digits 1 to 9, printing 0 when none exists.Medium5BacktrackingCombinatorics+1No attempts yet1s256 MBJudgeable
Football scorelinesCount the ordered scoring sequences by both teams that reach the given final score under the listed play values, modulo 1000000009.Medium5Dynamic programmingCombinatoricsNo attempts yet2s256 MBJudgeable
Krusty's BurgerCount burger combinations of size, bun, cheeses, toppings and sauces whose size plus extra-item cost is at most B.Medium5CombinatoricsMathNo attempts yet1s256 MBJudgeable
Delicious CookieSplit every piece of a right triangle with legs a and b N times along the altitude to the hypotenuse and print the natural log of the K-th largest piece area.Medium5CombinatoricsGeometry+1No attempts yet1s512 MBJudgeable
Running StepsCount left-right alternating sequences of one-step and two-step strides where both legs use equal counts and twos are at least as many as ones.Medium5CombinatoricsMathNo attempts yet1s256 MBJudgeable
Feast CoinsCount ways to reach total S with owned coins so that every chosen coin value appears the same number of times.Medium5Dynamic programmingCombinatoricsNo attempts yet3s256 MBJudgeable
Perica's PianoSort the N key values and add each value multiplied by the number of K-sets where it is the largest, modulo 1000000007.Medium5CombinatoricsSorting+1No attempts yet1s64 MBJudgeable