← CSES Better
Open official problem ↗Unrank a Lexicographic List of Integer Compositions
ZIO · 2022 · Zonal Informatics Olympiad · P4
Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude Desktopcombinatorics · compositions · lexicographic-order
The organizer’s problem statement is available at the official source link.
ordered groups
Lists are grouped by their sum
Enumerate positive-integer lists by increasing total, then lexicographically within each total.
| sum k | lexicographic composition |
|---|---|
| k | (1,...,1) |
| k | (1,...,2,...) |
| k | (k) |
- 1
Skip earlier groups
A k-list is an ordered list of positive integers summing to k. - 2
Unrank lexicographically
Count each sum-group and skip whole groups before the target position. - 3
Compute requested value
Unrank within the matching group, then compute the requested sum or product.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 charsRun output
Run your code to see output.