eeee
2025-01-08 20:31:52
发布于:湖南
26阅读
0回复
0点赞
试改本帖作者的运气代码以此AC所有测试点(
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
#include<omp.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define QWQ return 0;
#define ll long long
using namespace std;
ll f(const vector<ll>&p,const ll c,const vector<bool>&r){
ll n=p.size();
vector<ll>g=p;
for(ll i(0);i<n;++i){
if(r[i]){
ll l=(i-1+n)%n;ll m=(i+1)%n;
g[l]-=c;g[m]-=c;
}
}
ll t=0;
for(ll i(0);i<n;++i){
if(r[i]){t+=g[i];}
}
return t;
}
ll m(const vector<ll>&p,const ll c){
ll n=p.size();ll ma=LLONG_MIN;
#pragma omp parallel for reduction(max:ma)
for(ll i(0);i<(1<<n);++i){
vector<bool>r(n,false);
for(ll j(0);j<n;++j){
if(i&(1<<j)){r[j]=true;}
}
ll cur=f(p,c,r);
#pragma omp critical
{
ma=max(ma,cur);
}
}
return ma;
}
signed main(void){
IOS
ll n,c;
cin>>n>>c;
vector<ll>p(n);
for(ll i(0);i<n;++i){cin>>p[i];}
if(n==1){cout<<0;}else{cout<<m(p,c);}
QWQ
}
这里空空如也
有帮助,赞一个