#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
string s; cin >> s;
int q; cin >> q;
while(q--) {
int l, r; cin >> l >> r;
--l, --r;
int ans = 0;
int mn = 0;
int sum =0;
for(int i=l;i<=r;i++) {
if(s[i]=='C') sum++;
else --sum;
}
int curr = 0;
for(int i=l;i<=r;i++) {
if(s[i]=='C') ++curr;
else --curr;
mn = min(mn, curr);
ans = max(ans, curr-mn-sum);
}
cout << ans << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
364 KB |
Output is correct |
2 |
Correct |
9 ms |
364 KB |
Output is correct |
3 |
Correct |
9 ms |
364 KB |
Output is correct |
4 |
Correct |
9 ms |
364 KB |
Output is correct |
5 |
Correct |
9 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
364 KB |
Output is correct |
2 |
Correct |
9 ms |
364 KB |
Output is correct |
3 |
Correct |
9 ms |
364 KB |
Output is correct |
4 |
Correct |
9 ms |
364 KB |
Output is correct |
5 |
Correct |
9 ms |
364 KB |
Output is correct |
6 |
Execution timed out |
3087 ms |
1680 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
364 KB |
Output is correct |
2 |
Correct |
9 ms |
364 KB |
Output is correct |
3 |
Correct |
9 ms |
364 KB |
Output is correct |
4 |
Correct |
9 ms |
364 KB |
Output is correct |
5 |
Correct |
9 ms |
364 KB |
Output is correct |
6 |
Execution timed out |
3087 ms |
1680 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |