#include <bits/stdc++.h>
using namespace std;
constexpr int M = 500'005;
bool czy[M];
int main(){
cin.tie(0)->sync_with_stdio(0);
int n;
cin>>n;
string temp;
cin>>temp;
string s = "#" + temp;
int k;
cin>>k;
while(k--){
int a, b;
cin>>a>>b;
int akt = 0;
for(int i=a; i<=b; i++){
if(s[i]=='C') akt++;
else if(czy[i]==0 && s[i]=='T') akt--;
if(akt < 0){
akt++;
czy[i] = 1;
}
}
akt = 0;
for(int i=b; i>=a; i--){
if(s[i]=='C') akt++;
else if(czy[i]==0 && s[i]=='T') akt--;
if(akt < 0){
akt++;
czy[i] = 1;
}
}
int wynik = 0;
//for(int i=1; i<=n; i++) cout<<czy[i]<<" ";
//cout<<endl;
for(int i=1; i<=n; i++) if(czy[i]==1) wynik++;
cout<<wynik<<endl;
for(int i=a; i<=b; i++) czy[i] = 0;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
500 KB |
Output is correct |
3 |
Correct |
8 ms |
348 KB |
Output is correct |
4 |
Correct |
10 ms |
348 KB |
Output is correct |
5 |
Correct |
8 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
500 KB |
Output is correct |
3 |
Correct |
8 ms |
348 KB |
Output is correct |
4 |
Correct |
10 ms |
348 KB |
Output is correct |
5 |
Correct |
8 ms |
344 KB |
Output is correct |
6 |
Execution timed out |
3006 ms |
1248 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
500 KB |
Output is correct |
3 |
Correct |
8 ms |
348 KB |
Output is correct |
4 |
Correct |
10 ms |
348 KB |
Output is correct |
5 |
Correct |
8 ms |
344 KB |
Output is correct |
6 |
Execution timed out |
3006 ms |
1248 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |