Facebook
From KRH, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 112
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5. using PI = pair<int,int>;
  6.  
  7.  
  8. int main() {
  9.     // #ifndef ONLINE_JUDGE
  10.     // freopen("input.txt", "r", stdin);
  11.     // #endif
  12.    
  13.     ios_base::sync_with_stdio(false);
  14.     cin.tie(0);
  15.  
  16.     int t;
  17.     //cin>>t;
  18.     t = 1;
  19.     while(t--) {
  20.         int n, a, b;
  21.         cin>>n>>a>>b;
  22.  
  23.         vector<int> dancers(n);
  24.         for(auto &v: dancers) {
  25.             cin>>v;
  26.         }
  27.  
  28.         int invalid = 0, ret = 0;
  29.         for(int i = 0; i < n / 2; i++) {
  30.             int left = dancers[i], right = dancers[n-1-i];
  31.            
  32.             if (left == right) {
  33.                 if(left == 2) ret += 2*min(a, b);
  34.                 continue;
  35.             }
  36.  
  37.             if(left < 2 && right < 2) {
  38.                 invalid = 1;
  39.                 break;
  40.             }
  41.  
  42.             if(left == 2) {
  43.                 if(right == 0) ret += a;
  44.                 else ret += b;
  45.                 continue;
  46.             }
  47.  
  48.             if(right == 2) {
  49.                 if(left == 0) ret += a;
  50.                 else ret += b;
  51.                 continue;
  52.             }
  53.         }
  54.  
  55.         if (n%2 == 1 && dancers[n/2] == 2) ret += min(a,b);
  56.  
  57.         if (invalid) cout<<-1<<endl;
  58.         else cout<<ret<<endl;
  59.  
  60.  
  61.     }
  62.  
  63.     return 0;
  64. }