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 = "", z = "";
for(int i = l; i <= r; i++) t.push_back(s[i]);
z = t;
int sum = 0, cnt = 1e9;
for(int j = 0; j <= Sz(z); j++) {
for(int k = 0; k <= Sz(z) - j; k++) {
t = z;
int val = 0;
sum = 0;
for(int i = 0; i < j; i++) if(t[i] == 'T') t[i] = '?', val++;
for(int i = Sz(t) - 1; i >= Sz(t) - k; i--) if(t[i] == 'T') t[i] = '?', val++;
bool flag = true;
for(int i = 0; i < Sz(t); i++) {
if(t[i] == 'T') sum--;
else if(t[i] == 'C') sum++;
if(sum < 0) {
flag = false;
break;
}
}
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) {
flag = false;
break;
}
}
if(flag) {
cnt = min(cnt, val);
}
}
}
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... |