// oooo
/*
har chi delet mikhad bebar ~
gitar o ba khodet nabar! ~
;Amoo_Hasan;
*/
#include<bits/stdc++.h>
//#pragma GCC optimize("O3,no-stack-protector,unroll-loops")
//#pragma GCC target("avx2,fma")
using namespace std;
typedef long long ll;
typedef long double ld;
#define Sz(x) int((x).size())
#define All(x) (x).begin(), (x).end()
#define wtf(x) cout<<#x <<" : " <<x <<endl
constexpr ll inf = 1e18, N = 1e6 + 10, mod = 1e9 + 7, pr = 1000696969;
int main() {
ios :: sync_with_stdio(0), cin.tie(0);
int n; cin >>n;
string s; cin >>s;
int q; cin >>q;
while(q--) {
int l, r; cin >>l >>r; l--, r--;
string t = "";
for(int i = l; i <= r; i++) t.push_back(s[i]);
int sum = 0, cnt = 0;
for(int i = 0; i < Sz(t); i++) {
if(t[i] == 'T') sum--;
else sum++;
if(sum < 0) {
cnt++;
t[i] = '?';
sum++;
}
}
sum = 0;
for(int i = Sz(t) - 1; i >= 0; i--) {
if(t[i] == 'T') sum--;
else if(t[i] == 'C') sum++;
if(sum < 0) {
t[i] = '?';
cnt++;
sum++;
}
}
cout<<cnt <<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
340 KB |
Output is correct |
2 |
Correct |
15 ms |
352 KB |
Output is correct |
3 |
Correct |
13 ms |
340 KB |
Output is correct |
4 |
Correct |
13 ms |
348 KB |
Output is correct |
5 |
Correct |
11 ms |
360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
340 KB |
Output is correct |
2 |
Correct |
15 ms |
352 KB |
Output is correct |
3 |
Correct |
13 ms |
340 KB |
Output is correct |
4 |
Correct |
13 ms |
348 KB |
Output is correct |
5 |
Correct |
11 ms |
360 KB |
Output is correct |
6 |
Execution timed out |
3067 ms |
1268 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
340 KB |
Output is correct |
2 |
Correct |
15 ms |
352 KB |
Output is correct |
3 |
Correct |
13 ms |
340 KB |
Output is correct |
4 |
Correct |
13 ms |
348 KB |
Output is correct |
5 |
Correct |
11 ms |
360 KB |
Output is correct |
6 |
Execution timed out |
3067 ms |
1268 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |