시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 (추가 시간 없음) | 1024 MB (추가 메모리 없음) | 109 | 42 | 33 | 54.098% |
You are given an array $a$ of length $N$. Each element of $a$ is either -1 or an integer between $1$ and $N$. Each number between $1$ and $N$ appears at most once in $a$. Also, no two adjacent elements of $a$ have a difference of $1$.
You are to find the lexicographically smallest permutation $p$ of $\{1,2,\cdots ,N\}$ satisfying the following.
The first line contains one integer, $N$.
The second line contains space-separated $N$ integers — elements of the array $a$.
If there is no permutation $p$ satisfying the condition, then output a single integer $-1$.
Otherwise, output the lexicographically smallest permutation $p$.
10 3 -1 10 -1 8 -1 -1 -1 -1 -1
3 1 10 2 8 4 6 9 5 7
2 -1 -1
-1