← CSES Better
Open official problem ↗Rearrange Students into an Alternating Line
ZIO · 2022 · Zonal Informatics Olympiad · P1
Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude Desktopstrings · greedy · rearrangement
The organizer’s problem statement is available at the official source link.
alternating sequence
Compare both alternating targets
Minimize moved positions while maximizing adjacent unlike genders.
B G B G ...G B G B ...min moves = N ... matches
- 1
Build both targets
Build both alternating patterns for the same length. - 2
Count fixed positions
Count original positions that already match each pattern. - 3
Minimize moved students
Subtract fixed positions from N and choose the lower move count.
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.