#include <bits/stdc++.h>
using namespace std;
string s;
int a[2007];
int main()
{
int n,q;
cin>>n;
cin>>s;
cin>>q;
for(int i=0;i<q;i++)
{
int l,r;
cin>>l>>r;
int m=r-l+1,sum=0,t=0;
for(int i=l;i<=r;i++) a[i-l]=s[i-1]=='T'?-1:1;
for(int i=0;i<m;i++)
{
sum+=a[i];
if(sum<0) {sum=0; a[i]=0; t++;}
}
sum=0;
for(int i=m-1;i>=0;i--)
{
sum+=a[i];
if(sum<0) {sum=0; a[i]=0; t++;}
}
cout<<t<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
380 KB |
Output is correct |
2 |
Correct |
10 ms |
388 KB |
Output is correct |
3 |
Correct |
10 ms |
488 KB |
Output is correct |
4 |
Correct |
26 ms |
580 KB |
Output is correct |
5 |
Correct |
11 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
380 KB |
Output is correct |
2 |
Correct |
10 ms |
388 KB |
Output is correct |
3 |
Correct |
10 ms |
488 KB |
Output is correct |
4 |
Correct |
26 ms |
580 KB |
Output is correct |
5 |
Correct |
11 ms |
600 KB |
Output is correct |
6 |
Runtime error |
5 ms |
1396 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
380 KB |
Output is correct |
2 |
Correct |
10 ms |
388 KB |
Output is correct |
3 |
Correct |
10 ms |
488 KB |
Output is correct |
4 |
Correct |
26 ms |
580 KB |
Output is correct |
5 |
Correct |
11 ms |
600 KB |
Output is correct |
6 |
Runtime error |
5 ms |
1396 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |