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 results907 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
&+ +&Over all N^2 pairs, compute the sum modulo 1999 of pairwise ANDs, and the bitwise AND of all pairwise sums.Medium5Bit manipulationMath+1No attempts yet1.5s512 MBJudgeable
Life on a TorusSimulate Conway's Life on a wrapped 8x8 torus and find the smallest repeat period reached after any transient.Medium5SimulationHash map+1No attempts yet2s512 MBJudgeable
Binary StringDelete the fewest bits from a binary string so the remaining subsequence keeps no leading zeros and has value at most K.Medium5StringGreedy+2No attempts yet0.5s512 MBJudgeable
Nim Game 3Given Nim pile sizes, count how many first moves (choosing a pile and removing stones) leave the opponent in a losing position.Medium5Game theoryBit manipulation+2No attempts yet1s512 MBJudgeable
From A to BGiven two integers a and b, find the minimum number of operations (divide an even number by two, or add one) needed to turn a into b.Medium5GreedyBit manipulation+2No attempts yet1s512 MBJudgeable
Word MemorizationTrack which letters are currently remembered and, after each forget or recall query, report how many dictionary words contain only remembered letters.Medium5Bit manipulationHash map+2No attempts yet4s1024 MBJudgeable
Looking for TasteGiven N numbers, choose at most K of them so their bitwise OR is as large as possible.Medium5Bit manipulationGreedy+2No attempts yet3s512 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
Painting ExchangeGiven who can sell to whom at what price, find the longest chain of distinct buyers starting from artist 1 where each resale price never drops below the purchase price.Medium6Dynamic programmingBit manipulation+2No attempts yet2s128 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
Power PlantsGiven restart costs between plants and which plants are already on, find the minimum total cost to reach at least P working plants, or -1.Medium6Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
FencesPartition up to 16 given fence lengths into disjoint triples, keep only triples that form a valid triangle, and maximize the total area.Medium6Dynamic programmingBit manipulation+2No attempts yet2s128 MBJudgeable
Making WordsFor each 3x3 letter board, find which center letters yield the fewest and the most dictionary words of length 4 or more, along with those counts.Medium6StringBit manipulation+2No attempts yet1s128 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
Moonlit Maze EscapeFind the shortest path from start to any exit in a grid maze where doors need matching keys collected along the way, tracked as key-state BFS.Medium6BFSBit manipulation+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
Coin FlippingGiven an N by N grid of H/T coins (N up to 20), find the minimum number of tails achievable by flipping any subset of rows and columns.Medium6Bit manipulationBrute force+2No attempts yet6s128 MBJudgeable
Assigning Tasks 1Given an N by N cost matrix, assign each person exactly one task to minimize the total assignment cost.Medium6Dynamic programmingBit manipulation+1No attempts yet1s512 MBJudgeable
Friendly BrothersGiven a reduced fraction a/b, find the shortest repeating turn pattern (length at most 60) of two people eating half the remaining cake so one person's total share equals a/b.Medium6Number theoryMath+2No attempts yet2s128 MBJudgeable
Sum of Largest Power-of-Two DivisorsGiven A and B up to 10^15, compute the sum over that range of the largest power-of-two divisor of each integer.Medium6MathNumber 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
Nice NumbersCount integers in the range [L, R] whose binary representation has three consecutive equal bits, using digit DP over bits.Medium6Dynamic programmingBit manipulation+1No attempts yet2s128 MBJudgeable
Coin Flips IIGiven an N by M grid of coins, find the minimum number of top-left rectangle flips needed to turn every coin to heads.Medium6MatrixGreedy+1No attempts yet2s128 MBJudgeable
Maze EscapeFind the minimum time to escape a maze where the player can press a button to rotate an entire row and column of rooms by 90 degrees, changing their door layout.Medium6BFSBit manipulation+2No attempts yet2s128 MBJudgeable
Turning On the LightsFind the minimum number of bulb presses, each flipping a cell and its 8 neighbors, needed to turn all bulbs on an N×M grid (N,M ≤ 8) on, or report impossibility.Medium6Bit manipulationBrute force+2No attempts yet2s128 MBJudgeable
Coin FlipsFind the minimum number of row and column flips on an odd N by M 0/1 grid so every row and column has an even count of 1s, or output -1.Medium6MathBit manipulation+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
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
Turning Off the LightsGiven a row of L bulbs and a fixed T-slot switch device that can be pressed at any aligned position any number of times, find the minimum number of bulbs left on.Medium6Dynamic programmingBit manipulation+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
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
Card GameGiven 9 piles of 4 cards, compute the probability that repeatedly removing a uniformly random matching-rank pair of top cards clears all cards.Medium6ProbabilityDynamic programming+1No attempts yet2s128 MBJudgeable
CiphertextGiven up to 40 positive integers and a target K, find a subset (as a bitstring) whose sum equals K, exploiting the small total sum with meet-in-the-middle or subset-sum search.Medium6Dynamic programmingBit manipulation+1No attempts yet2s128 MBJudgeable
Binary XORGiven binary strings, find the closest achievable XOR combination (using at least one XOR) to a target, breaking ties by fewest operations then lexicographic order.Medium6Bit manipulationMath+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
LampsGiven N lamps in a circle updating by XOR with the right neighbor each second, compute the states after M steps efficiently using binary exponentiation over XOR shifts.Medium6Bit manipulationMath+1No attempts yet5s128 MBJudgeable
Word ChainGiven up to 16 vowel-only words, chain them by matching first and last letters without repeats to maximize the total length used.Medium6Bit manipulationDynamic programming+1No attempts yet2s128 MBJudgeable
LieDetect the first parity query in a sequence that becomes inconsistent with earlier ones, using weighted union-find over prefix-sum parities.Medium6Union-findBit manipulation+1No attempts yet2s128 MBJudgeable
Hamming PathGiven N binary codes, build implicit graph edges between codes at Hamming distance 1 and output shortest paths from code 1 to each queried code via BFS.Medium6BFSBit manipulation+1No attempts yet1s128 MBJudgeable
Coin Flipping 2Given an N x N grid of H/T coins, find the minimum number of tails achievable by flipping any subset of rows and columns.Medium6Brute forceBit manipulation+1No attempts yet1s128 MBJudgeable
QR DecodingParse a 19-byte QR data payload bit by bit and decode its numeric, alphanumeric, byte, and kanji mode segments into a formatted output string.Medium6Bit manipulationString+2No attempts yet1s128 MBJudgeable
Logical Expression EquivalenceParse two concatenated boolean expressions with C-style operator precedence and decide if they are logically equivalent for all variable assignments.Medium6StringBrute force+1No attempts yet1s128 MBJudgeable
Childhood Toy BoxesCount subsets of N boxes (as bitmasks over M<=20 toy types) whose union covers all M types, modulo 1e9+7.Medium6Bit manipulationDynamic programming+2No attempts yet2s128 MBJudgeable
Bored JungyuGiven XOR values of a lowercase/period/space plaintext with a digit key, decide for each position whether the original was a letter or a period/space.Medium6Bit manipulationBrute force+1No attempts yet1s128 MBJudgeable
XOR ShapesGiven up to 10 right isosceles triangles drawn with XOR-style color inversion, compute the total black area after all draws.Medium6GeometryBit manipulation+1No attempts yet1s128 MBJudgeable
Agent Mission AssignmentGiven an N x N matrix of success percentages, assign one mission per agent to maximize the product of chosen probabilities, essentially an assignment problem with a product (log-sum) objective.Medium6Dynamic programmingBit manipulation+1No attempts yet1s128 MBJudgeable
Processor DesignReconstruct lexicographically smallest initial 32-bit register values consistent with a sequence of bit-rotation and XOR-output commands, using union-find over bits with XOR relations.Medium6Union-findBit manipulation+1No attempts yet1s128 MBJudgeable
Lazy TelegraphFor each dictionary word to be sent, find a same-length string minimizing total transmission time (dots=1s, dashes=2s) so that it is the unique closest dictionary word by Hamming distance, then sum the minimum times.Medium6Brute forceString+2No attempts yet1s128 MBJudgeable
Monkey in the LabyrinthFind the shortest path in a labyrinth where rooms can be locked or unlocked and up to 8 switches toggle groups of room states, using BFS over a state space that combines room and switch configuration.Medium6BFSBit manipulation+1No attempts yet1s128 MBJudgeable
KnightGiven an N×N board with M forbidden squares, find the maximum number of knights placeable so none attacks another.Medium6GraphGreedy+2No attempts yet1s128 MBJudgeable
Justice for AllGiven a k x k 0/1 trust matrix (k up to 20), count the number of perfect matchings between knights and horses, i.e. the permanent of the matrix.Medium6Dynamic programmingBit manipulation+1No attempts yet1s128 MBJudgeable
Key TaskFind the shortest path from a start cell to any exit in a grid maze where doors require previously collected matching keys.Medium6BFSBit manipulation+1No attempts yet1s128 MBJudgeable
Hang or Not to HangGiven a tiny assembly program with 32 boolean registers, arbitrary initial state, and nondeterministic RANDOM instructions, find the minimum number of cycles over all possible executions until STOP, or report HANGS.Medium6BFSBit manipulation+2No attempts yet1s512 MBJudgeable
Set EquationsParse a set-theory equation with union, intersection, difference, and symmetric difference, then determine per-element membership assignments for undefined variables that satisfy it, printing the canonical lexicographically smallest solution or reporting impossibility.Medium6SimulationImplementation+1No attempts yet2s64 MBJudgeable
ExpectationCompute the exact expected value (as a reduced fraction) of the XOR of two independent uniform random integers in [0, n-1), for up to 1000 values of n up to 1e9.Medium6Bit manipulationMath+1No attempts yet2s64 MBJudgeable
TichuGiven a 13-card Tichu hand, compute the minimum number of legal combinations (singles, pairs, triples, quads, full houses, straights) that partition the hand.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
The Computer GameGiven a diamond-shaped lattice grid with some cells blocked, count all nonempty subsets of free cells that form a single connected (4-adjacency) region.Medium6Brute forceGraph+2No attempts yet1s128 MBJudgeable
Binary PolynomialsGiven a Boolean function's polynomial coefficients over n variables, count vectors with exactly k ones that make the function evaluate to 1.Medium6Bit manipulationCombinatorics+2No attempts yet1s128 MBJudgeable
Finding the Weakness in the EncryptionGiven nine XOR-encrypted 32-bit values where the last is a checksum of the others, recover the XOR key bit by bit using carry propagation.Medium6Bit manipulationMath+1No attempts yet1s128 MBJudgeable
God of WindDecide if a 2x2 cloud can move on a 4x4 grid, one to two cells per step in a straight line, so every village avoids rain-free streaks over 6 days while never raining on a marked village on its festival day.Medium6BFSBit manipulation+1No attempts yet1s128 MBJudgeable
Hongjun's Royal GuardCount permutations of N distinct elements where every interior element is a local extremum (both neighbors larger or both smaller); N is at most 20.Medium6Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
The AgencyFind the minimum landing-tax cost to travel from one N-bit planet to another, where flights flip exactly one bit.Medium6GraphShortest path+2No attempts yet1s128 MBJudgeable
Pizza Delivery Minimum TimeGiven directed travel times between a pizzeria and up to 10 stops, find the shortest round trip from the pizzeria visiting every stop.Medium6Shortest pathDynamic programming+2No attempts yet1s128 MBJudgeable
The Game of EfilCount how many predecessor configurations on a torus could evolve into a given Game of Life state.Medium6Bit manipulationBrute force+2No attempts yet1s128 MBJudgeable
MosaicCount the tilings of an N x M grid with 2 x 2 squares and L-trominoes, modulo 1,000,000.Medium6Dynamic programmingBit manipulationNo attempts yet1s128 MBJudgeable
Powers of ThreeGiven n, list the elements of the n-th smallest subset of powers of 3 when subsets are ordered by their sums.Medium6MathCombinatorics+2No attempts yet1s128 MBJudgeable
No TippingCount the orders in which n packages can be removed from a lever on two fulcrums so the board never tips.Medium6BacktrackingBit manipulation+1No attempts yet1s128 MBJudgeable
PebblesPlace pebbles on an N by N board so no two touch even diagonally, maximizing the sum of covered cell values.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Time to GraduateGiven up to 12 courses with prerequisites, fall or spring offerings, and a per-semester course cap, find the minimum number of semesters to finish all courses.Medium6GraphDynamic programming+2No attempts yet1s128 MBJudgeable
Double VisionGiven n pixel grids of symbols, decide for each whether one or two pixels uniquely identify it, and mark the chosen pixels.Medium6Brute forceImplementation+2No attempts yet1s128 MBJudgeable
Not One Bit MoreCount integers in [LO, HI] whose repeated popcount chain reaches 1 at exactly step X, with LO up to 1e18 and X up to 10.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
WordStackOrder the given words and pad each with leading spaces to maximize the total number of columns where a letter matches the letter directly above it.Medium6Dynamic programmingBit manipulationNo attempts yet1s128 MBJudgeable
Complaint SortGiven a sequence of n values, count the strictly decreasing subsequence triples (i < j < k with a_i > a_j > a_k).Medium6ArrayCombinatorics+2No attempts yet1s256 MBJudgeable
Chemical AnalysisGiven up to 12 element bitmasks and a target bitmask, find the fewest elements whose bitwise OR equals the target, or report that none does.Medium6Bit manipulationBrute force+2No attempts yet1s128 MBJudgeable
Zebra HerdAssign each of z zebras one of two colors at each of t times, minimizing same-color distance costs, opposite-color bonuses, and color-change penalties.Medium6Dynamic programmingBit manipulation+2No attempts yet7s128 MBJudgeable
Arsenic and Old LaceGiven up to 20 base products as bitmasks over s substances, find the fewest products whose union exactly equals the poison mask, or report impossible.Medium6Bit manipulationBrute force+2No attempts yet1s128 MBJudgeable
Essay WritingGiven a sample text, two keywords, and a target length w, decide whether a word sequence of exactly w words exists where every adjacent pair appears in the sample and both keywords occur at least once.Medium6GraphBFS+2No attempts yet1s128 MBJudgeable
Warehouse Location PlanningChoose any nonempty subset of up to 20 candidate warehouses and assign each of up to 100 stores to a chosen one so that building plus Euclidean shipping cost is minimum.Medium6Brute forceBit manipulation+2No attempts yet2s128 MBJudgeable
Course LoadPick a set of classes with pairwise disjoint meeting slots and total workload at most C, maximizing total utility.Medium6Dynamic programmingBit manipulation+1No attempts yet1s128 MBJudgeable
Party LampsGiven N lamps all starting ON and a press count C, list every distinct final lamp configuration reachable with exactly C presses of four fixed toggle buttons and consistent with up to two ON and two OFF constraints.Medium6Brute forceBit manipulation+2No attempts yet1s128 MBJudgeable
SenbeiGiven a binary R x C grid with R at most 10, choose one subset of rows and one subset of columns to flip so the number of 1s is maximized.Medium6Brute forceGreedy+2No attempts yet1s128 MBJudgeable
Long Night of MuseumsWith at most 20 museums, viewing times, and travel times, find the largest number of distinct museums a 420-minute tour can include.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Cows in a SkyscraperGiven up to 18 cow weights and an elevator capacity, find the minimum number of trips that carry every cow without exceeding the capacity.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
The Trough GameGiven N troughs and M queries that each count filled troughs within a listed subset, find the filled set or report impossible or non-unique.Medium6Brute forceBit manipulation+1No attempts yet1s128 MBJudgeable
Mixed Up CowsCount permutations of N serial numbers (N at most 16) where every adjacent pair differs by more than K.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
Round NumbersCount integers in [Start, Finish] whose binary form has at least as many zeroes as ones.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
DividingGiven counts of marbles worth 1 to 6, decide whether the collection can be split into two sets of equal total value.Medium6Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Pizza Anyone?Each friend accepts a pizza if it meets at least one of their requests; find the fewest-topping pizza, breaking ties by smallest topping string, or report that none exists.Medium6Bit manipulationBrute force+2No attempts yet1s128 MBJudgeable
Fiber NetworkFor each query in a directed multigraph where every edge is labeled with a set of companies, list the companies that have a path from A to B using only their own edges.Medium6GraphBFS+2No attempts yet1s128 MBJudgeable
Mondrian's DreamCount the number of ways to tile an h by w rectangle (up to 11 by 11) with 2 by 1 dominoes, for several test cases.Medium6Dynamic programmingBit manipulation+2No attempts yet1s256 MBJudgeable
Collecting BeepersGiven Karel's start and up to 8 beepers on a grid, find the shortest Manhattan-distance round trip visiting every beeper.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
CandySplit multiset candies with counts and calorie values into two groups so the two calorie totals differ as little as possible.Medium6Dynamic programmingBit manipulation+2No attempts yet1s128 MBJudgeable
BlindfoldGiven a grid with obstacles and a fixed sequence of forward/turn moves, mark every walkable square that can be a final position for some unknown start and heading.Medium6SimulationBit manipulation+2No attempts yet1s128 MBJudgeable
Word GroupingSplit N words into the fewest groups so that each group shares at least one common letter, with at most 15 distinct letters.Medium6Bit manipulationDynamic programming+1No attempts yet1s1024 MBJudgeable
Flip GameFind the minimum number of flips to turn all 16 pieces white or all black, where each move flips a chosen cell and its orthogonal neighbors.Medium6Brute forceBit manipulation+2No attempts yet1s128 MBJudgeable
Pimp My RideGiven n jobs with base prices and pairwise surcharges paid when a later job follows an earlier one, find the cheapest order to finish all jobs.Medium6Dynamic programmingBit manipulationNo attempts yet1s128 MBJudgeable
Colored StonesRemove the fewest stones so that in the remaining row every color appears in one contiguous block.Medium6Dynamic programmingBit manipulationNo attempts yet1s128 MBJudgeable
Shortest Computer Reboot TourGiven up to 12 points, find the shortest closed tour that visits every point exactly once and returns to the start.Medium6Dynamic programmingBit manipulation+1No attempts yet0.1s128 MBJudgeable