Glitch · Medium CodeFree
Shoulder to Shoulder
The penguins want a group photo: k of them must stand shoulder to shoulder in the frame. Each move slides one penguin one cell, and nobody overtakes anybody. What is the fewest moves?
Find the fewest moves, which penguins to use and where their block starts.
The moves must be the fewest possible, and your group and block must need exactly that many.
N k, the cells of the ice shelf and the penguins wanted in the photo.N characters: P a penguin, . empty ice.moves j s. j: the first penguin of the group, counted from the left from 1. s: the cell where the block starts, from 1.N ≤ 200 000; 1 ≤ k ≤ the number of penguins16 4 P.P....PP..P...P
6 2 7
Sign in to play. It is free.
Sign in