답안 #892463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892463 2023-12-25T11:24:17 Z maxFedorchuk Election (BOI18_election) C++14
28 / 100
3000 ms 1448 KB
#include <bits/stdc++.h>
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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 4 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 4 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Execution timed out 3075 ms 1448 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 4 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Execution timed out 3075 ms 1448 KB Time limit exceeded
7 Halted 0 ms 0 KB -