秒的有点难以理解:https://blog.csdn.net/weixin_42868863/article/details/103200132

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18+;
const ll N=1E6+;
ll arr[N];
ll n;
ll cal(ll x){
ll sum=,s=;
for(ll i=;i<=n;i++){
s=(s+arr[i])%x;
sum+=min(s,x-s);
}
return sum;
}
int main(){
ios::sync_with_stdio();
cin>>n;
ll cnt=;
for(ll i=;i<=n;i++){
cin>>arr[i];
cnt+=arr[i];
}
if(cnt==){
cout<<-<<endl;
return ;
}
if(n==){
cout<<<<endl;
return ;
}
ll m=sqrt(cnt);
ll sum=INF;
for(ll i=;i<=m;i++){
if(cnt%i==){
sum=min(sum,cal(i));
while(cnt%i==) cnt/=i;
}
}
if(cnt!=) sum=min(sum,cal(cnt));
cout<<sum<<endl;
return ;
}

E2. Send Boxes to Alice (Hard Version)的更多相关文章

  1. Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version)

    Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version) N个盒子,每个盒子有a[i]块巧克力,每次操作可以将盒子中的 ...

  2. E1.Send Boxes to Alice(Easy Version)//中位数

    发送盒子给Alice(简单版本) 题意:准备n个盒子放巧克力,从1到n编号,初始的时候,第i个盒子有ai个巧克力. Bob是一个聪明的家伙,他不会送n个空盒子给Alice,换句话说,每个盒子里面都有巧 ...

  3. Codeforces1254B2 Send Boxes to Alice (Hard Version)(贪心)

    题意 n个数字的序列a,将i位置向j位置转移x个(a[i]-x,a[j]+x)的花费为\(x\times |i-j|\),最终状态可行的条件为所有a[i]均被K整除(K>1),求最小花费 做法 ...

  4. Codeforces Round #601 (Div. 2) E1 Send Boxes to Alice (Easy Version)

    #include <bits/stdc++.h> using namespace std; typedef long long ll; ; int a[N]; int n; bool pr ...

  5. E1. Send Boxes to Alice (Easy Version)

    题解: 保存每个1的位置.然后记录1的总个数cnt,如果存在一个k使得这个k是每个集合的倍数,那么为了使操作次数最小,这个k应该是cnt的质因子.(因为都是每个集合的数目1,使每个集合的数目变为2需要 ...

  6. Send Boxes to Alice

    E. Send Boxes to Alice 首先求出每一个位置的前缀和. 对答案进行复杂度为\(\sqrt{a[n]}\)的遍历,因为最后的答案不可能大于\(\sqrt{a[n]}\) for(ll ...

  7. Codeforces 1255E Send Boxes to Alice(前缀和+枚举+数论)

    我们考虑前缀和sum[i],如果将a[i+1]中的一个塞入a[i]中,则不影响sum[i+1],但是sum[i]++,如果将a[i]中的一个塞入a[i+1],则不影响sum[i+1],但是sum[i] ...

  8. Codeforces Round #601 (Div. 2)

    传送门 A. Changing Volume 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/19 22:37:33 */ #include ...

  9. Codeforces Round #584 E2. Rotate Columns (hard version)

    链接: https://codeforces.com/contest/1209/problem/E2 题意: This is a harder version of the problem. The ...

随机推荐

  1. Check If It Is a Straight Line

    2019-10-21 10:35:33 问题描述: 问题求解: public boolean checkStraightLine(int[][] coordinates) { int n = coor ...

  2. [状态压缩,折半搜索] 2019牛客暑期多校训练营(第九场)Knapsack Cryptosystem

    链接:https://ac.nowcoder.com/acm/contest/889/D来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言52428 ...

  3. 学习mybatis框架时配置xml文件解决select莫名其妙报错问题

    遇到这种情况,如果语法没有错误,那就可能是你的eclipse在耍你!!! 怎么弄呢,重新建立一个文件,把原来的代码复制到新的文件中就ok啦!不用谢我,我叫雷锋

  4. Linux下MySQL的数据库安装

    centos7 + mysql5.7 tar包解压安装 先执行wget https://dev.mysql.com//Downloads/MySQL-5.7/mysql-5.7.18-linux-gl ...

  5. 给社团同学做的R语言爬虫分享

    大家好,给大家做一个关于R语言爬虫的分享,很荣幸也有些惭愧,因为我是一个编程菜鸟,社团里有很多优秀的同学经验比我要丰富的多,这次分享是很初级的,适用于没有接触过爬虫且有一些编程基础的同学,内容主要有以 ...

  6. CUDA编程入门

    CUDA是一个并行计算框架.用于计算加速.是nvidia家的产品.广泛地应用于现在的深度学习加速. 一句话描述就是:cuda帮助我们把运算从cpu放到gpu上做,gpu多线程同时处理运算,达到加速效果 ...

  7. SpringCloud入门(七): Zuul 简介与使用

    Zuul 简介 Zuul 微服务网关是为Spring Cloud Netflix提供动态路由,监控,弹性,安全等服务的框架.可以和Eureka.Ribbon.Hystrix等组件配合使用. Zuul ...

  8. 5.Maven坐标

    而这个坐标也意味着jar包等保存在 C:\Users\用户名.m2\repository\org\apache\tomcat\tomcat-catalina\9.0.2

  9. Ubuntu在Anaconda中安装TensorFlow GPU,Keras,Pytorch

    安装TensorFlow GPU pip install --ignore-installed --upgrade tensorflow-gpu 安装测试: $ source activate tf ...

  10. [JZOJ5343]健美猫<模拟>

    [思路] 这个是一个非常容易看出来的模拟,但是模拟也是有技巧的 一般人的模拟思路一般就是移动元素或者下标 然后我就看到了一个有趣的思路 建立坐标轴 以i坐标为横坐标,以si为纵坐标,然后画一条斜率为1 ...