Under construction

Still being built. Things may change

Secret Permutation

Time limit1.5sMemory limit1024 MB

Summary
Recover a hidden permutation P of 1 to N using queries that return the sum of absolute differences of P along a chosen index order V.
Level

Medium7 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

The Scientific Committee has hidden a permutation PP of all integers from 1 to NN (3 ≤ NN ≤ 256). You need to find it. PP is fixed, and the grader is not adaptive.

You may ask queries with another permutation VV of the integers from 1 to NN as the parameter. The query query(V)\text{query}(V) returns

query(V)=∑i=1N−1∣P[Vi]−P[Vi+1]∣\text{query}(V) = \sum_{i=1}^{N-1} |P[V_i] - P[V_{i+1}]|

After a number of queries, find PP, or any other permutation P′P' that cannot be distinguished from PP. Two permutations are indistinguishable if every possible query returns the same answer for both.

Examples1

  1. Example 1

    Input
    3
    
    Expected output
    ? 1 2 3
    ! 1 2 3