This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// 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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |