forked from debsourav33/CodeForces-Problem-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1040A- Palindrome Dance.cpp
60 lines (47 loc) · 989 Bytes
/
1040A- Palindrome Dance.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<bits/stdc++.h>
using namespace std;
//{
#define fr(i,a,n) for(int i=a;i<n;i++)
#define ull unsigned long long
#define ll long long
#define pb push_back
#define MX 10000007
#define all(v) v.begin(),v.end()
//}
main(){
int n, w, b;
int a[100];
cin>>n>>w>>b;
fr(i,0,n)
cin>>a[i];
int mini, maxi;
if(w<=b){
mini= w;
maxi= b;
}
else{
mini= b;
maxi= w;
}
int st=0, endi=n-1, cost=0;
while(st<=endi){
if(a[st]==a[endi] && a[st]==2){
if(st!=endi)
cost+= 2*mini;
else
cost+= mini;
}
if(a[st]!=a[endi]){
if(a[st]!=2 && a[endi]!=2){
cout<<"-1"<<endl;
return 0;
}
if(a[st]==0|| a[endi]==0)
cost+= w;
else if(a[st]==1|| a[endi]==1)
cost+= b;
}
st++; endi--;
}
cout<<cost<<endl;
}