← CSES Better

Interleavings and Blocks

ZCO · 2020 · Zonal Computing Olympiad · ZCO20002

Open official problem ↗
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

dynamic-programming · arrays · interleavings

The organizer’s problem statement is available at the official source link.

interleaving blocks

A block starts whenever the interleaved value changes

An interleaving chooses the next unused item from A or B; adjacent equal values merge into one block.

take A_i or B_jappend next valuenew block iff value changes
  1. 1

    Track consumed prefixes

    Represent a partial merge by positions consumed from A and B plus the last emitted value.
  2. 2

    Extend or start a block

    Each next choice either extends the current block or starts another.
  3. 3

    Count exact K

    Count paths to the end with exactly K blocks.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 chars

Run output

Run your code to see output.