Contest Duration: ~ (local time) (140 minutes) Back to Home

Submission #3212442

Source Code Expand

Copy
```#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = unsigned long long;

ll n, x, xs[2*100000+5];

ll getCost(int k){
ll result = 0;
result += x*(n+k);
result += (xs[0]-xs[k])*2;
int i;
for(i=0;i<n/k;i++){
result += (2*i+3)*(xs[i*k]-xs[(i+1)*k]);
}
if(n%k!=0){
result += (2*i+3)*(xs[i*k]-xs[n]);
}
return result;
}

int main(){
int tmp;
xs[0] = 0;

cin >> n >> x;
for(int i=0;i<n;i++){
cin >> tmp;
xs[i+1] = xs[i]+tmp;
}
reverse(begin(xs), begin(xs)+(n+1));

ll ans = getCost(1);
for(int i=2;i<=n;i++)
ans = min(ans, getCost(i));

cout << ans << endl;

/*
int p[4];
ll q[4];
p[0] = 1;
q[0] = getCost(p[0]);
p[3] = n;
q[3] = getCost(p[3]);
while(p[3]-p[0]>3){
//cout << p[0] << " " << p[3] << endl;
p[1] = (p[0]+p[3])/2;
q[1] = getCost(p[1]);
p[2] = p[1]+1;
q[2] = getCost(p[2]);
ll m = *min_element(begin(q), end(q));
if(m==q[0]){
p[3] = p[1];
q[3] = q[1];
}
else if(m==q[3]){
p[0] = p[2];
q[0] = q[2];
}
else if(m==q[1]){
q[0] = q[1];
p[0] = p[1];
}
else{
q[3] = q[2];
p[3] = p[2];
}
}
p[1] = (p[0]+p[3])/2;
q[1] = getCost(p[1]);
p[2] = p[1]+1;
q[2] = getCost(p[2]);

cout << (*min_element(begin(q), end(q))) << endl;
*/

/*
下凸っぽいので最小値を探索できそう?
for(int k=1;k<=n;k++)
cout << k << "回目： " << getCost(k) << endl;
*/

return 0;
}```

#### Submission Info

Submission Time 2018-09-16 23:51:58+0900 B - Garbage Collector glia269 C++14 (GCC 5.4.1) 700 1780 Byte AC 116 ms 1792 KB

#### Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Subtask1 400 / 400 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, stest_01.txt, stest_02.txt, stest_03.txt, stest_04.txt, stest_05.txt, stest_06.txt, stest_07.txt, stest_08.txt, stest_09.txt, stest_10.txt, stest_11.txt, stest_12.txt
All 300 / 300 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, stest_01.txt, stest_02.txt, stest_03.txt, stest_04.txt, stest_05.txt, stest_06.txt, stest_07.txt, stest_08.txt, stest_09.txt, stest_10.txt, stest_11.txt, stest_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt
Case Name Status Exec Time Memory
sample_01.txt 1 ms 256 KB
sample_02.txt 1 ms 256 KB
sample_03.txt 1 ms 256 KB
sample_04.txt 1 ms 256 KB
stest_01.txt 3 ms 384 KB
stest_02.txt 2 ms 256 KB
stest_03.txt 1 ms 256 KB
stest_04.txt 1 ms 256 KB
stest_05.txt 2 ms 256 KB
stest_06.txt 2 ms 256 KB
stest_07.txt 2 ms 256 KB
stest_08.txt 2 ms 256 KB
stest_09.txt 1 ms 256 KB
stest_10.txt 2 ms 256 KB
stest_11.txt 2 ms 256 KB
stest_12.txt 1 ms 256 KB
test_13.txt 116 ms 1792 KB
test_14.txt 114 ms 1792 KB
test_15.txt 24 ms 512 KB
test_16.txt 83 ms 1792 KB
test_17.txt 85 ms 1792 KB
test_18.txt 12 ms 512 KB
test_19.txt 98 ms 1792 KB
test_20.txt 96 ms 1792 KB
test_21.txt 99 ms 1792 KB
test_22.txt 96 ms 1792 KB
test_23.txt 85 ms 1792 KB
test_24.txt 84 ms 1792 KB
test_25.txt 41 ms 1024 KB
test_26.txt 98 ms 1792 KB
test_27.txt 96 ms 1792 KB
test_28.txt 79 ms 1536 KB