CF370E.Summer Reading
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
At school Vasya got an impressive list of summer reading books. Unlike other modern schoolchildren, Vasya loves reading, so he read some book each day of the summer.
As Vasya was reading books, he was making notes in the Reader's Diary. Each day he wrote the orderal number of the book he was reading. The books in the list are numbered starting from 1 and Vasya was reading them in the order they go in the list. Vasya never reads a new book until he finishes reading the previous one. Unfortunately, Vasya wasn't accurate and some days he forgot to note the number of the book and the notes for those days remained empty.
As Vasya knows that the literature teacher will want to check the Reader's Diary, so he needs to restore the lost records. Help him do it and fill all the blanks. Vasya is sure that he spends at least two and at most five days for each book. Vasya finished reading all the books he had started. Assume that the reading list contained many books. So many, in fact, that it is impossible to read all of them in a summer. If there are multiple valid ways to restore the diary records, Vasya prefers the one that shows the maximum number of read books.
输入格式
The first line contains integer n — the number of summer days ( 2<=n<=2⋅105 ). The second line contains n integers a1,a2,... an — the records in the diary in the order they were written ( 0<=ai<=105 ). If Vasya forgot to write the number of the book on the i -th day, then ai equals 0.
输出格式
If it is impossible to correctly fill the blanks in the diary (the diary may contain mistakes initially), print "-1".
Otherwise, print in the first line the maximum number of books Vasya could have read in the summer if we stick to the diary. In the second line print n integers — the diary with correctly inserted records. If there are multiple optimal solutions, you can print any of them.
输入输出样例
输入#1
7 0 1 0 0 0 3 0
输出#1
3 1 1 2 2 3 3 3
输入#2
8 0 0 0 0 0 0 0 0
输出#2
4 1 1 2 2 3 3 4 4
输入#3
4 0 0 1 0
输出#3
1 1 1 1 1
输入#4
4 0 0 0 3
输出#4
-1