This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |