#include <bits/stdc++.h>
using namespace std;
signed main() {
int n,q; cin>>n;
string s; cin>>s;
cin>>q;
while(q--) {
int l,r; cin>>l>>r;
l--,r--;
vector<bool>v(n, 0);
int cnt = 0;
int ans = 0;
for(int i = l ; i <= r ; i++) {
if(s[i] == 'T')
cnt--;
else
cnt++;
if(cnt < 0)
v[i] = 1, ans++, cnt++;
}
cnt = 0;
for(int i = r ; i >= l ; i--) {
if(s[i] == 'C')
cnt++;
else if(!v[i])
cnt--;
if(cnt < 0)
ans++, cnt++;
}
cout << ans << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
212 KB |
Output is correct |
2 |
Correct |
10 ms |
212 KB |
Output is correct |
3 |
Correct |
11 ms |
212 KB |
Output is correct |
4 |
Correct |
10 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
212 KB |
Output is correct |
2 |
Correct |
10 ms |
212 KB |
Output is correct |
3 |
Correct |
11 ms |
212 KB |
Output is correct |
4 |
Correct |
10 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
212 KB |
Output is correct |
6 |
Execution timed out |
3076 ms |
1132 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
212 KB |
Output is correct |
2 |
Correct |
10 ms |
212 KB |
Output is correct |
3 |
Correct |
11 ms |
212 KB |
Output is correct |
4 |
Correct |
10 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
212 KB |
Output is correct |
6 |
Execution timed out |
3076 ms |
1132 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |