// And you curse yourself for things you never done
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 5e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
string solve(string s){
string ans;
int num = 0;
for(char c : s){
num+= (c == 'C' ? 1 : -1);
if(num >= 0)
ans+= c;
num = max(num, int(0));
}
return ans;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();
int n;
cin >> n;
string s;
cin >> s;
int q;
cin >> q;
while(q--){
int l, r;
cin >> l >> r;
--l;
string ss = solve(s.substr(l, r-l));
reverse(ss.begin(), ss.end());
ss = solve(ss);
cout << r-l-sz(ss) << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
384 KB |
Output is correct |
2 |
Correct |
16 ms |
384 KB |
Output is correct |
3 |
Correct |
16 ms |
384 KB |
Output is correct |
4 |
Correct |
15 ms |
384 KB |
Output is correct |
5 |
Correct |
14 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
384 KB |
Output is correct |
2 |
Correct |
16 ms |
384 KB |
Output is correct |
3 |
Correct |
16 ms |
384 KB |
Output is correct |
4 |
Correct |
15 ms |
384 KB |
Output is correct |
5 |
Correct |
14 ms |
384 KB |
Output is correct |
6 |
Execution timed out |
3066 ms |
1204 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
384 KB |
Output is correct |
2 |
Correct |
16 ms |
384 KB |
Output is correct |
3 |
Correct |
16 ms |
384 KB |
Output is correct |
4 |
Correct |
15 ms |
384 KB |
Output is correct |
5 |
Correct |
14 ms |
384 KB |
Output is correct |
6 |
Execution timed out |
3066 ms |
1204 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |