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;
#define LL long long
#define ULL unsigned LL
#define LD long double
#define debug(x) cerr << #x << " " << x << endl;
/*
* Rozwiazanie brutalne, O(n*q)
*
*/
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
string s;
cin>>n>>s>>q;
int a, b;
while(q--) {
cin>>a>>b; a--; b--;
vector<bool> czy(n, 0);
int ob = 0;
int ans = 0;
for(int i=a; i<=b; i++) {
ob += (s[i] == 'C' ? 1 : -1);
if(ob < 0) {
ans++;
ob++;
czy[i] = 1;
}
}
ob = 0;
for(int i=b; i>=a; i--) {
if(czy[i])
continue;
ob += (s[i] == 'C' ? 1 : -1);
if(ob < 0) {
ans++;
ob++;
}
}
cout<<ans<<"\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |