#include <bits/stdc++.h>
#define long long ll
using namespace std;
const int MAX_N=1e6;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int q;
cin >> q;
while(q--) {
int l,r;
cin >> l >> r;
--l;
int cnt=0, ans=0;
string tmp=s;
for(int i=l; i<r; ++i) {
if(s[i]=='C') ++cnt;
else if(s[i]=='T') --cnt;
if(cnt<0) {
++cnt;
++ans;
tmp[i]='X';
}
}
cnt=0;
for(int i=r-1; i>=l; --i) {
if(tmp[i]=='C') ++cnt;
else if(tmp[i]=='T') --cnt;
if(cnt<0) {
++cnt;
++ans;
}
}
cout << ans << endl;
}
}
int main()
{
int T=1;
while(T--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
7 ms |
348 KB |
Output is correct |
3 |
Correct |
8 ms |
348 KB |
Output is correct |
4 |
Correct |
7 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
7 ms |
348 KB |
Output is correct |
3 |
Correct |
8 ms |
348 KB |
Output is correct |
4 |
Correct |
7 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
448 KB |
Output is correct |
6 |
Execution timed out |
3065 ms |
1272 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
7 ms |
348 KB |
Output is correct |
3 |
Correct |
8 ms |
348 KB |
Output is correct |
4 |
Correct |
7 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
448 KB |
Output is correct |
6 |
Execution timed out |
3065 ms |
1272 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |