#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";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
364 KB |
Output is correct |
2 |
Correct |
7 ms |
364 KB |
Output is correct |
3 |
Correct |
6 ms |
364 KB |
Output is correct |
4 |
Correct |
6 ms |
364 KB |
Output is correct |
5 |
Correct |
4 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
364 KB |
Output is correct |
2 |
Correct |
7 ms |
364 KB |
Output is correct |
3 |
Correct |
6 ms |
364 KB |
Output is correct |
4 |
Correct |
6 ms |
364 KB |
Output is correct |
5 |
Correct |
4 ms |
364 KB |
Output is correct |
6 |
Execution timed out |
3057 ms |
1256 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
364 KB |
Output is correct |
2 |
Correct |
7 ms |
364 KB |
Output is correct |
3 |
Correct |
6 ms |
364 KB |
Output is correct |
4 |
Correct |
6 ms |
364 KB |
Output is correct |
5 |
Correct |
4 ms |
364 KB |
Output is correct |
6 |
Execution timed out |
3057 ms |
1256 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |