CF1040A.Palindrome Dance
入门
通过率:0%
时间限制:1.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A group of n dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they've studied their dancing moves and can't change positions. For some of them, a white dancing suit is already bought, for some of them — a black one, and for the rest the suit will be bought in the future.
On the day when the suits were to be bought, the director was told that the participants of the olympiad will be happy if the colors of the suits on the scene will form a palindrome. A palindrome is a sequence that is the same when read from left to right and when read from right to left. The director liked the idea, and she wants to buy suits so that the color of the leftmost dancer's suit is the same as the color of the rightmost dancer's suit, the 2nd left is the same as 2nd right, and so on.
The director knows how many burls it costs to buy a white suit, and how many burls to buy a black suit. You need to find out whether it is possible to buy suits to form a palindrome, and if it's possible, what's the minimal cost of doing so. Remember that dancers can not change positions, and due to bureaucratic reasons it is not allowed to buy new suits for the dancers who already have suits, even if it reduces the overall spending.
有 n 名舞者正在为闭幕式排练一场演出。这些舞者排成一列,且已确定各自的位置,无法更改。其中部分舞者已购置白色演出服,部分已购置黑色演出服,其余舞者的演出服将在未来购置。
在原定购置演出服的当天,导演被告知:若舞台上的演出服颜色序列构成回文,则奥林匹克竞赛的参与者将感到高兴。所谓回文,是指从左向右读与从右向左读完全相同的序列。导演十分赞同这一想法,她希望购置演出服,使得最左侧舞者的服装颜色与最右侧舞者的服装颜色相同,左起第二位与右起第二位的颜色相同,依此类推。
导演已知购置一件白色演出服需花费若干“布尔”(burl),购置一件黑色演出服也需花费若干“布尔”。你需要判断:是否可能购置演出服以形成回文;若可能,求出实现该目标的最小总花费。注意:舞者的位置不可更改;并且出于官僚主义原因,不允许为已经拥有演出服的舞者重新购置新演出服(即使这会降低总支出)。
输入格式
The first line contains three integers n, a, and b (1≤n≤20, 1≤a,b≤100) — the number of dancers, the cost of a white suit, and the cost of a black suit.
The next line contains n numbers ci, i-th of which denotes the color of the suit of the i-th dancer. Number 0 denotes the white color, 1 — the black color, and 2 denotes that a suit for this dancer is still to be bought.
第一行包含三个整数 n、a 和 b(1≤n≤20,1≤a,b≤100)—— 分别表示舞者的数量、白色服装的单价以及黑色服装的单价。
下一行包含 n 个数字 ci,其中第 i 个数表示第 i 位舞者所穿服装的颜色。数字 0 表示白色,1 表示黑色,2 表示该舞者的服装尚未购买。
输出格式
If it is not possible to form a palindrome without swapping dancers and buying new suits for those who have one, then output -1. Otherwise, output the minimal price to get the desired visual effect.
如果在不交换舞者且不为已有服装的舞者购买新服装的情况下无法构成回文,则输出 −1。否则,输出实现所需视觉效果的最低价格。
输入输出样例
输入#1
5 100 1 0 1 2 1 2
输出#1
101
输入#2
3 10 12 1 2 0
输出#2
-1
输入#3
3 12 1 0 1 0
输出#3
0
说明/提示
In the first sample, the cheapest way to obtain palindromic colors is to buy a black suit for the third from left dancer and a white suit for the rightmost dancer.
In the second sample, the leftmost dancer's suit already differs from the rightmost dancer's suit so there is no way to obtain the desired coloring.
In the third sample, all suits are already bought and their colors form a palindrome.
在第一个样例中,获得回文颜色的最便宜方法是:为从左数第三个舞者购买黑色服装,为最右侧舞者购买白色服装。
在第二个样例中,最左侧舞者的服装颜色已经与最右侧舞者的服装颜色不同,因此无法得到所期望的颜色排列。
在第三个样例中,所有服装都已购买完毕,且其颜色已构成回文。
输入解题思路,AI测评打分。不知道怎么写?