Submission #68580

# Submission time Handle Problem Language Result Execution time Memory
68580 2018-08-17T11:47:42 Z renatsj Election (BOI18_election) C++14
28 / 100
3000 ms 2300 KB
#include<bits/stdc++.h>
using namespace std;
int i,j,n,m,l,r,mas[500005],a[2],rez,maz,sum[500005];
vector<int> k;
vector<int>::iterator it;
char c;
int main()
{
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    i=0;
    while (i<n)
    {
        cin >> c;
        if (c=='C')
        {
            mas[i]=1;
        }
        else
        {
            mas[i]=-1;
        }
        i++;
    }
    i=n-1;
    while (i>=0)
    {
        sum[i]=sum[i+1]+mas[i];
        i--;
    }
    cin >> m;
    i=0;
    while (i<m)
    {
        cin >> l >> r;
        l--;
        r--;
        j=l;
        a[0]=0;
        a[1]=0;
        k.clear();
        rez=0;
        maz=1000000000;
        while (j<=r)
        {
            a[max(0,mas[j])]++;
            maz=min(maz,sum[j]);
            if (a[1]<a[0])
            {
                a[max(0,mas[j])]--;
                k.push_back(j);
                maz++;
                rez++;
            }
            //cout << j << " " << a[0] << " " << a[1] << "\n";
            j++;
        }
        //cout << rez << " " << maz << " " << maz-sum[r+1] << "  ";
        rez+=max(0,-maz+sum[r+1]);
        /*a[0]=0;
        a[1]=0;
        j=r;
        it=k.end();
        it--;
        while (j>=l)
        {
            if (k.empty()||j!=*it)
            {
                a[max(0,mas[j])]++;
                if (a[1]<a[0])
                {
                    a[max(0,mas[j])]--;
                    rez++;
                }
            }
            else
            {
                k.pop_back();
                it=k.end();
                it--;
            }
            j--;
        }*/
        cout << rez << "\n";
        i++;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 376 KB Output is correct
2 Correct 9 ms 496 KB Output is correct
3 Correct 10 ms 732 KB Output is correct
4 Correct 9 ms 732 KB Output is correct
5 Correct 8 ms 732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 376 KB Output is correct
2 Correct 9 ms 496 KB Output is correct
3 Correct 10 ms 732 KB Output is correct
4 Correct 9 ms 732 KB Output is correct
5 Correct 8 ms 732 KB Output is correct
6 Execution timed out 3043 ms 2300 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 376 KB Output is correct
2 Correct 9 ms 496 KB Output is correct
3 Correct 10 ms 732 KB Output is correct
4 Correct 9 ms 732 KB Output is correct
5 Correct 8 ms 732 KB Output is correct
6 Execution timed out 3043 ms 2300 KB Time limit exceeded
7 Halted 0 ms 0 KB -