Contest Duration: ~ (local time) (90 minutes)

Submission #569457

Source Code Expand

Copy
```#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
int N; scanf("%d", &N);
long long *A = new long long[N];
long long *Asum = new long long[N+1];
Asum[0] = 0;
for(int i = 0; i < N; ++i) {
scanf("%lld", &A[i]);
Asum[i+1] = Asum[i] + A[i];
}
long long *sum1 = new long long[N+1];
long long *sum2 = new long long[N+1];
sum1[1] = 0;
for(int i = 3; i <= N; i+=2) {
sum1[i] = sum1[i-2] + (Asum[i-2]+i-3) + (Asum[i-1]+i-2);
// printf("sum1[%d] = %lld\n", i, sum1[i]);
}
sum2[N-1] = 0;
for(int i = N-3; i >= 0; i-=2) {
sum2[i] = sum2[i+2] + (Asum[N]-Asum[i+2]+(N-i)-3) + (Asum[N]-Asum[i+1]+(N-i)-2);
// printf("sum2[%d] = %lld\n", i, sum2[i]);
}
long long minval = 1LL<<62;
for(int i = 1; i+1 < N; i+=2) {
long long val;
val = sum1[i] + sum2[i+1] + (Asum[i]+i-1) + (Asum[i+1]+i);
minval = min(minval, val);
// printf("val = %lld\n", val);
val = sum1[i] + sum2[i+1] + (Asum[N]-Asum[i+1]+(N-i-1)-1) + (Asum[N]-Asum[i]+(N-i-1));
minval = min(minval, val);
// printf("val = %lld\n", val);
}
printf("%lld\n", minval);
delete[] sum2;
delete[] sum1;
delete[] A;
return 0;
}
```

#### Submission Info

Submission Time 2015-11-15 09:29:31+0900 A - 一次元オセロ qnighy C++11 (GCC 4.9.2) 100 1219 Byte AC 54 ms 3956 KB

#### Compile Error

```./Main.cpp: In function ‘int main()’:
./Main.cpp:6:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int N; scanf("%d", &N);
^
./Main.cpp:11:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &A[i]);
^
```

#### Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample-01.txt, sample-02.txt
All 100 / 100 sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt
Case Name Status Exec Time Memory
01-01.txt 25 ms 792 KB
01-02.txt 23 ms 796 KB
01-03.txt 24 ms 928 KB
01-04.txt 52 ms 3924 KB
01-05.txt 50 ms 3868 KB
01-06.txt 52 ms 3920 KB
01-07.txt 50 ms 3956 KB
01-08.txt 45 ms 3360 KB
01-09.txt 45 ms 3872 KB
01-10.txt 42 ms 3872 KB
01-11.txt 54 ms 3920 KB
01-12.txt 41 ms 3108 KB
sample-01.txt 25 ms 796 KB
sample-02.txt 24 ms 672 KB