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 results6,373 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Interleaved Periodic StringGiven a binary string S, find the minimum total length of two binary strings whose repeated copies can be interleaved to produce S.Hard8Brute forceDynamic programming+2No attempts yet1s512 MBJudgeable
NM and K (1)Choose exactly K non-adjacent cells from an N by M grid, at most 10 by 10, to maximize the sum of their values.Hard8Dynamic programmingBit manipulation+2No attempts yet2s512 MBJudgeable
NM and K (2)Choose exactly K non-adjacent cells from an N by M grid, each with a value, to maximize the total sum.Hard8Dynamic programmingBit manipulation+2No attempts yet2s512 MBJudgeable
Bird WatchingGiven a digraph P known to contain the true edge set G plus some path-shortcut edges, list all in-neighbors a of T such that every path from a to T uses the edge (a, T).Hard8GraphDFS+2No attempts yet3s512 MBJudgeable
SealGiven a binary document grid and a binary seal stamp, decide whether the document is exactly the union of non-overlapping (and non-rotated) placements of the stamp.Hard8ImplementationSimulation+2No attempts yet2s512 MBJudgeable
VisitsGiven a tree, a visiting order, fuel prices, and tank capacities, compute the refueling cost of each trip in the order.Hard8TreePrefix sum+2No attempts yet2s512 MBJudgeable
Collecting Stamps 3On a circular lake, N stamps sit at given positions with individual collection deadlines; find the maximum number of stamps JOI-kun can collect starting from position 0.Hard8Dynamic programmingIntervals+2No attempts yet2s512 MBJudgeable
Farm of MonstersYou and a fixed greedy opponent alternate attacking monsters; you choose targets to maximize the number of monsters you personally kill.Hard8GreedySorting+2No attempts yet1s512 MBJudgeable
Face Recognition AlgorithmGiven a planar straight-line embedding of a connected graph, decide whether every face, including the outer one, is bounded by exactly three edges.Hard8GeometryGraph+2No attempts yet2s512 MBJudgeable
Euclid's AlgorithmGiven d and k, find the largest integer that divides (a+d)^k - a^k for every positive integer a.Hard8Number theoryMath+2No attempts yet1s512 MBJudgeable
Bad DoctorEach doctor prescribes a set of medicines over a day interval; ignoring one doctor, compute the total cost of distinct medicines needed per day summed over all days.Hard8Segment treeSorting+2No attempts yet3s512 MBJudgeable
ProgramGiven a sequence of assignment and conditional assignment instructions starting from X=1, delete the fewest instructions so the final value is k, for every k.Hard8GraphShortest path+2No attempts yet2s512 MBJudgeable
Game XGiven n and k, decide whether exactly k pairs of nonzero, distinct-magnitude integers can have positive sum, and if so maximize the number of pairs whose product is positive.Hard8MathGreedy+2No attempts yet1s512 MBJudgeable
Glad You CameApply m range-max updates (a_j = max(a_j, v_i)) to a zero array, where each l, r, v comes from a fixed 32-bit RNG, then output the XOR of i*a_i.Hard8Segment treeImplementation+2No attempts yet4s512 MBJudgeable
Cake DistributionChoose up to 5000 positive integer cake pieces so that for each of A, B, C guests they can be split evenly, labeling each piece with its recipient for each case.Hard8MathNumber theory+2No attempts yet1s512 MBJudgeable
Block BreakerBlocks drop in a grid when a knocked block has a dropped left/right neighbor and a dropped front/back neighbor; after each of q moves, report how many blocks fall.Hard8Union-findSimulation+2No attempts yet2s512 MBJudgeable
ChallengeConstruct a tree with at most n vertices whose recursive center-removal decomposition puts some vertex in at least floor(sqrt(n)) different pieces.Hard8TreeGreedy+2No attempts yet2s512 MBJudgeable
BaklawaGiven a huge cuboid with up to 100 poisonous unit cells, players alternate cutting off a safe cuboid half; decide who wins under optimal play.Hard8Game theoryGeometry+2No attempts yet2s512 MBJudgeable
Exciting MenusGiven N strings with a joy value per position, maximize over all substrings the product of its length, the joy at its end, and the number of strings having it as a prefix.Hard8TrieString+2No attempts yet4s512 MBJudgeable
Invited SpeakersGiven n red and n blue points in the plane with distinct x and y coordinates and no three collinear, draw n disjoint polygonal chains pairing each red point with a blue point.Hard8GeometryGreedy+2No attempts yet2s512 MBJudgeable
Help Yourself (Gold)Sum the number of connected regions in the union of segments over all 2^N subsets, modulo 1e9+7.Hard8CombinatoricsSorting+2No attempts yet2s512 MBJudgeable
O Life of My YouthGiven N pairs of happiness and fatigue with some values missing (0), find the largest K < N such that all young-day pairs can exceed all old-day pairs in happiness and stay below them in fatigue.Hard8SortingGreedy+2No attempts yet2s1024 MBJudgeable
HaircutFor each threshold j from 0 to N-1, clip every value above j down to j and count the resulting inversions.Hard8SortingPrefix sum+2No attempts yet1s512 MBJudgeable
Printer's HeadGiven a permutation of heights 1..n to print in order, find the minimum number of left-to-right or right-to-left sweeps, where each sweep prints positions in order with heights dropping by 1.Hard8GreedyDynamic programming+1No attempts yet1.5s64 MBJudgeable
PasswordsGiven n rows of m letters, permute the columns so the rows become lexicographically nondecreasing, choosing the smallest such permutation or reporting NIE.Hard8GreedySorting+2No attempts yet1.5s64 MBJudgeable
Hidden GraphFind a hidden undirected graph on n vertices, where every induced subgraph has a vertex of degree at most k, using at most 2nk+n independence queries that return an edge when the set is not independent.Hard8GraphDivide and conquer+2No attempts yet5s512 MBJudgeable
Tree HullMaintain a set of tree vertices under insertions and deletions, and after each query report the total edge weight of the minimal subtree spanning the current set.Hard8TreeDFS+2No attempts yet3s256 MBJudgeable
Bag of BagsProcess bags one by one; keep a bag unless its equality class merges two classes that were already equal, and report the decision for each.Hard8IntervalsUnion-find+2No attempts yet2s256 MBJudgeable
Exact ArithmeticSimulate a stack calculator whose values are sums of rationals and rational multiples of square roots, and print each result in a canonical exact form.Hard8ImplementationMath+2No attempts yet1s512 MBJudgeable
Oleg and Data ScienceCount positive integers X such that ((S mod Q) mod X) equals (S mod X) for every S in [L, R], or report infinity.Hard8Number theoryMath+2No attempts yet2s256 MBJudgeable
Christmas GarlandGiven a garland of n bulbs with colors, each query flips the state of every bulb of one color, and after each flip you report the number of maximal lit segments.Hard8ArrayImplementation+2No attempts yet2s256 MBJudgeable
FaintSum the absolute differences between consecutive rows of a fixed column in the lexicographically ordered list of k-subsets of {1,...,n}, modulo 1e9+7.Hard8CombinatoricsMath+2No attempts yet1s512 MBJudgeable
Biggest NumberAfter each of Q point updates to the digits on N cards, report the largest base-D number obtainable by rearranging the cards, modulo 1e9+7.Hard8Segment treeSorting+2No attempts yet0.5s256 MBJudgeable
Hotter-colderAn interactive problem: locate a hidden point in a d-dimensional integer grid using at most 100d queries that only report whether the latest Chebyshev distance got smaller or larger.Hard8Binary searchImplementation+2No attempts yet1s256 MBJudgeable
PrimesAnswer online queries that ask for the sum of shared distinct prime counts over all pairs in a range [a, b] up to 10^6.Hard8Number theoryPrefix sum+2No attempts yet8s256 MBJudgeable
SchedulingDecide whether n preemptible tasks with release times, deadlines, and processing times can be scheduled on m identical processors within their windows.Hard8GreedySorting+2No attempts yet1s256 MBJudgeable
2x+2Given n up to 10^100, choose the largest subset of {1,...,n} with no x and 2x+2 both present.Hard8MathGreedy+2No attempts yet1s512 MBJudgeable
Simple PolygonGiven a perimeter l and area s, construct a simple rectilinear polygon with exactly that perimeter and area, or report that none exists.Hard8GeometryMath+2No attempts yet1s512 MBJudgeable
GaloisGiven a permutation p, count permutations q with p(q(i)) = q(p(i)) for all i, that have an even number of inversions, modulo 1e9+7.Hard8CombinatoricsMath+2No attempts yet1s512 MBJudgeable
Addition RobotMaintain a binary string under range flips and answer queries that apply the range's A/B operations to a pair of numbers, modulo 1e9+7.Hard8Segment treeMatrix+2No attempts yet3s512 MBJudgeable
Yet Another Problem About PermutationsGiven a permutation, write it as a product of the fewest simple permutations, where each simple permutation has only cycles of length one or two, and output one optimal factorization.Hard8CombinatoricsGreedy+2No attempts yet3s256 MBJudgeable
Teenage SharkSimulate a 4x4 board where numbered fish rotate and swap, and a shark moves along its direction eating fish; find the maximum total value eaten.Hard8SimulationBacktracking+2No attempts yet1s512 MBJudgeable
Game of ChairsChoose a starting chair to minimize the expected distance to the nearest chair of a uniformly random color, and output the expectation as a reduced fraction.Hard8MathPrefix sum+2No attempts yet2s512 MBJudgeable
ADD, DIV, MAXMaintain an array under range add, range floor-divide, and range maximum queries, with N and Q up to 200000.Hard8Segment treeLinked list+2No attempts yet5s256 MBJudgeable
Piecewise LinearityDecide whether a piecewise linear function given by n+1 increasing x-coordinates can be written as a real linear combination of absolute value terms |x - a_i|.Hard8MathGeometry+1No attempts yet1s512 MBJudgeable
AftermathGiven the integer arithmetic mean a and integer harmonic mean h of the divisors of an unknown n up to 10^15, recover any valid n.Hard8Number theoryMath+2No attempts yet2s512 MBJudgeable
The Catcher in the RyeGiven a rectangle split into three vertical strips with different travel speeds, find the fastest route from the bottom-left to the top-right corner.Hard8GeometryBinary search+2No attempts yet1s512 MBJudgeable
Edge-Disjoint Spanning TreesGiven N and K, output K edge-disjoint spanning trees of the complete graph on N vertices, or -1 if impossible.Hard8GraphGreedy+2No attempts yet2s512 MBJudgeable
Hacker Cups and BallsGiven a permutation and range sort operations that go ascending or descending depending on whether l < r, find the value in the middle cup at the end.Hard8Binary searchSegment tree+2No attempts yet3s512 MBJudgeable
ImmigrationPeter moves along the x-axis while tracking an object whose velocity changes n times; find the maximum absolute angular speed of his gaze from time t0 onward.Hard8GeometryMath+2No attempts yet2s256 MBJudgeable
Array and OperationsMaintain an array under range add, range floor-square-root, and range sum queries, printing each sum.Hard8Segment treeBinary search+2No attempts yet1s512 MBJudgeable
ChampionshipsFind the largest set S of vertices such that the induced subgraph on S is connected and every vertex in S has degree at least d within S.Hard8GraphGreedy+2No attempts yet1.5s256 MBJudgeable
Taking ItemsEach item may require others first, cycles mean all-or-nothing; pick a feasible set of items maximizing total mood change.Hard8GraphDynamic programming+2No attempts yet1s1024 MBJudgeable
Internet ProblemGiven a directed graph, find all vertices lying on every walk from 1 to n, and only on walks from 1 to n, so a walk passes through each chosen vertex exactly once.Hard8GraphDFS+2No attempts yet5s512 MBJudgeable
Cash GapGiven payments with allowed day ranges, decide whether some placement and ordering of the payments forces the balance below zero.Hard8GreedySorting+2No attempts yet1s512 MBJudgeable
Jet TrainsMaintain a growing friendship graph and a growing train-route graph; each query asks how many friends of v lie in v's current connected component.Hard8Union-findGraph+2No attempts yet2s512 MBJudgeable
Flexible SegmentsFor each n up to 10000, decide whether some n consecutive positive integers admit a +1/-1 choice per element preserving the product, and output the start and signs.Hard8Number theoryMath+2No attempts yet1s512 MBJudgeable
Counting in the OrderEach soldier looks left or right and sees past people no taller than the target; count how many soldiers each one sees.Hard8StackArray+2No attempts yet1s512 MBJudgeable
Right-hand obstructionCars arrive in four queues at a crossroad; a front car passes only if the queue on its right is empty, so simulate second by second and report each car's crossing time or -1.Hard8SimulationQueue+2No attempts yet1s512 MBJudgeable
A Strange ExhibitGiven the inversion counts of every window of length k in an unknown permutation of 1..n, reconstruct any valid permutation.Hard8ImplementationGreedy+2No attempts yet2s512 MBJudgeable
Planet NineDecide whether a register can go from a to b using operations that add 9x and operations that delete leading digits, all of which are 1.Hard8MathNumber theory+2No attempts yet1s512 MBJudgeable
Similar ArraysGiven pairs of positions, decide whether there is an array with all distinct values and an array with a repeated value that agree on every listed comparison, and output both arrays.Hard8GraphDFS+2No attempts yet1s512 MBJudgeable
Equal MaximumsCount quadruples of indices i<=j<k<=l where the maximum of a[i..j] equals the maximum of a[k..l], modulo 1e9+7, for n up to 100000.Hard8ArrayStack+2No attempts yet1s512 MBJudgeable
Heavy BurgerMaintain a string of parentheses under range flips, and for each query on a substring report the minimum number of characters to insert so the substring becomes a balanced parenthesis sequence.Hard8Segment treeString matching+2No attempts yet3s1024 MBJudgeable
BusSimulate bus boarding with passengers sitting in the closest free seat or standing over an occupied one, and choose Anton's seat minimizing the total time someone stands over him.Hard8SimulationGreedy+2No attempts yet2s512 MBJudgeable
Good NumbersGiven a set S of forbidden integers, rank positive integers by how many good intervals (ranges containing only non-S values) contain each one, then print the first n.Hard9CombinatoricsMath+2No attempts yet2s128 MBJudgeable
Folded Paper PaintingSimulate K rounds of folding a W by H rectangle along a vertical line and several horizontal folds, painting one rectangle each round through all layers, and report the unpainted area at the end.Hard9GeometrySimulation+2No attempts yet2s128 MBJudgeable
Robot ArmGiven a rectilinear factory polygon and five candidate fixed points, decide for each whether an L-shaped two-segment robot arm confined to the polygon can reach every interior point.Hard9GeometryIntervals+2No attempts yet5s128 MBJudgeable
Paper FoldingGiven a colored paper strip, determine the sequence of folds that minimizes final length while respecting a color-matching constraint on folded layers.Hard9SimulationGreedy+1No attempts yet1s128 MBJudgeable
Gates of LogicParse an ASCII-art diagram of logic gates and wires with grid tracing rules (junctions, crossings, negation, ports) and compute values propagated to every named output.Hard9SimulationGraph+2No attempts yet1s128 MBJudgeable
K’ak’-u-pakal and the Maya ScriptParse a recursive grammar for Maya glyph compositions and render a minimal-size ASCII-art box layout respecting horizontal/vertical grouping and bracket-doubling size rules.Hard9RecursionString+2No attempts yet1s128 MBJudgeable
TantrixSimulate the hexagonal tile game Tantrix and count all legal placements of hand tiles given complex forced-space and controlled-side rules.Hard9SimulationGeometry+2No attempts yet1s128 MBJudgeable
Cubic ColoniesGiven a 3x3x3 arrangement of unit cubic blocks (some missing) and two surface points, compute the length of the shortest path on the colony's outer surface between them, allowing passage through zero-width edge or vertex gaps.Hard9GeometryGraph+2No attempts yet5s128 MBJudgeable
Origami Through-HoleSimulate repeated paper folds with layered segments and reflection/overlap propagation rules, then count how many layers a pin punch pierces.Hard9GeometrySimulation+1No attempts yet1s128 MBJudgeable
Crossing PrismsCompute the surface area of the solid formed by intersecting two identical prisms (one along the x-axis, one along the y-axis) whose cross section is a given simple polygon.Hard9GeometryMath+1No attempts yet1s128 MBJudgeable
Brainf**k InterpreterDecide whether a given Brainfuck program halts on its input and, if it loops, report the matching bracket pair that encloses the infinite loop.Hard9SimulationImplementation+2No attempts yet7s128 MBJudgeable
OutsourcingGiven two directed labeled graphs (factories) with start and final nodes, decide whether the two sets of label sequences realizable as paths from start to final are identical.Hard9GraphDFS+2No attempts yet1s128 MBJudgeable
Museum GuardsAssign each guard repeating daily intervals on half-hour boundaries within their availability and minute limits so the minimum number of guards on duty is maximized.Hard9Binary searchGreedy+2No attempts yet5s128 MBJudgeable
Asteroid RangersGiven n moving points, count how many times the minimum spanning tree over all future times changes, plus the initial build.Hard9Minimum spanning treeGeometry+2No attempts yet1s128 MBJudgeable
Affine MessGiven three integer start points and three integer end points, decide whether a snapped integer rotation, integer scaling, and integer translation map one set onto the other, and if so whether all such maps agree on the whole plane.Hard9GeometryMath+2No attempts yet2s128 MBJudgeable
Cubic RubeGiven two connected 5x5 height maps of unit cubes, decide whether the pieces can be rotated and translated in 3D to assemble a full 5x5x5 cube.Hard9ImplementationGeometry+2No attempts yet1s128 MBJudgeable
A to Z NumeralsConvert each positive integer up to 7e17 into its unique A to Z numeral, where letters a to r and A to R stand for powers of ten and their quintuples.Hard9GreedyMath+2No attempts yet1s128 MBJudgeable
GuardPlace g guards on segments so every valuable point is seen, minimizing the largest value-times-distance risk, or report too few guards.Hard9GeometryBinary search+2No attempts yet1s128 MBJudgeable
Triangle CutsGiven a large triangle and four small triangles as angle triples in clockwise order, decide whether three straight cuts can produce exactly those four pieces.Hard9GeometrySimulation+2No attempts yet1s128 MBJudgeable
PotholesPlace a straight rope across a rectangular lot without crossing any pothole so the total pothole area is split as evenly as possible, with tie-breaking rules.Hard9GeometrySorting+2No attempts yet1s128 MBJudgeable
Planning Rolling BlackoutsPartition an h by w grid by recursive guillotine cuts so that the heaviest set of groups left powered stays within capacity, maximizing the group count and then the reserve.Hard9Dynamic programmingPrefix sum+2No attempts yet3s512 MBJudgeable
Twirl AroundA bar inside a simple polygon rotates clockwise, pivoting on the wall whenever a new contact point appears; report the final position of one end, or the position when it jams.Hard9GeometrySimulation+2No attempts yet1s128 MBJudgeable
KindergartenSplit n students into three classes so nobody keeps their old teacher and every classmate sits in each other's top T, minimizing T.Hard9GraphBinary search+2No attempts yet1s128 MBJudgeable
The Floor BricksCover a column-height profile of a bare floor with rotated 3x3 polyomino bricks of given prices, minimizing total cost.Hard9Dynamic programmingImplementation+1No attempts yet1s128 MBJudgeable
ASCII ArtRender triangles with ASCII characters, projecting 3D vertices through a camera onto an S by S screen grid with depth-based visibility.Hard9GeometryImplementation+2No attempts yet1s128 MBJudgeable
Giant CoverGiven axis-aligned boxes on a rectangular campus, find the minimum surface area of a convex solid above the ground that covers all boxes and is anchored to the campus boundary.Hard9GeometryMath+2No attempts yet1s128 MBJudgeable
TablesCount the tilings of a polyiamond on a triangular grid by isosceles trapezoids made of three unit triangles, given the shape's boundary as a sequence of grid nodes.Hard9Dynamic programmingGeometry+2No attempts yet1s128 MBJudgeable
Farmer JohnGiven start, goal, and up to 100 disjoint line-segment fences, find the shortest path that cannot cross any fence, touching allowed, and print the length to six decimals.Hard9GeometryGraph+2No attempts yet1s128 MBJudgeable
ArcheryPlace Seungwon into one of 2N gaps so that after R tournament rounds his final target number is minimized, breaking ties by the largest starting target.Hard9MathSimulation+2No attempts yet1s128 MBJudgeable
TeleportersPlace up to M new teleporters between given endpoints so the forced eastward walk triggers as many teleports as possible.Hard9GreedySorting+2No attempts yet1s128 MBJudgeable
Success Probability of the Card-Pile GameGiven n decks of k cards each shuffled into n piles, find the probability that the follow-the-number drawing game succeeds within m restarts, printed to r decimals.Hard9ProbabilityCombinatorics+2No attempts yet1s128 MBJudgeable
Version-Controlled IDEMaintain a versioned text buffer under insert and delete operations, answering substring queries against any past version, with all commands encoded by a running counter.Hard9TreeImplementation+2No attempts yet1s128 MBJudgeable
Apparent Twin PrimesFor each query (n, t), find the smallest n-digit p such that neither p nor p+2 has a prime factor at most t.Hard9Number theoryMath+2No attempts yet1s128 MBJudgeable
Synnerg LifeformGiven rewriting rules that merge adjacent synnergs with multiplicative lifetimes, find all maximum-lifetime synnergs obtainable by fully unifying some contiguous block of each input sequence.Hard9Dynamic programmingIntervals+2No attempts yet1s128 MBJudgeable
Ballroom LightsGiven point lightbulbs and disjoint circular columns inside a rectangle, compute the total length of the wall perimeter that some lightbulb can reach with a straight, unblocked ray.Hard9GeometryMath+2No attempts yet1s128 MBJudgeable