CF1032C.Playing Piano
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Little Paul wants to learn how to play piano. He already has a melody he wants to start with. For simplicity he represented this melody as a sequence a1,a2,…,an of key numbers: the more a number is, the closer it is to the right end of the piano keyboard.
Paul is very clever and knows that the essential thing is to properly assign fingers to notes he's going to play. If he chooses an inconvenient fingering, he will then waste a lot of time trying to learn how to play the melody by these fingers and he will probably not succeed.
Let's denote the fingers of hand by numbers from 1 to 5. We call a fingering any sequence b1,…,bn of fingers numbers. A fingering is convenient if for all 1≤i≤n−1 the following holds:
- if ai<ai+1 then bi<bi+1, because otherwise Paul needs to take his hand off the keyboard to play the (i+1)-st note;
- if ai>ai+1 then bi>bi+1, because of the same;
- if ai=ai+1 then bi=bi+1, because using the same finger twice in a row is dumb. Please note that there is =, not = between bi and bi+1.
Please provide any convenient fingering or find out that there is none.
小保罗想学习弹钢琴。他已经有一段想要练习的旋律。为了简化问题,他将这段旋律表示为一个键位编号序列 a1,a2,…,an:数值越大,对应键位越靠近钢琴键盘的右端。
保罗非常聪明,他知道最关键的是为要演奏的音符合理分配手指。如果他选择了不合适的指法,就会浪费大量时间去练习用这些手指演奏该旋律,而且很可能最终失败。
我们用数字 1 到 5 表示一只手的五根手指。我们将任意一个手指编号序列 b1,…,bn 称为一种指法。若对所有 1≤i≤n−1 均满足以下条件,则称该指法是合适的:
- 若 ai<ai+1,则必须有 bi<bi+1,否则保罗需将手抬离键盘才能弹奏第 (i+1) 个音符;
- 若 ai>ai+1,则必须有 bi>bi+1,原因同上;
- 若 ai=ai+1,则必须有 bi=bi+1,因为连续两次使用同一根手指是不合理的。请注意此处是 =,而非 =。
请给出任意一种合适的指法,或判定不存在这样的指法。
输入格式
The first line contains a single integer n (1≤n≤105) denoting the number of notes.
The second line contains n integers a1,a2,…,an (1≤ai≤2⋅105) denoting the positions of notes on the keyboard.
第一行包含一个整数 n(1≤n≤105),表示音符的数量。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤2⋅105),表示键盘上各音符的位置。
输出格式
If there is no convenient fingering, print −1. Otherwise, print n numbers b1,b2,…,bn, each from 1 to 5, denoting a convenient fingering, separated by spaces.
如果没有合适的指法,则输出 −1。否则,输出 n 个数字 b1,b2,…,bn(每个数字均在 1 到 5 之间),表示一种合适的指法,数字之间用空格分隔。
输入输出样例
输入#1
5 1 1 4 2 2
输出#1
1 4 5 4 5
输入#2
7 1 5 7 8 10 3 1
输出#2
1 2 3 4 5 4 3
输入#3
19 3 3 7 9 8 8 8 8 7 7 7 7 5 3 3 3 3 8 8
输出#3
1 3 4 5 4 5 4 5 4 5 4 5 4 3 5 4 3 5 4
说明/提示
The third sample test is kinda "Non stop" song by Reflex.
第三个样例测试是 Reflex 的歌曲《Non stop》。
输入解题思路,AI测评打分。不知道怎么写?