Official algorithmic problem description and constraints.
Bodya and Sasha found a permutation π1,β¦,ππ and an array π1,β¦,ππ. They decided to play a well-known "Permutation game".
A permutation of length π is an array consisting of π distinct integers from 1 to π in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4] is also not a permutation (π=3 but there is 4 in the array).
Both of them chose a starting position in the permutation.
The game lasts π turns. The players make moves simultaneously. On each turn, two things happen to each player:
The winner of the game is the player with the higher score after exactly π turns.
Knowing Bodya's starting position ππ΅ and Sasha's starting position ππ, determine who wins the game if both players are trying to win.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.