首页 > 其他 > 详细

【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) A】Palindrome Dance

时间:2018-09-06 11:46:33      阅读:155      评论:0      收藏:0      [点我收藏+]

【链接】 我是链接,点我呀:)
【题意】


在这里输入题意

【题解】


i从1..n/2循环一波。
保证a[i]和a[n-i+1]就好。
如果都是2的话填上min(a,b)*2就好
其他情况跟随非2的。

【代码】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std;

const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};

const int N = 20;

int n,a,b,cost[2];
int c[N+10];

int main(){
    #ifdef LOCAL_DEFINE
        freopen("rush_in.txt", "r", stdin);
    #endif
    scanf("%d%d%d",&n,&a,&b);
    cost[0] = a,cost[1] = b;
    rep1(i,1,n) scanf("%d",&c[i]);
    int ans = 0;
    rep1(i,1,n/2){
        int l = i,r = n-i+1;
        if (c[l]==2 && c[r]==2){
            ans+=min(a,b)*2;
        }else{
            if (c[l]==2){
                ans+=cost[c[r]];
            }else if (c[r]==2){
                ans+=cost[c[l]];
            }else if (c[l]!=c[r]){
                cout<<-1<<endl;
                return 0;
            }
        }
    }
    if (n&1){
        if (c[n/2+1]==2){
            ans+=min(a,b);
        }
    }
    printf("%d\n",ans);
    return 0;
}

【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) A】Palindrome Dance

原文:https://www.cnblogs.com/AWCXV/p/9597251.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!