codeforces158D
Ice Sculptures
The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular n-gon. They are numbered in clockwise order with numbers from 1 to n.
The site of the University has already conducted a voting that estimated each sculpture's characteristic of ti — the degree of the sculpture's attractiveness. The values of ti can be positive, negative or zero.
When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that:
- the remaining sculptures form a regular polygon (the number of vertices should be between 3 and n),
- the sum of the ti values of the remaining sculptures is maximized.
Help the Vice Rector to analyze the criticism — find the maximum value of ti sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved.
Input
The first input line contains an integer n (3 ≤ n ≤ 20000) — the initial number of sculptures. The second line contains a sequence of integers t1, t2, ..., tn, ti — the degree of the i-th sculpture's attractiveness ( - 1000 ≤ ti ≤ 1000). The numbers on the line are separated by spaces.
Output
Print the required maximum sum of the sculptures' attractiveness.
Examples
8
1 2 -3 4 -5 5 2 3
14
6
1 -2 3 -4 5 -6
9
6
1 2 3 4 5 6
21
Note
In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.
sol:想了半天都不会,然后看题解,然后惊呼这TM能过??
for(i=;i*<=n;i++)
{
if(n%i==)
{
for(j=;j<=i;j++)
{
int Sum=;
for(k=j;k<=n;k+=i)
{
Sum+=a[k];
}
ans=max(ans,Sum);
}
}
}
这也太暴力了吧,我怎么算复杂度都是n2及以上啊,为什么能过啊qaq
Ps:不管了,弃了弃了(跪求更好的做法或证明一下复杂度)
4.3updata:这是调和级数的复杂度,似乎是n1.5。实锤不会算复杂度qaq
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,a[N];
int main()
{
int i,j,k,ans=-0x3f3f3f3f;
R(n);
for(i=;i<=n;i++) R(a[i]);
for(i=;i*<=n;i++)
{
if(n%i==)
{
for(j=;j<=i;j++)
{
int Sum=;
for(k=j;k<=n;k+=i)
{
Sum+=a[k];
}
ans=max(ans,Sum);
}
}
}
Wl(ans);
return ;
}
/*
input
8
1 2 -3 4 -5 5 2 3
output
14 input
6
1 -2 3 -4 5 -6
output
9 input
6
1 2 3 4 5 6
output
21 input
4
1 -10 1 -10
output
-18
*/
codeforces158D的更多相关文章
随机推荐
- 在Ubuntu中部署并测试HyperLedger Fabric 0.6
最近开始研究区块链,对这个新兴的技术有了基本概念上的了解,所以打算基于一个开源项目做做实验.如果是做数字货币,那么比特币的源代码是最好的了,不过这算是区块链1.0吧,已经有很多改进的竞争币和山寨币出来 ...
- 【重磅】Spring Boot 2.1.0 权威发布
如果这两天登录 https://start.spring.io/ 就会发现,Spring Boot 默认版本已经升到了 2.1.0.这是因为 Spring Boot 刚刚发布了 2.1.0 版本,我们 ...
- ESP8266-Arduino杀手?
Arduino之所以流行可能是因为它的学习曲线比较平缓,另外是支持它的第三方程序库非常多,无论在什么平台上都比较容易入门.多年前我曾和一些搞嵌入开发多年的朋友请教,他们更建议我多点尝试STM的开发,A ...
- LeetCode 595. Big Countries
There is a table World +-----------------+------------+------------+--------------+---------------+ ...
- 安装SQL Server时,提示VS Shell 安装失败,退出代码为 1638。
在安装SQL Server时,提示“安装 Microsoft Visual C++ 2015 Redistributable 时出错VS Shell 安装失败,退出代码为 1638”. 原因:是由于你 ...
- Diverse Garland CodeForces - 1108D (贪心+暴力枚举)
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...
- Day5 Pyhton基础之编码与解码(四)
1.编码与解码 1.1现在常用的编码类型
- 自己实现数据结构系列三---Stack
一.代码部分 1.定义接口 public interface Stack<E> { int getSize(); boolean isEmpty(); void push(E e); E ...
- C\C++学习笔记 3
C++记录7 函数指针: 函数名为地址, 地址指的是在机器指令存储的地址. double func(int line){ reture line*3.5;} void f(int line, doub ...
- java的static与C#的static的异同
static static同样可以用在类.方法.变量上面,但是在java和C#中所表示的意思完全不同,我个人的总结是C#中的静态和非静态是有一个明显的分界的,静态的是属于类级别的,而非静态的是属于实例 ...