HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Array and Matrices > problem:


50384 - Permutations revisited

Guest
• Review clarifications (1)

Volume problems

• 50371 - Modified Karnaugh-Map
• 50382 - Parkside's Other Triangle
• 50413 - Valid Permutations
• 50406 - Draw Pattern 178
• 50861 - The largest Student Group
• 50418 - Student averages
• 50420 - Teachers Sightseeing
• 50384 - Permutations revisited
• 50841 - My grand-grand-grandfather
• 50395 - Page "Like" Averages
• 50407 - Missing Number
• 50516 - Lines
• 50446 - Snake
• 50875 - Take m-out
• 50509 - Reading Book
• 50529 - Row to Table

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Prepared by Ibrahim Mesecan.

Permutations revisited

 

In previous contest you were asked to find the k-th permutation of a series in lexicographical order, for a given k. Now, we are asking for the inverse: you are given a permuted series, and you need to output its order. The inputs admit that k can have at most 15 digits.

 

Sample Input 1                                  Sample Output 1

4                                                          8

2 1 4 3

 

Sample Input 2                                  Sample Output 2

5                                                          110

5 3 1 4 2

 

Explanation for sample output 1:

1 2 3 4  // First permutation

1 2 4 3

1 3 2 4

1 3 4 2

1 4 2 3

1 4 3 2

2 1 3 4

2 1 4 3   // 8th permutation

 

Äëÿ îòïðàâêè ðåøåíèé íåîáõîäèìî âûïîëíèòü âõîä.

www.contester.ru