Phase Synchronization (phaserepair)

145 teams scored 7095 points on this task, for a maximum score of 100, an average score of 49 and a median score of 25.

Highlights

  1. Banfi, Vimercate is the institute with the most points (335).
  2. Lombardia is the region with the most points (1790).

Statement

You oversee N Internet-of-Things (IoT) devices arranged on a ring of M residues. The devices are numbered from 0 to N - 1. Each device displays a phase represented by an integer between 0 and M - 1 (inclusive). The initial phase of device i is A_i. Your goal is to make all devices display the same phase. To achieve this, you may repeatedly broadcast an instruction of the form "bump r". This instruction causes every device whose current phase is exactly r to shift to phase (r + 1) \bmod M. Find a sequence of instructions with the minimum possible length that makes every device display the same phase.