Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
542 B
7
Indexable
Never
int k = 0;
    for(int i =0;i<color.length();++i)
    {
        if(color[i] == '1')
        ++k;
    }
    
    vector<long> A, B(1);
        for (int i = 0; i < color.size(); ++i)
            if (color[i] == '1')
                A.push_back(i);
        long n = A.size(), res = 2e9;
        for (int i = 0; i < n; ++i)
            B.push_back(B[i] + A[i]);
        for (int i = 0; i < n - k + 1; ++i)
            res = min(res, B[i + k] - B[k / 2 + i] - B[(k + 1) / 2 + i] + B[i]);
        res -= (k / 2) * ((k + 1) / 2);
        cout<< res;
Leave a Comment