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
Health Plan ComparisonParse free-text health plan descriptions to extract premiums and copay rules, then compute each plan's total yearly cost across the given visits.Medium7StringImplementation+2No attempts yet1s128 MBJudgeable
Polly Wants a CrackerMatch each spoken word to a distinct original word minimizing total Levenshtein edit distance, and report that minimum sum.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
MinersAssign each of N shipments in order to one of two mines; each shipment scores 1 to 3 based on how many distinct kinds appear among it and the previous two shipments at that mine, and the goal is to maximize the total.Medium7Dynamic programmingString+1No attempts yet1s128 MBJudgeable
Run, IOI TrainDiscard a prefix from each of two I/O strings, then interleave the remaining fronts to build the longest alternating string that starts and ends with I.Medium7Dynamic programmingTwo pointers+2No attempts yet1s128 MBJudgeable
String FarmGiven up to 10^4 strings, find the longest chain where each string is a contiguous substring of the next, all photos distinct.Medium7StringDynamic programming+2No attempts yet5s128 MBJudgeable
Emoticons :-)Given a set of emoticon strings, replace the fewest characters with spaces across several text lines so that no emoticon appears consecutively in any line.Medium7String matchingDynamic programming+2No attempts yet1s128 MBJudgeable
Insidious BrandingCount quadruples of dictionary words A, B, C, D with A+B = C+D and length(A) < length(C).Medium7Hash mapStringNo attempts yet2s128 MBJudgeable
NecklaceGiven a string and a pattern, delete the fewest characters so the pattern no longer appears as a contiguous substring.Medium7Dynamic programmingString matching+2No attempts yet1s128 MBJudgeable
Threatening LetterGiven a newspaper string and a message, split the message into the fewest contiguous pieces, each of which appears somewhere in the newspaper. Output that minimum count.Medium7StringDynamic programming+2No attempts yet1s128 MBJudgeable
Forgotten PasswordFind the lexicographically smallest length-L string that matches a pattern of known letters and '?' and can be written as a concatenation of given dictionary words.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
VimGiven a string over a-j, find the minimum Vim keypresses (x, h, and f C) to delete every 'e' without touching other characters, starting with the cursor at index 0.Medium7Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Formatting TextBreak a paragraph into lines of fixed width, choosing line breaks to minimize total badness with a lexicographic tie-break on gap widths.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
WordApply a cyclic cellular rewriting rule s times to a binary word of length n, then print the lexicographically smallest rotation.Medium7StringSimulation+2No attempts yet1s128 MBJudgeable
DehuffGiven a sample string and its full binary encoding, reconstruct the unique prefix-code table for the alphabet, or report several possible tables.Medium7TreeDFS+2No attempts yet1s128 MBJudgeable
Calculator LanguageEvaluate expressions in a tiny language with right-associative equal-precedence operators, assignment, and right-to-left operand evaluation, then report changed variables.Medium7ImplementationRecursion+2No attempts yet1s128 MBJudgeable
String DecodingGiven a string, a permutation, and a large repetition count m, recover the string that the permutation maps to the given encoded string.Medium7MathImplementation+2No attempts yet1s128 MBJudgeable
New FruitFor each pair of strings, output the shortest common supersequence, breaking ties by choosing the lexicographically smallest one.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Corporate IdentityGiven up to 4000 short lowercase strings, find the longest string that occurs as a contiguous substring of every one, breaking ties by lexicographic order.Medium7StringString matching+2No attempts yet1s128 MBJudgeable
IVXLCDMGiven a lowercase inscription line, find the largest value of a valid Roman numeral readable as a subsequence of its letters, or 0 if none.Medium7GreedyString+2No attempts yet1s128 MBJudgeable
RepetitivityCompute the sum of squared occurrence counts over all distinct subsequences of a string, modulo M.Medium7StringDynamic programming+2No attempts yet2s512 MBJudgeable
Mhocskian LanguagesGiven a context-free grammar in Chomsky normal form and a list of words, decide for each word whether the start variable can derive it.Medium7Dynamic programmingString+2No attempts yet2s512 MBJudgeable
DinnerGiven a line of G and H programmers, repeatedly remove a run of at least K equal letters; find the minimum number of removals to clear the line, or -1.Medium7Dynamic programmingIntervals+2No attempts yet1s128 MBJudgeable
SubstringsCount the distinct substrings of a string, including the empty string and the whole string, for up to 5000 characters per test case.Medium7StringTrie+2No attempts yet1s128 MBJudgeable
TripGiven two strings, print all longest common subsequences in lexicographic order without duplicates.Medium7Dynamic programmingBacktracking+2No attempts yet1s128 MBJudgeable
Lazy Math InstructorDecide whether two arithmetic expressions with left-to-right equal-precedence operators are identical as polynomials over single-letter variables.Medium7Hash mapString+2No attempts yet1s128 MBJudgeable
Shortest Regular Brackets SequenceGiven a string of brackets, find the length of the shortest regular bracket sequence that contains it as a subsequence.Medium7Dynamic programmingIntervals+2No attempts yet1s128 MBJudgeable
Computer DialogueGiven file names split into name and extension parts, simulate the alternating 'I don't know' messages between two clients and list files still possible after M messages.Medium7SimulationHash map+2No attempts yet1s128 MBJudgeable
DictionaryGiven a list of words, insert leading spaces so the list satisfies a recursive definition: every maximal run of words sharing a first letter must, after removing the first word and that letter, again be a dictionary.Medium7TrieRecursion+2No attempts yet1s128 MBJudgeable
ArtinalsInterpret a small language over hereditarily finite sets, evaluating assignments, expressions and relations, and print reduced canonical set representations.Medium7StringImplementation+2No attempts yet1s512 MBJudgeable
Dictionary of Obscene WordsGiven dictionary words and a text, find the length of the shortest prefix of the text containing some word as a subsequence.Medium7Dynamic programmingString+1No attempts yet1s128 MBJudgeable
Hexaroman NumbersParse and output hexadecimal Roman numerals, choosing the shorter of additive or subtractive notation per digit, then evaluate +, -, and * expressions.Medium7StringImplementation+2No attempts yet1s128 MBJudgeable
PalindromesFor each number in a small interval written in base b, apply reverse-and-add up to l times and count how many do not reach a palindrome.Medium7SimulationMath+2No attempts yet1s128 MBJudgeable
List CalculatorImplement an interpreter for a small list language with slicing, unary and binary elementwise operators, concatenation, and single-character variable assignment.Medium7ImplementationRecursion+2No attempts yet1s128 MBJudgeable
Edit DistanceGiven strings A and B up to length 17000, find the minimum number of insert, delete, and substitute operations to turn A into B.Medium7Dynamic programmingStringNo attempts yet8s128 MBJudgeable
Reverse NumbersGiven up to 10000-digit numbers M, decide whether some N satisfies M = N + Rev(N).Medium7StringMath+1No attempts yet1s32 MBJudgeable
Roman CorridorFind a left-to-right path through the grid whose symbol string is a valid Roman numeral and has the smallest decimal value.Medium7DFSGraph+2No attempts yet1s128 MBJudgeable
TemplateFind a template whose overlapping occurrences cover every position of S, minimizing the template length.Medium7StringString matching+1No attempts yet3s128 MBJudgeable
The Number of Symmetrical ChoicesGiven two word sequences of length n, count how many of the 2^n ways of picking one word per index produce a palindrome when concatenated.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
GenotypesGiven budding rules A1 -> A2 A3, decide for each target word whether it can be derived from some number of supergenes S, and report the minimum count.Medium7Dynamic programmingIntervals+2No attempts yet1s128 MBJudgeable
Word EqualizingAppend the given words to x and y any number of times to make them equal, and output the minimum total number of appends, or NIE if impossible.Medium7StringGraph+2No attempts yet1s128 MBJudgeable
Even Palindrome DecompositionDecide whether a string can be split entirely into even-length palindromes, and if so report the minimum and maximum number of parts.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
PalindromesGiven n distinct palindromes, count ordered pairs whose concatenation is also a palindrome, with total length up to 2,000,000.Medium7StringHash map+2No attempts yet5s256 MBJudgeable
BBBFind the minimum cost to fix a + and - statement so the balance starts at p, never goes negative, and ends at q, using character flips and rotations.Medium7GreedyPrefix sum+1No attempts yet1s128 MBJudgeable
TrainsAfter each of m car swaps, track the largest number of trains that ever shared each train's exact colour string.Medium7Hash mapString+1No attempts yet1s128 MBJudgeable
Squared WordsGiven a lowercase string, delete the fewest letters so the remaining letters, in order, form a squared word xx.Medium7Dynamic programmingStringNo attempts yet1s128 MBJudgeable
Type Two de Bruijn SequencesGiven a binary string, append the fewest digits so that every length-n binary word appears as a subsequence.Medium7GreedyString+1No attempts yet2s512 MBJudgeable
WordsGiven a word of length n, find the smallest number of blocks in a word that differs from it in at most k positions.Medium7Dynamic programmingStringNo attempts yet1s128 MBJudgeable
Room NumbersCount the distinct numbers formed by flipping each 6 or 9 in n independently that are at most h, modulo 9999997.Medium7Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Banner RepairTransform one uppercase banner string into another with block insertions and deletions where each block of length S costs X plus S times Y.Medium7Dynamic programmingStringNo attempts yet10s128 MBJudgeable
Popping GroupsDecide whether a string of a and b can be fully erased by repeatedly deleting maximal runs of at least two equal letters.Medium7Dynamic programmingString+1No attempts yet2s128 MBJudgeable
CipherGiven total character volume, word count, and rank, reconstruct the I-th message in lexicographic order or report corruption.Medium7Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Heavy Chain ClusterizationSplit n antibody chains into the fewest groups so each group shares the same first k or last k letters.Medium7GraphStringNo attempts yet2s256 MBJudgeable
Nested PalindromeFill each question mark with a digit to build the k-th smallest nested palindrome with no equal adjacent digits, or print -1.Medium7RecursionCombinatorics+1No attempts yet2s128 MBJudgeable
Decoding the HallwayFor each query, decide whether the given string appears as a contiguous substring of the turn record built after n hallway walks.Medium7StringRecursion+2No attempts yet1s128 MBJudgeable
Infix to PrefixGiven a prefix expression with spaces and parentheses removed, compute the smallest and largest values over all valid parses.Medium7Dynamic programmingIntervals+1No attempts yet5s128 MBJudgeable
WeatherReconstruct the first and last days of a weather string from its multiset of length-d substrings, choosing the alphabetically smallest pair when several fit.Medium7GraphStringNo attempts yet2s512 MBJudgeable
XenospeakGiven words per page and a page number, print the first and last words on that page over tilings of a, ab and bb ordered by length then alphabetically.Medium7CombinatoricsDynamic programming+1No attempts yet1s128 MBJudgeable
Secret MessageCount the operation sequences that build the given string by repeatedly prepending or appending a proper prefix or suffix.Medium7Dynamic programmingString+1No attempts yet1s128 MBJudgeable
PalindromeFind the palindromic substring that maximizes its length times its number of occurrences in the given string.Medium7String matchingStringNo attempts yet2s128 MBJudgeable
A Cure for the Common CodeCompute the shortest encoded length of each lowercase string using count-plus-parentheses notation for repeats.Medium7Dynamic programmingStringNo attempts yet5s256 MBJudgeable
Black and White StonesShagga reorders black and white stones so all black stones stand left of white ones with minimum cost, paying A per swap and A minus B for adjacent swaps.Medium7Dynamic programmingGreedy+1No attempts yet3s256 MBJudgeable
Repeated Substring CountCount the distinct substrings that occur at least twice in each string of up to 100000 letters.Medium7String matchingStringNo attempts yet5s256 MBJudgeable
VocabularyCount ways to replace every question mark with a lowercase letter so the three words are distinct and in lexicographic order.Medium7Dynamic programmingString+1No attempts yet5s256 MBJudgeable
LRFill each ? with an allowed character to form a valid L and R expression with the largest possible value, or report invalid.Medium7Dynamic programmingString+1No attempts yet2s128 MBJudgeable
Palindromic PathsCount distinct palindromic strings spelled by right-down paths from the top-left to the bottom-right of an N by N letter grid.Medium7DFSHash map+1No attempts yet1s256 MBJudgeable
369 Game CountCount numbers from A to B that are multiples of 3 or contain the digit 3, 6, or 9, and output the count modulo 20150523.Medium7Dynamic programmingString+1No attempts yet1s256 MBJudgeable
Counting Soundex StringsCount case-insensitive strings up to length L whose Soundex code equals the given code, modulo 1000000007.Medium7Dynamic programmingString+1No attempts yet1s256 MBJudgeable
String StretchingGiven a lowercase string up to length 200, find the shortest base string that builds it by repeated insertions anywhere, breaking ties alphabetically.Medium7Dynamic programmingString+1No attempts yet1s256 MBJudgeable
Word LadderPick one new word to add to the dictionary so the single-letter ladder from the first word to the second is as short as possible.Medium7BFSGraph+2No attempts yet3s256 MBJudgeable
The Fox and the OwlGiven a huge integer N, print the largest integer below N whose digit sum is exactly one more than that of N.Medium7GreedyString+1No attempts yet1s256 MBJudgeable
PLAY in BASICGiven a Music Macro Language score, find the character length of the shortest score with identical pitches, note lengths, volumes, and rests.Medium7Dynamic programmingSimulation+1No attempts yet5s512 MBJudgeable
Alpaca SentenceFind the K-th string in lexicographic order among the shortest palindromes that contain S as a subsequence, or report NONE.Medium7Dynamic programmingString+1No attempts yet3s256 MBJudgeable
Albocede DNA (Small)Count subsequences of S that split into blocks of the form a^i b^j c^i d^j with i and j at least 1, modulo 1e9+7.Medium7Dynamic programmingString+1No attempts yet5s512 MBJudgeable
Reordering Train Cars (Small)Count the orders of the given letter strings whose concatenation keeps every equal letter in one contiguous block.Medium7GraphCombinatorics+1No attempts yet5s512 MBJudgeable
Reordering Train Cars (Large)Count the orders of the given strings that keep all equal letters contiguous without reversing any string, modulo 1,000,000,007.Medium7GraphCombinatorics+1No attempts yet5s512 MBJudgeable
The Killer Word (Large)Choose the dictionary word that forces the most wrong letter guesses from a guesser who tries letters in a fixed order while ruling out inconsistent words.Medium7TrieSimulation+1No attempts yet5s512 MBJudgeable
Distinct valid bracket subsequencesCount distinct non-empty balanced bracket strings that appear as subsequences of a given bracket string of length at most 100, modulo 1,000,000,007.Medium7Dynamic programmingString+2No attempts yet2s512 MBJudgeable
Next Special StringGiven a binary special string (each split satisfies U < V), find the next special string of the same length in lexicographic order, or -1 if none exists.Medium7StringGreedy+2No attempts yet2s512 MBJudgeable
Palindrome WalkGiven an undirected labeled graph, find the length of the shortest walk from vertex 0 to vertex 1 whose edge-label string is a palindrome, or -1 if none exists.Medium7BFSGraph+2No attempts yet2s512 MBJudgeable
Splitting a StringChoose K non-overlapping substrings of A that also appear in B in the same non-overlapping order, maximizing their total length.Medium7Dynamic programmingString+1No attempts yet2s512 MBJudgeable
Suffix Array 1Given S, decide whether some lexicographically smaller string of the same length has an identical suffix array. Constraints: |S| <= 50.Medium7StringSorting+1No attempts yet2s512 MBJudgeable
K-InversionsFor every distance k, count pairs (i,j) with i<j, s[i]='B', s[j]='A', and j-i=k, over a string of up to a million characters.Medium7Divide and conquerString+2No attempts yet10s512 MBJudgeable
Bracket MatchGiven a lowercase string S, find the lexicographically smallest matching bracket sequence, or print -1 if none exists.Medium7StackGreedy+1No attempts yet2s512 MBJudgeable
Reading the stone slabAfter each range replacement on a string, count the number of subsequences equal to a given name of length at most 5, modulo 1e9+7.Medium7Dynamic programmingSegment tree+1No attempts yet4s256 MBJudgeable
Suffix array 2Sort all suffixes of a string lexicographically and output the starting index of each suffix in sorted order.Medium7StringSorting+1No attempts yet2s512 MBJudgeable
Longest palindromic substringFind the length of the longest contiguous substring of S that reads the same forwards and backwards.Medium7StringBinary search+1No attempts yet0.5s512 MBJudgeable
Pry Sequence TransformationFind the minimum edit distance between strings A and B under weighted insert, delete, and replace costs, or print TOSS if it exceeds budget K.Medium7Dynamic programmingStringNo attempts yet2s512 MBJudgeable
Chameleon SubstringGiven a string S, find the longest substring that is both a prefix and a suffix of S and also appears somewhere strictly inside S.Medium7String matchingString+1No attempts yet2s512 MBJudgeable
Bracket substring queriesFor each query substring, find the length of the longest balanced bracket subsequence within it.Medium7Prefix sumString+2No attempts yet2s512 MBJudgeable
K-th SubstringSort every substring of S lexicographically and print the K-th one, or -1 if there are fewer than K substrings.Medium7StringSorting+1No attempts yet2s512 MBJudgeable
Prefix and SuffixFor each prefix of S that is also a suffix, output its length and how many times it occurs as a substring.Medium7String matchingPrefix sum+1No attempts yet2s512 MBJudgeable
Palindromic SubsequenceGiven a string and marked positions, find a palindromic subsequence covering the most marked positions, and report the length of the longest such one.Medium7Dynamic programmingStringNo attempts yet1s512 MBJudgeable
Same wordGiven two sets of binary words, decide whether some nonempty concatenation of words from the first set equals some nonempty concatenation from the second.Medium7StringBFS+2No attempts yet2s512 MBJudgeable
Strings and QueriesFor a string S, F(i) is the length of the longest common suffix of S and the prefix of S ending at position i; answer M queries for F(i).Medium7StringString matching+2No attempts yet2s512 MBJudgeable
Buggy RobotGiven a grid and an existing command string, insert or delete single commands at minimum cost so the robot reaches the exit.Medium7Dynamic programmingBFS+1No attempts yet2s512 MBJudgeable
Full Text SearchFor each query, find the shortest letter string whose set of length-1 and length-2 substrings contains the query's set but which does not contain the query itself.Medium7StringGraph+2No attempts yet8s512 MBJudgeable
Alice in FoxlandGiven two strings X and Y, find the longest common subsequence of X and Y that contains a required substring C as a contiguous block, or report impossible; among ties pick the lexicographically smallest.Medium7Dynamic programmingString+2No attempts yet8s512 MBJudgeable
CastleMaintain a growing string under appends, insertions of the whole current string into a set, and queries counting how many stored strings are suffixes of the current string.Medium7StringTrieNo attempts yet0.5s256 MBJudgeable
Reading DigitsDecode the given run-length-encoded string k times, then report the digit at index pos of the original string s.Medium7StringImplementation+1No attempts yet0.1s256 MBJudgeable
StickersParse a comma-separated list of sticker numbers and ranges with leading zeros, deduplicate, then output the shortest valid representation with fewest commas.Medium7StringImplementation+2No attempts yet0.5s256 MBJudgeable