Submission #114827

# Submission time Handle Problem Language Result Execution time Memory
114827 2019-06-03T10:41:42 Z Charis02 Election (BOI18_election) C++14
28 / 100
3000 ms 2352 KB
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define INF 1e9+7

using namespace std;

ll n,q,ar[N],l,r;
char c;
bool akiro[N];

ll solve(ll i,ll j)
{
    ll sum = 0;
    ll ans = 0;

    rep(s,i,j+1)
        akiro[s] = false;

    rep(s,i,j+1)
    {
        sum += ar[s];

        if(sum < 0)
        {
            ans++;
            akiro[s] = true;
            sum++;
        }
    }

    sum = 0;

    for(int s = j;s >= i;s--)
    {
        sum += (!akiro[s])*ar[s];

        if(sum < 0)
        {
            sum++;
            ans++;
        }
    }

    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n;

    rep(i,0,n)
    {
        cin >> c;

        if(c == 'C')
            ar[i] = 1;
        else
            ar[i] = -1;
    }

    cin >> q;

    rep(i,0,q)
    {
        cin >> l >> r;

        cout << solve(l-1,r-1) << endl;
    }

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 14 ms 384 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 8 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 14 ms 384 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 8 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
6 Correct 2865 ms 2352 KB Output is correct
7 Execution timed out 3035 ms 1840 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 14 ms 384 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 8 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
6 Correct 2865 ms 2352 KB Output is correct
7 Execution timed out 3035 ms 1840 KB Time limit exceeded
8 Halted 0 ms 0 KB -