Submission #1026708

#TimeUsernameProblemLanguageResultExecution timeMemory
1026708vjudge1Election (BOI18_election)C++17
28 / 100
3085 ms1132 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    string s;
    cin >> n >> s >> q;
    while (q--) {
        string p=s;
        int l, r, rez=0;
        cin >> l >> r;
        l--, r--;
        int cap=0, tony=0;
        for (int i=l;i<=r;i++) {
            if (p[i]=='C') cap++;
            else {
                tony++;
                if (tony>cap) {
                    tony--;
                    p[i]='0';
                    rez++;
                }
            }
        }
        cap=0, tony=0;
        for (int i=r;i>=l;i--) {
            if (p[i]=='C') cap++;
            else if (p[i]=='0') continue;
            else {
                tony++;
                if (tony>cap) {
                    tony--;
                    p[i]='0';
                    rez++;
                }
            }
        }
        cout << rez << '\n';
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...