Practice

Problems & Editor

Pick a Codeforces problem, write a solution in Python or C++, and grade it locally against the public sample tests.

Problems

CF 1096G — Lucky Tickets

Medium
fftconvolutioncountingSelected

Count length-n strings over an allowed digit set whose digit sum equals exactly half the maximum possible. Reduces to raising a digit-frequency polynomial to the n/2 power via FFT/NTT.

CF 632E — Thief in a Shop

Hard
fftnttknapsack

Determine all total values that can be reached by picking exactly k items (with repetition) from a list of n prices. Solved via polynomial exponentiation of the indicator polynomial.

CF 755G — PolandBall and Many Other Balls

Hard
nttpolynomialmatrix-exponentiation

For every k in [1..K], count the number of ways to partition n balls into k labelled groups of one or two adjacent balls. Solve with NTT-accelerated matrix exponentiation on generating-function polynomials.

Built-in editor

Editor

Loading Python…
Selected problem:CF 1096G — Lucky TicketsMedium
fftconvolutioncounting
3 sample testsOpen on Codeforces ↗

Runs in your browser via Pyodide (WebAssembly).

Input

Output

Output of “Run custom input” will appear here.

Sample tests for this problem

3 samples

Sample 1

Input

4 2
1 8

Expected output

6

Sample 2

Input

20 1
6

Expected output

1

Sample 3

Input

10 5
6 1 4 0 3

Expected output

569725

Complexity comparison

Theoretical Operation Count

Approximate arithmetic operations vs polynomial degree. Log scale on y-axis — notice how O(n²) diverges rapidly while both FFT variants stay near-flat.

Recursive FFT ≈ 4·n·log₂n ops (complex butterfly). Iterative FFT ≈ 3·n·log₂n (same passes, no recursion overhead). Naive = n² multiply-accumulates.

Live benchmark

Live Performance Benchmark

Naive O(n²) vs FFT O(n log n) polynomial multiplication, measured in your browser. Results may vary by device — larger degrees expose the gap most clearly.

0%

Running benchmark… naive multiply may be slow for large n.

External practice