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
Ambiguous CodesDecide whether a set of hexadecimal code words is ambiguous, and if so report the length of the shortest message with two distinct decodings.Hard8StringGraph+2No attempts yet1s128 MBJudgeable
First!Given up to 30000 strings, find every string that can become lexicographically smallest under some permutation of the 26-letter alphabet.Hard8StringTrie+2No attempts yet1s128 MBJudgeable
Scrambled LettersGiven N scrambled names, find for each the lowest and highest rank its original anagram could occupy in an alphabetical ordering of all cows.Hard8StringSorting+2No attempts yet1s128 MBJudgeable
AppendGiven an LZ-style encoding as a list of (back-reference, length) pairs, count how many prefix positions split it into two valid non-empty encodings whose concatenation reproduces the original string.Hard8StringImplementation+2No attempts yet1s128 MBJudgeable
L-system SubstringGiven a D0L system over {a,b} and a query z, decide whether z appears as a contiguous substring of some word derivable from the start word.Hard8StringSimulation+2No attempts yet1s128 MBJudgeable
XenosemanticsFind words over lowercase letters delimited by varying spacer letters in a bit stream, then report the distinct true words that repeat and overlap another true word.Hard8StringHash map+2No attempts yet1s128 MBJudgeable
FoldGiven the sequence of A/V fold directions along an unfolded paper strip, find the minimum number of all-layer folding steps that produce it.Hard8Dynamic programmingRecursion+2No attempts yet1s128 MBJudgeable
Careful DeclarationMerge two word sequences into the shortest common supersequence, breaking ties by choosing the lexicographically smallest result.Hard8Dynamic programmingString+2No attempts yet2s128 MBJudgeable
God of the Vile BaskersFind the longest prefix of a string that contains no two substrings with the same multiset of k alphabetic characters, ignoring case.Hard8StringSliding window+2No attempts yet1s128 MBJudgeable
Transforming CometsGiven two cyclic sequences of integer points, decide whether one is a rotation, uniform positive scaling, and translation of the other, and report the matching cyclic offset.Hard8String matchingGeometry+2No attempts yet5s512 MBJudgeable
Post's Correspondence ProblemFind the shortest, lexicographically smallest index sequence whose A-concatenation equals its B-concatenation, under k < m.Hard8BFSString+2No attempts yet1s128 MBJudgeable
Ransom NoteGiven a target note and a newspaper text, find the minimum number of contiguous clips (letters and spaces only, case-insensitive, reusable) needed to paste the note.Hard8Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Automatic TradingGiven a string and pairs of positions, for each query find the length of the longest common prefix of the two suffixes starting at those positions.Hard8StringString matching+2No attempts yet5s128 MBJudgeable
The Palindromes Strike BackFor every position i, count the subsets of positions that include i and form a palindrome, then XOR all i times that count mod 1e9+7.Hard8Dynamic programmingCombinatorics+2No attempts yet2s1024 MBJudgeable
ASMFind the fewest add/multiply/print commands in a one-variable program whose printed concatenation matches every test's required output.Hard8Brute forceDynamic programming+2No attempts yet1s1024 MBJudgeable
Changing Phone NumbersGiven area codes and a sequence of rules (digit duplication, digit swap, area-code change) applied over time, answer queries transforming a phone number from one year to another.Hard8StringSimulation+2No attempts yet1s128 MBJudgeable
Puzzle OutGiven a dictionary and an encrypted uppercase text, recover the substitution cipher table or report no solution or multiple solutions.Hard8BacktrackingHash map+2No attempts yet1s128 MBJudgeable
DNA LaboratoryGiven up to 15 DNA strings, find the shortest string that contains all of them as substrings, breaking ties by lexicographic order.Hard8Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Missing LettersReconstruct a space-free corrupted string into words from a known vocabulary, choosing the highest-scoring word segmentation and breaking ties alphabetically.Hard8Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Identity CheckerEach test case gives a reverse Polish expression in x with sin, cos, and tan; decide whether it equals zero wherever defined.Hard8MathString+2No attempts yet1s128 MBJudgeable
CensorshipGiven a text and a filter word set, remove occurrences repeatedly to make the shortest possible result and report its length.Hard8Dynamic programmingString+1No attempts yet1s128 MBJudgeable
Vigenère CipherGiven a ciphertext and pair frequencies, find the key length-K shift maximizing the total frequency of adjacent plaintext letter pairs.Hard8Dynamic programmingString+1No attempts yet5s64 MBJudgeable
Cyclic Rotation CipherReconstruct the original lowercase string from its Burrows-Wheeler transform index i and last column R.Hard8StringSorting+1No attempts yet1s32 MBJudgeable
ByephoneFind the longest common subsequence of two strings up to length 10000 within 3MB of memory, breaking ties by the lexicographically smallest result.Hard8Dynamic programmingString+2No attempts yet2s3 MBJudgeable
EncodingFind the shortest encoding length for a target string under dynamic coding, where a changing marker toggles between verbatim and interpreted modes.Hard8Dynamic programmingStringNo attempts yet1s128 MBJudgeable
Beer NumbersDecide whether a positive integer is the only one that can produce its row of binary mugs under any choice of which mug position means 1 and which reading direction.Hard8StringCombinatorics+1No attempts yet1s128 MBJudgeable
NecklacesDecide whether two run-length compressed string descriptions encode the same circular necklace up to rotation.Hard8StringString matching+2No attempts yet1s128 MBJudgeable
Word EquationsCount the binary word assignments to variables of fixed lengths that make the two sides of a word equation equal.Hard8StringUnion-find+2No attempts yet1s128 MBJudgeable
Words 2Given exponents k1..kn, find the smallest m such that the concatenation of h_k(0) is a substring of h_m(0), or report NIE.Hard8StringRecursion+2No attempts yet1s128 MBJudgeable
WordsGiven indices k_i, decide whether the concatenation of the words h^{k_i}(0) appears as a substring of some h^m(0).Hard8StringDynamic programming+2No attempts yet1s128 MBJudgeable
BeadsSplit the bead string into blocks of size k (leftover dropped) and find the k that maximizes the count of distinct blocks, where a block and its reversal are the same.Hard8StringHash map+2No attempts yet1s128 MBJudgeable
AntisymmetryCount how many contiguous substrings of a binary string are antisymmetric, meaning each character differs from its mirror-position partner.Hard8StringHash map+2No attempts yet3s512 MBJudgeable
A Horrible PoemGiven a string and substring queries, find the length of the shortest full period of each substring, where a full period divides the substring into equal repeats.Hard8StringNumber theory+2No attempts yet8s128 MBJudgeable
PrefixuffixGiven a string t, find the maximum length L, at most n/2, such that the length-L prefix and the length-L suffix of t are cyclic rotations of each other.Hard8StringString matching+2No attempts yet3s512 MBJudgeable
TransformationsGiven two binary strings of length n, decide whether disjoint ab and ba fragments can be swapped repeatedly to turn the first string into the second.Hard8StringMath+2No attempts yet1s128 MBJudgeable
The Shortest PeriodDelete exactly one letter from a string to minimize the length of the shortest period of the resulting word.Hard8StringString matching+2No attempts yet5s128 MBJudgeable
TurnsFor each starting position, find how many turns must be observed before the position on the map becomes uniquely determined.Hard8StringString matching+2No attempts yet1s128 MBJudgeable
Almost ConjugatesDecide whether two length-n words are almost conjugates and, if so, list every rotation of the first that differs from the second in exactly one position.Hard8StringString matching+2No attempts yet1s128 MBJudgeable
Gordian DancesGiven a sequence of S (string swap) and R (quarter-turn) moves, find the minimum number of further moves that returns the dance to a horizontal, parallel, untangled state.Hard8MathString+2No attempts yet1s128 MBJudgeable
CiągBajtek needs the shortest string over the given alphabet that is not a subsequence of the word, and the lexicographically smallest among shortest such strings.Hard8Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Three-Bit ComputersThe task is to decide whether a target string over a, b and c can be built from uninitialized cells with the two pair operations.Hard8Dynamic programmingStringNo attempts yet1s128 MBJudgeable
General BytorGiven two permutations of n unit types and m cyclic position-shift orders, find the shortest (then lexicographically smallest) sequence of at most 10 orders that transforms the start into the target.Hard8Brute forceString+2No attempts yet1s128 MBJudgeable
RitualCount the subsequences of a long digit string that form a palindrome divisible by 666, then report ((count - 1) mod 666) + 1.Hard8Dynamic programmingString+2No attempts yet1s128 MBJudgeable
The Fibonacci GameDetermine whether the first player wins a game that erases Fibonacci words only from the right end of a given a/b string.Hard8String matchingDynamic programming+2No attempts yet1s128 MBJudgeable
PandoraGiven the left/right turn sequence of a rectilinear polygon, count the coordinate axes it is monotone with respect to.Hard8GeometryStringNo attempts yet1s128 MBJudgeable
Digital OnionGiven a balanced parentheses string, output the string that comes next in the defined price order.Hard8CombinatoricsRecursion+1No attempts yet1s128 MBJudgeable
Correcting CuriosityGiven two strings, find the length of the shortest substitution command that rewrites the first into the second.Hard8String matchingString+1No attempts yet2s256 MBJudgeable
PasswordsFind the longest prefix length and suffix length from two distinct set strings whose repetitions coincide.Hard8String matchingStringNo attempts yet7s128 MBJudgeable
Moves on an Infinite Binary TreeStarting from the node reached by S, count the distinct nodes reachable by following any subsequence of T on an infinite binary tree.Hard8Dynamic programmingTree+1No attempts yet2s128 MBJudgeable
RNAReport the longest contiguous block shared by both RNA strings whose parenthesis marks balance.Hard8Dynamic programmingString+1No attempts yet1s128 MBJudgeable
Eunki's DNA MoleculesFor every pair of N DNA strings, decide whether four two-way substring swaps can rewrite one into the other.Hard8MathString+1No attempts yet5s256 MBJudgeable
Ancient ScrollsRecover the lexicographically smallest string within Hamming distance d of three given strings, or print -1 when no such string exists.Hard8GreedyString+1No attempts yet8s256 MBJudgeable
Make a superpalindromeGiven a lowercase string, find the smallest superpalindrome of the same length that comes after it in lexicographic order.Hard8StringRecursion+1No attempts yet1s16 MBJudgeable
Selling NumbersCount how many D-digit strings, with leading zeros allowed, have exactly the memorability score S defined by palindromic and repeated substrings.Hard8BacktrackingCombinatorics+1No attempts yet2s256 MBJudgeable
SubstringsOrder all given strings as the consecutive length-L windows of one string of length L+N-1 and print the lexicographically smallest such string.Hard8GraphDFS+2No attempts yet2s256 MBJudgeable
Round wordsGiven two words of length up to 2000, pick a rotation or reversal of each to maximize the LCS length and print that maximum.Hard8Dynamic programmingStringNo attempts yet2s128 MBJudgeable
Birthday Numbers IIAdd up the products of every neighboring pair among the integers between x and y that use only the digits 3, 5 and 8, and report the total modulo 19980305.Hard8MathRecursion+2No attempts yet1s256 MBJudgeable
Fair and Square (Large2)Count numbers in each interval [A, B] that read the same forwards and backwards and equal the square of such a number.Hard8MathString+1No attempts yet5s512 MBJudgeable
Hongjun Likes StringsFor each of up to 100000 queries, find the shortest substring of a fixed string S that contains both given short patterns A and B, allowing overlap.Hard8StringString matching+2No attempts yet2s512 MBJudgeable
Maximum substring costGiven a string T, find the maximum of length times number of occurrences over all substrings S of T.Hard8StringSorting+2No attempts yet2s512 MBJudgeable
Flipping a Bit StringGiven a binary string and a divisor M of its length, find the minimum number of operations (single flip, prefix flip of a multiple of M, or suffix flip of a multiple of M) to make all characters 1.Hard8Dynamic programmingGreedy+1No attempts yet2s512 MBJudgeable
Counting strings with LCS n-1Count length-n strings over the first m letters whose longest common subsequence with a given string S has length exactly n-1.Hard8Dynamic programmingCombinatorics+1No attempts yet2s512 MBJudgeable
Fewest letters for a suffix arrayGiven a permutation that is a suffix array, find the minimum number of distinct letters needed for a string that realizes exactly this suffix array.Hard8StringGreedy+2No attempts yet2s512 MBJudgeable
Calculation mistakeMaintain a string of digits and plus or minus signs under range replacements, and evaluate the arithmetic value of any substring with the calculator's operator rules.Hard8Segment treeString+1No attempts yet3s256 MBJudgeable
PasswordGiven a length-N string, collect all distinct substrings meeting four counts (length, digits, specials, uppercase), sort them lexicographically, and print the middle one.Hard8StringSorting+2No attempts yet4s512 MBJudgeable
Big Number MultiplicationMultiply two non-negative integers of up to 300,000 digits each and print the exact product without leading zeros.Hard8MathString+1No attempts yet3s512 MBJudgeable
Good SubstringsCount how many distinct substrings of a binary string appear twice at non-overlapping positions.Hard8StringString matching+2No attempts yet2s512 MBJudgeable
New Store NameSplit each of two short strings into two non-overlapping contiguous pieces so that A+C equals B+D, and output the lexicographically smallest longest result.Hard8StringBrute force+1No attempts yet2s512 MBJudgeable
Substitution Cipher KeyGiven N distinct words and a target permutation, find the lexicographically smallest substitution cipher key that sorts the encrypted words into that order, or report none.Hard8GreedySorting+2No attempts yet1s64 MBJudgeable
Palindromes and QueriesSupport range character assignments and count palindromic substrings of length at most K inside a queried range.Hard8Segment treeString+2No attempts yet2s512 MBJudgeable
What NextGiven a prefix of an NZPC Speak program cut at an arbitrary point, list the symbols that can legally come next, respecting declarations, masking, and partial names.Hard8ImplementationSimulation+2No attempts yet2s512 MBJudgeable
Revenge of the Champernowne ConstantGiven a digit string S of length up to 100, find the 1-indexed position of its first occurrence in the Champernowne constant 0.123456789101112...Hard8StringMath+2No attempts yet8s512 MBJudgeable
Palindrome cipher decryptionFor each string, find its longest palindromic subsequence and output the lexicographically smallest one among those of maximal length.Hard8Dynamic programmingString+2No attempts yet8s512 MBJudgeable
Favorite musicGiven n note strings and q pairs, find the shortest string containing both given fragments as contiguous substrings, allowing overlap.Hard8String matchingTrie+2No attempts yet1s256 MBJudgeable
Game of MatchingsCount substrings of S that match pattern P under a bijective letter-to-number mapping, where distinct numbers must get distinct letters.Hard8String matchingString+2No attempts yet2s512 MBJudgeable
Arranging HatEach of n m-digit strings may have individual digits rewritten; find the minimum number of digit changes so the sequence becomes nondecreasing.Hard8Dynamic programmingGreedy+2No attempts yet5s512 MBJudgeable
Binary CodeEach of n binary words has at most one unreadable bit; decide whether the ?s can be filled so no word is a prefix of another.Hard8TrieGreedy+2No attempts yet2s2048 MBJudgeable
K-th good stringGiven a bracket string S, list the distinct good strings that appear as subsequences in lexicographic order and print the K-th one.Hard8Dynamic programmingString+1No attempts yet2s512 MBJudgeable
Substring appearing twiceGiven a string and at most K letter replacements, maximize the length of the longest substring that occurs at two different starting positions, allowing overlap.Hard8StringBinary search+2No attempts yet6s128 MBJudgeable
ZvonimirFind the minimum number of operations (type one letter, or copy a contiguous block of already typed text and append it) to produce string X.Hard8Dynamic programmingString+2No attempts yet2s128 MBJudgeable
ExpressionParse a two-dimensional rendering of nested fractions, additions, multiplications, and divisions, then print the reduced value as a fraction.Hard8ImplementationRecursion+2No attempts yet2s512 MBJudgeable
RhymeGiven N distinct words, find the longest sequence using each word at most once where consecutive words rhyme: their longest common suffix has length at least the longer word's length minus one.Hard8StringTrie+2No attempts yet1s256 MBJudgeable
f(X) = A + X + B + X + CCount occurrences of pattern F in the K-fold string expansion f(X)=A+X+B+X+C applied to S, modulo 1e9+7.Hard8String matchingDynamic programming+2No attempts yet2s512 MBJudgeable
Integeregex (Large)Count integers in [A, B] whose decimal form (no leading zeros) matches a small regular expression over digits.Hard8Dynamic programmingString+2No attempts yet5s512 MBJudgeable
String TableBuild a table whose cells are huge concatenated strings defined by comparing neighbors, then print 50 characters from a given position of the final cell.Hard8Dynamic programmingString+2No attempts yet2s512 MBJudgeable
Palindromes and Queries 2Given a string and queries, each query asks how many palindromic substrings start at a given index with length at least a given value.Hard8StringString matching+2No attempts yet2s512 MBJudgeable
Period of a Slot MachineGiven a sequence of n outcomes, find k and p minimizing k+p (ties by smaller p) such that T[i+p]=T[i] for all i>k with i+p<=n.Hard8String matchingImplementation+1No attempts yet2s512 MBJudgeable
Jumping FrogGiven a circular string of rocks and ponds, count the step sizes K (1 to N-1) for which some rock's K-step cycle stays entirely on rocks.Hard8Number theoryMath+2No attempts yet1s1024 MBJudgeable
Long Long StringsDecide whether two sequences of insertions and deletions, applied to any sufficiently long string, produce identical results.Hard8StringMath+2No attempts yet1s512 MBJudgeable
Flipping OutCount the strings that, added to the given patterns, make the flip rule reproduce the given flip sequence, or -1 if infinitely many work.Hard8StringDynamic programming+2No attempts yet2s512 MBJudgeable
String PuzzleGiven equality hints between substrings of a huge implicit string plus some fixed letters, decide the letters at the queried positions. The hint structure is a partition of the string into sections, and a hint joins one section to an earlier same-length section, so the constraints are interval equalities on an unknown string of length n; the task is to propagate equality and fixed letters across positions, answering ? where a position's letter is not forced. The input size is small (at most 1000 hints and 1000 queries) but n can be 10^9, so positions cannot be enumerated directly and the hint/Hard8StringUnion-find+1No attempts yet2s512 MBJudgeable
MarsFor each query substring, find the minimum number of bit flips that make it match no substring of the DNA, or report Impossible.Hard8String matchingDynamic programming+1No attempts yet2s512 MBJudgeable
RetroGiven a grid where the player moves horizontally while objects fall one row per turn, collect brackets to form the longest valid expression and output the lexicographically smallest one of that length.Hard8Dynamic programmingGreedy+2No attempts yet0.5s512 MBJudgeable
Concert Attendance SchedulesCount the ways to pick increasing day positions matching a target band sequence, where each pick must wait h_b+1 days after that band's previous pick.Hard8Dynamic programmingStringNo attempts yet0.3s128 MBJudgeable
Vera and the BanquetGiven a circular string S, count the number of distinct substrings appearing in any contiguous block read in either direction around the circle.Hard8StringString matching+2No attempts yet2s512 MBJudgeable
Standing Out from the HerdFor each name in the herd, count its substrings that occur in no other name.Hard8StringString matching+2No attempts yet2s512 MBJudgeable
Operation OptimizationFind the shortest sequence of append-0, append-1, and self-doubling operations whose two-fold application to the empty string yields a given binary string S.Hard8StringGreedy+2No attempts yet2s256 MBJudgeable
Big Number Multiplication (2)Multiply two integers of up to 300,000 digits each, too large for quadratic multiplication, and print the exact product.Hard8MathDivide and conquer+2No attempts yet2s512 MBJudgeable
Hit of the SeasonFind the shortest print matrix over R, G, B that can reproduce a wallpaper string, where specified stripes must never be overprinted and at most 19 stripes are unspecified.Hard8StringBrute force+2No attempts yet2s512 MBJudgeable
Go with the FlowChoose a line width for justified monospaced text, then find the longest run of spaces that drifts by at most one column per line, and report the best width and length.Hard8Brute forceString+2No attempts yet12s1024 MBJudgeable