CF65B.Harry Potter and the History of Magic

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has a soporific effect even on the quill. That's why the quill often makes mistakes, especially in dates.

So, at the end of the semester Professor Binns decided to collect the students' parchments with notes and check them. Ron Weasley is in a panic: Harry's notes may contain errors, but at least he has some notes, whereas Ron does not have any. Ronald also has been sleeping during the lectures and his quill had been eaten by his rat Scabbers. Hermione Granger refused to give Ron her notes, because, in her opinion, everyone should learn on their own. Therefore, Ron has no choice but to copy Harry's notes.

Due to the quill's errors Harry's dates are absolutely confused: the years of goblin rebellions and other important events for the wizarding world do not follow in order, and sometimes even dates from the future occur. Now Ron wants to change some of the digits while he copies the notes so that the dates were in the chronological (i.e. non-decreasing) order and so that the notes did not have any dates strictly later than 2011, or strictly before than 1000. To make the resulting sequence as close as possible to the one dictated by Professor Binns, Ron will change no more than one digit in each date into other digit. Help him do it.

《魔法史》或许是霍格沃茨魔法与巫术学校中最枯燥乏味的一门课程。哈利·波特在历史课上通常都昏昏欲睡,而他的魔法羽毛笔则自动为他记录课堂讲义。魔法史教授宾斯先生讲课时语调单调乏味、毫无起伏,甚至对羽毛笔都产生了催眠效果。因此,这支羽毛笔常常出错,尤其是在书写日期时。

于是,学期末,宾斯教授决定收齐学生们的羊皮纸笔记并加以检查。罗恩·韦斯莱顿时慌了神:哈利的笔记中可能含有错误,但至少他还有一些笔记;而罗恩却一片空白——他在课堂上同样酣然入梦,且他的羽毛笔早已被他的老鼠斑斑啃掉了。赫敏·格兰杰拒绝把她的笔记借给罗恩,因为她认为每个人都应当独立学习。因此,罗恩别无选择,只能抄写哈利的笔记。

由于羽毛笔的错误,哈利所记的日期完全混乱:妖精叛乱及其他魔法世界重要事件发生的年份并未按时间顺序排列,甚至有时还出现了来自未来的日期。现在,罗恩希望在抄写笔记时修改其中部分数字,使得所有日期按时间顺序(即非递减)排列,并且所有日期均不严格晚于 2011 年,也不严格早于 1000 年。为了使最终得到的日期序列尽可能接近宾斯教授实际所讲授的内容,罗恩对每个日期最多只允许修改一位数字(即将该位上的一个数字改为另一个数字)。请帮助他完成这一任务。

输入格式

The first input line contains an integer n (1 ≤ n ≤ 1000). It represents the number of dates in Harry's notes. Next n lines contain the actual dates _y_1, _y_2, ..., y__n, each line contains a date. Each date is a four-digit integer (1000 ≤ y__i ≤ 9999).

第一行输入包含一个整数 nn(1≤n≤10001 \leq n \leq 1000),表示哈利笔记中日期的数量。接下来的 nn 行包含实际的日期 y1,y2,…,yny_1, y_2, \dots, y_n,每行一个日期。每个日期均为四位整数(1000≤yi≤99991000 \leq y_i \leq 9999)。

输出格式

Print n numbers _z_1, _z_2, ..., z__n (1000 ≤ z__i ≤ 2011). They are Ron's resulting dates. Print each number on a single line. Numbers z__i must form the non-decreasing sequence. Each number z__i should differ from the corresponding date y__i in no more than one digit. It is not allowed to change the first digit of a number into 0. If there are several possible solutions, print any of them. If there's no solution, print "No solution" (without the quotes).

输出 n 个数字 _z_₁, _z_₂, ..., z__n(1000 ≤ z__i ≤ 2011)。它们是 Ron 的最终日期。每个数字单独占一行输出。数字 z__i 必须构成一个非递减序列。每个数字 z__i 与对应日期 y__i 至多有一位数字不同。不允许将数字的首位改为 0。若存在多种可能的解,输出任意一种即可。若无解,则输出 "No solution"(不带引号)。

输入输出样例

  • 输入#1

    3
    1875
    1936
    1721

    输出#1

    1835
    1836
    1921
  • 输入#2

    4
    9999
    2000
    3000
    3011

    输出#2

    1999
    2000
    2000
    2011
  • 输入#3

    3
    1999
    5055
    2000

    输出#3

    No solution

输入解题思路,AI测评打分。不知道怎么写?

首页