Submission #1089810

# Submission time Handle Problem Language Result Execution time Memory
1089810 2024-09-17T07:46:40 Z lucri Election (BOI18_election) C++17
28 / 100
3000 ms 1092 KB
#include <bits/stdc++.h>
using namespace std;
char a[500010];
bool e[500010];
int n,q,x,y;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>a+1>>q;
    while(q--)
    {
        cin>>x>>y;
        int sum=0;
        for(int i=x;i<=y;++i)
        {
            if(a[i]=='C')
                ++sum;
            else
                --sum;
            if(sum>=0)
                e[i]=true;
            else
            {
                e[i]=false;
                ++sum;
            }
        }
        sum=0;
        int ans=0;
        for(int i=y;i>=x;--i)
        {
            if(e[i]==false)
            {
                ++ans;
                continue;
            }
            if(a[i]=='C')
                ++sum;
            else
                --sum;
            if(sum>=0)
                e[i]=true;
            else
            {
                ++ans;
                e[i]=false;
                ++sum;
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:11:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   11 |     cin>>n>>a+1>>q;
      |             ~^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 4 ms 500 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 3 ms 500 KB Output is correct
5 Correct 3 ms 500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 4 ms 500 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 3 ms 500 KB Output is correct
5 Correct 3 ms 500 KB Output is correct
6 Execution timed out 3063 ms 1092 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 4 ms 500 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 3 ms 500 KB Output is correct
5 Correct 3 ms 500 KB Output is correct
6 Execution timed out 3063 ms 1092 KB Time limit exceeded
7 Halted 0 ms 0 KB -