Submission #902851

# Submission time Handle Problem Language Result Execution time Memory
902851 2024-01-11T03:36:44 Z 12345678 Election (BOI18_election) C++17
28 / 100
3000 ms 3416 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=5e5+5;
int n, v[nx], w[nx], q, l, r, cnt, ans;
string s;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>s;
    for (int i=1; i<=n; i++) v[i]=s[i-1]=='C';
    cin>>q;
    while (q--)
    {
        cin>>l>>r;
        cnt=ans=0;
        for (int i=l; i<=r; i++)
        {
            if (v[i]) w[i]=v[i], cnt++;
            else if (cnt==0) w[i]=2, ans++;
            else w[i]=0, cnt--;
        }
        cnt=0;
        for (int i=r; i>=l; i--)
        {
            if (w[i]==1) cnt++;
            else if (w[i]==2) continue;
            else if (w[i]==0&&cnt==0) ans++;
            else cnt--;
        }
        cout<<ans<<'\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2556 KB Output is correct
2 Correct 6 ms 2396 KB Output is correct
3 Correct 6 ms 2396 KB Output is correct
4 Correct 4 ms 2396 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2556 KB Output is correct
2 Correct 6 ms 2396 KB Output is correct
3 Correct 6 ms 2396 KB Output is correct
4 Correct 4 ms 2396 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Execution timed out 3089 ms 3416 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2556 KB Output is correct
2 Correct 6 ms 2396 KB Output is correct
3 Correct 6 ms 2396 KB Output is correct
4 Correct 4 ms 2396 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Execution timed out 3089 ms 3416 KB Time limit exceeded
7 Halted 0 ms 0 KB -