Submission #126368

# Submission time Handle Problem Language Result Execution time Memory
126368 2019-07-07T13:43:41 Z miguel Election (BOI18_election) C++14
28 / 100
3000 ms 1208 KB
#include<bits/stdc++.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <int, pi>
#define vi vector <int>
const ll mod = 1e9 + 7;
int n, q, l, r, sum;
set <int> s;
string ss;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n>>ss>>q;
    //cout<<q<<endl;
    for(int i=1; i<=q; i++){
        s.clear();
        sum=0;//cout<<l<<endl;
        cin>>l>>r;
        for(int ix=l-1; ix<=r-1; ix++){
            if(ss[ix]=='C') sum++;
            else sum--;
            if(sum<0){
                sum+=1;
                s.insert(ix);
            }
        }
        sum=0;
        for(int ix=r-1; ix>=l-1; ix--){
            if(ss[ix]=='C') sum++;
            else if(s.find(ix)==s.end())sum--;
            if(sum<0){
                sum+=1;
                s.insert(ix);
            }
        }
        cout<<s.size()<<"\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 44 ms 504 KB Output is correct
2 Correct 35 ms 504 KB Output is correct
3 Correct 22 ms 376 KB Output is correct
4 Correct 71 ms 424 KB Output is correct
5 Correct 43 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 504 KB Output is correct
2 Correct 35 ms 504 KB Output is correct
3 Correct 22 ms 376 KB Output is correct
4 Correct 71 ms 424 KB Output is correct
5 Correct 43 ms 376 KB Output is correct
6 Execution timed out 3033 ms 1208 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 504 KB Output is correct
2 Correct 35 ms 504 KB Output is correct
3 Correct 22 ms 376 KB Output is correct
4 Correct 71 ms 424 KB Output is correct
5 Correct 43 ms 376 KB Output is correct
6 Execution timed out 3033 ms 1208 KB Time limit exceeded
7 Halted 0 ms 0 KB -