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

Submission #4217036

Source Code Expand

Copy
```#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const long long INF = 1e15;

struct SegmentTree {
private:
long long n;
vector< long long > node;//min,max
public:
SegmentTree(vector<long long> v, vector<long long> u){
long long sz = v.size();
n = 1;
while(n < sz) n *= 2;
node.resize(2*n-1,INF);
for(int i = 0; i < sz; ++i){
node[i+n-1] = v[i];
if(i > 0) node[i+n-1] += u[i-1];
}
for(int i = n-2; i >= 0; --i)
node[i] = min(node[2*i+1],node[2*i+2]);
}
long long get_min(long long a, long long b, long long k=0, long long l=0, long long r=-1){
if(r < 0) r = n;
if(r <= a or b <= l) return INF;
if(a <= l and r <= b) return node[k];
long long vl = get_min(a,b,2*k+1,l,(l+r)/2);
long long vr = get_min(a,b,2*k+2,(l+r)/2,r);
return min(vl,vr);
}
};

int main(){
long long L;
cin >> L;
L += 2;
vector<long long> A(L,0), F(L+1,0), B(L+1,0), C(L+1,0), O(L+1,0);
for(int i = 0; i < L-2; ++i) cin >> A[i+1];
for(int i = 0; i < L; ++i) C[i+1] += A[i] + C[i];
for(int i = 0; i < L; ++i) O[i+1] += 1-(A[i]%2) + O[i];
for(int i = 0; i < L; ++i){
long long t = A[i]%2;
if(A[i] < 2) t = 2-A[i];
F[i+1] = min(F[i]+t,C[i+1]);
}
for(int i = L-1; i >= 0; --i){
long long t = A[i]%2;
if(A[i] < 2) t = 2-A[i];
B[i] = min(B[i+1]+t,C[L]-C[i]);
}
fprintf(stderr,"F : "); for(int i = 0; i <= L; ++i) cerr << F[i] << " "; cerr << endl;
fprintf(stderr,"B : "); for(int i = 0; i <= L; ++i) cerr << B[i] << " "; cerr << endl;
fprintf(stderr,"O : "); for(int i = 0; i <= L; ++i) cerr << O[i] << " "; cerr << endl;
SegmentTree st(B,O);
long long ans = min({F[L],O[L],B[0],C[L]});
for(int i = 0; i <= L; ++i){
long long t = F[i] + st.get_min(i,L) - O[i];
// fprintf(stderr,"F[%d] = %lld, st.get_min(%d) = %lld\n",i,F[i],i+1,st.get_min(i+1,L));
// fprintf(stderr,"O[%d] = %lld\n",i,O[i]);
// cerr << i << " " << t << endl;
ans = min(ans,t);
}
cout << ans << endl;
}
```

#### Submission Info

Submission Time 2019-02-09 22:54:38+0900 D - Ears TAB C++14 (GCC 5.4.1) 0 2094 Byte WA 597 ms 15232 KB

#### Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 0 / 600 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 591 ms 15232 KB
02.txt 585 ms 15232 KB
03.txt 597 ms 15232 KB
04.txt 590 ms 15232 KB
05.txt 550 ms 15232 KB
06.txt 539 ms 15232 KB
07.txt 547 ms 15232 KB
08.txt 545 ms 15232 KB
09.txt 545 ms 15232 KB
10.txt 550 ms 15232 KB
11.txt 550 ms 15232 KB
12.txt 550 ms 15232 KB
13.txt 547 ms 15232 KB
14.txt 542 ms 15232 KB
15.txt 551 ms 15232 KB
16.txt 551 ms 15232 KB
17.txt 548 ms 15232 KB
18.txt 538 ms 15232 KB
19.txt 549 ms 15232 KB
20.txt 546 ms 15232 KB
21.txt 544 ms 15232 KB
22.txt 536 ms 15232 KB
23.txt 548 ms 15232 KB
24.txt 543 ms 15232 KB
25.txt 548 ms 15232 KB
26.txt 589 ms 15232 KB
27.txt 547 ms 15232 KB
28.txt 549 ms 15232 KB
29.txt 563 ms 15232 KB
30.txt 555 ms 15232 KB
31.txt 555 ms 15232 KB
32.txt 573 ms 15232 KB
33.txt 545 ms 15232 KB
34.txt 538 ms 15232 KB
35.txt 568 ms 15232 KB
36.txt 545 ms 15232 KB
37.txt 1 ms 256 KB
38.txt 1 ms 256 KB
39.txt 1 ms 256 KB
40.txt 1 ms 256 KB
41.txt 1 ms 256 KB
42.txt 1 ms 256 KB
s1.txt 1 ms 256 KB
s2.txt 1 ms 256 KB
s3.txt 1 ms 256 KB