CF370E.Summer Reading
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
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.
在学校,瓦夏收到了一份令人印象深刻的暑期阅读书单。与其他现代中小学生不同,瓦夏热爱阅读,因此整个暑假期间他每天都读一本书。
瓦夏在读书时,会在《读者日记》中做记录。每天他都会写下当天所读书籍在书单中的序号。书单中的书籍从 1 开始编号,瓦夏严格按照书单顺序阅读;他总是在读完当前这本书后,才开始阅读下一本。不幸的是,瓦夏记录得不够准确,有些天他忘记写下所读书籍的编号,导致那些天的记录为空。
由于瓦夏知道语文老师会检查《读者日记》,所以他需要恢复这些丢失的记录。请你帮他完成这项工作,填满所有空白处。瓦夏确信:他阅读每本书所花的时间至少为两天,至多为五天;而且,他一旦开始读某本书,就一定会将其读完。假设书单中包含大量书籍——数量之多,以至于整个暑假根本无法全部读完。如果存在多种合法的方式恢复日记记录,则瓦夏倾向于选择其中能使已读书籍总数最大化的那种方案。
输入格式
The first line contains integer n — the number of summer days (2 ≤ n ≤ 2·105). The second line contains n integers _a_1, _a_2, ... a__n — the records in the diary in the order they were written (0 ≤ a__i ≤ 105). If Vasya forgot to write the number of the book on the i-th day, then a__i equals 0.
第一行包含一个整数 n —— 夏日的天数(2≤n≤2⋅105)。第二行包含 n 个整数 a1,a2,…,an —— 日记中按书写顺序记录的数值(0≤ai≤105)。若瓦夏在第 i 天忘记写下书的编号,则 ai=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。
否则,在第一行输出在遵循日记记录的前提下,瓦夏整个暑假最多可能阅读的书籍数量;在第二行输出 n 个整数——即填入正确记录后的日记。若存在多个最优解,输出任意一个即可。
输入输出样例
输入#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
输入解题思路,AI测评打分。不知道怎么写?