Submission #849305

#TimeUsernameProblemLanguageResultExecution timeMemory
849305JoksimKaktusElection (BOI18_election)C++17
28 / 100
3055 ms1276 KiB
#include <bits/stdc++.h>

using namespace std;
#define ll long long;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int n,q;
    string s;
    cin >> n >> s >> q;
    for(int i = 0;i < q;i++){
        int l,r;
        cin >> l >> r;
        vector <bool> vis(n,false);
        int c = 0;
        int t = 0;
        for(int j = l-1; j < r;j++){
            if(s.at(j) == 'C'){
                c++;
            }else{
                t++;
                if(t > c){
                    t--;
                    vis[j] = true;
                }
            }
        }
        c = 0;
        t = 0;
        for(int j = r-1; j >= l-1;j--){
            if(s.at(j) == 'C'){
                c++;
            }else if(!vis[j]){
                t++;
                if(t > c){
                    t--;
                    vis[j] = true;
                }
            }
        }
        int res = 0;
        for(int j = l-1;j < r;j++){
            if(vis[j]){
                res++;
            }
        }
        cout << res << "\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...