Submission #892465

# Submission time Handle Problem Language Result Execution time Memory
892465 2023-12-25T11:24:53 Z maxFedorchuk Election (BOI18_election) C++14
28 / 100
3000 ms 1124 KB
#include <bits/stdc++.h>

#pragma GCC target("avx2,sse4,popcnt,bmi")
#pragma GCC optimize("Ofast,unroll-loops")

using namespace std;

const long long MX=500002;

string s;
int n,q;

int masnm[MX];

void zap(int l,int r,int nmzp)
{
    int zrsum=0,kop=0;

    for(int i=l;i<=r;i++)
    {
        if(s[i]=='C')
        {
            zrsum++;
        }
        else
        {
            if(zrsum==0)
            {
                masnm[i]=nmzp;
                kop++;
            }
            else
            {
                zrsum--;
            }
        }
    }

    zrsum=0;
    for(int i=r;i>=l;i--)
    {
        if(s[i]=='C')
        {
            zrsum++;
        }
        else
        {
            if(masnm[i]!=nmzp)
            {
                if(zrsum==0)
                {
                    kop++;
                }
                else
                {
                    zrsum--;
                }
            }
        }
    }

    cout<<kop<<"\n";
    return;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    cin>>n>>s>>q;
    s="*"+s;

    for(int i=1;i<=q;i++)
    {
        int l,r;
        cin>>l>>r;
        zap(l,r,i);
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 7 ms 348 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 3 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 7 ms 348 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 3 ms 472 KB Output is correct
6 Execution timed out 3042 ms 1124 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 7 ms 348 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 3 ms 472 KB Output is correct
6 Execution timed out 3042 ms 1124 KB Time limit exceeded
7 Halted 0 ms 0 KB -