N = int(input()) Java /* package codechef // don't place package name! */
Adhere to the format shown in the sample output.Īmbiguous Solution – Ambiguous Permutations | CodeChef Solution C++ #include Output Specificationįor each test case output whether the permutation is ambiguous or not. The last test case is followed by a zero. You can assume that every integer between 1 and n appears exactly once in the permutation. There is exactly one space character between consecutive integers. Then a permutation of the integers 1 to n follows in the next line. The first line of each test case contains an integer n ( 1 ≤ n ≤ 100000). To get rid of such annoying sample test cases, you have to write a program which detects if a given permutation is ambiguous or not. The permutation 1, 4, 3, 2 for example is ambiguous, because its inverse permutation is the same. The inverse permutation for the sequence above is 5, 1, 2, 3, 4.Īn ambiguous permutation is a permutation which cannot be distinguished from its inverse permutation. Let us call this second possibility an inverse permutation. However, there is another possibility of representing a permutation: You create a list of numbers where the i-th number is the position of the integer i in the permutation. With n = 5, a permutation might look like 2, 3, 4, 5, 1. So the natural way to represent a permutation is to list the integers in this order. For an example, let us look at permutations.Ī permutation of the integers 1 to n is an ordering of these integers. Some programming contest problems are really tricky: not only do they require a different output format from what you might have expected, but also the sample output does not show the difference.
Solution – Ambiguous Permutations | CodeChef Solution.