//
// main.cpp
//
// Created by Panagiotis Chadjicostas on
// Copyright © Panagiotis Hadjicostas. All rights reserved.
//
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <limits>
#include <list>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
#define fo(i,a,b) for(int i = a; i<=b; i++)
#define f(i,b) for(int i=0;i<b;i++)
#define F first
#define S second
#define sz size
#define ls s,m,idx<<1
#define rs m+1,e,idx<<1|1
const ll MOD=ll(1e9)+7;
const ll MAXN=2*ll(1e6);
void checker(){
ll n=rand()%20+2;
vi a(n,ll());
for(ll i=0;i<n;i++){
a[i]=rand()%20+2;
}
for(ll b=0;b<(1<<n);b++){
vi on,off;
for(ll i=0;i<n;i++){
if(i&(1<<i)){
on.push_back(i);
}
else{
off.push_back(i);
}
}
}
}
///////////////////////////////////////////////////////////////////////
void solve(){
ll n;cin>>n;
string s;cin>>s;
s=' '+s;
/*
ll prefix[n+2];
prefix[0]=0;
for(ll i=1;i<=n;i++){
prefix[i]=prefix[i-1]+(s[i]=='C'?1:(-1));
}
*/
ll q;cin>>q;
while(q--){
ll l,r;cin>>l>>r;
string s1=s;
ll sum=0,counter=0;
for(ll i=l;i<=r;i++){
if(s1[i]=='C'){
sum++;
}
else if(s1[i]=='T')
sum--;
if(sum<0){
counter++;
sum++;
s1[i]='N';
}
}
sum=0;
for(ll i=r;i>=l;i--){
if(s1[i]=='C'){
sum++;
}
else if(s1[i]=='T')
sum--;
if(sum<0){
counter++;
sum++;
s1[i]='N';
}
}
cout<<counter<<endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t=1;//cin>>t;
while (t--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
212 KB |
Output is correct |
2 |
Correct |
11 ms |
332 KB |
Output is correct |
3 |
Correct |
13 ms |
340 KB |
Output is correct |
4 |
Correct |
10 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
212 KB |
Output is correct |
2 |
Correct |
11 ms |
332 KB |
Output is correct |
3 |
Correct |
13 ms |
340 KB |
Output is correct |
4 |
Correct |
10 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
3072 ms |
1040 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
212 KB |
Output is correct |
2 |
Correct |
11 ms |
332 KB |
Output is correct |
3 |
Correct |
13 ms |
340 KB |
Output is correct |
4 |
Correct |
10 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
3072 ms |
1040 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |