[BOJ 8120] Coding of Permutations
View as PDF
Submit solution
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text
Points:
3
Time limit:
1.0s
Memory limit:
128M
Problem types
Allowed languages
Every permutation A = (a1, ..., an) of numbers 1, ..., n can be coded by a sequence B = (b1, ..., bn) in which bi equals the number of all aj such that (j < i & aj > ai), for i = 1, ..., n.
The sequence B = (0, 0, 1, 0, 2, 0, 4) is the code of the permutation A = (1, 5, 2, 6, 4, 7, 3).
Write a program that:
- reads from the standard input the length n and successive elements of the sequence B,
- examines whether it is a code of some permutation of numbers 1, ..., n,
- if so, it finds that permutation and writes it in the standard output,
- otherwise it writes in the standard output one word
NIE("no").
입력 형식
- In the first line of the standard input there is a positive integer n ≤ 30,000. It is the number of elements of the sequence B.
- In each of the following n lines there is one nonnegative integer not greater than 30,000. It is the successive element of the sequence B.
출력 형식
The standard output should contain:
- in each of n consecutive lines - one element of the permutation A, whose code is the sequence B written in the standard input,
- one word
NIE, if the sequence B is not a code of any permutation.
예제 입력 1
7
0
0
1
0
2
0
4
예제 출력 1
1
5
2
6
4
7
3
예제 입력 2
4
0
2
0
0
예제 출력 2
NIE
Comments