Submission #637493

# Submission time Handle Problem Language Result Execution time Memory
637493 2022-09-02T08:59:56 Z Benmath Election (BOI18_election) C++14
28 / 100
3000 ms 1368 KB
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string s;
cin>>s;
int q;
cin>>q;
while(q--){
   int l,r;
   cin>>l>>r;
   l--;
   r--;
   vector<int>v1;
   vector<int>v2;
   int ro=0;
   for(int i=l;i<=r;i++){
      if(s[i]=='C'){
         if(i!=l and s[i-1]=='T'){
            v1.push_back(0-ro);
            if(ro<0){
            ro=0;
            }
         }
         ro++;
      }else{
         
         ro--;
      }
   }
   if(s[r]=='T'){
      v1.push_back(0-ro);
   }
   int j=v1.size()-1;
   ro=0;
   int ans=0;

     for(int i=r;i>=l;i--){
      if(s[i]=='C'){
         if(i!=r and s[i+1]=='T'){
   if(ro<0){
          ans=ans+max(abs(ro),v1[j]);
          
            ro=ro+max(abs(ro),v1[j]);
            j--;
   }else if(v1[j]>0){
      ans=ans+v1[j];
      ro=ro+v1[j];
      j--;
   }else{
      j--;
   }
         
         }
         ro++;
      }else{
         
         ro--;
      }
   }
     
   if(s[l]=='T'){
      if(ro<0 or v1[j]>0){
      ans=ans+max(0-ro,v1[j]);
      }
   }
  
   cout<<ans<<endl;
}
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 312 KB Output is correct
2 Correct 10 ms 340 KB Output is correct
3 Correct 10 ms 212 KB Output is correct
4 Correct 9 ms 340 KB Output is correct
5 Correct 6 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 312 KB Output is correct
2 Correct 10 ms 340 KB Output is correct
3 Correct 10 ms 212 KB Output is correct
4 Correct 9 ms 340 KB Output is correct
5 Correct 6 ms 212 KB Output is correct
6 Execution timed out 3065 ms 1368 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 312 KB Output is correct
2 Correct 10 ms 340 KB Output is correct
3 Correct 10 ms 212 KB Output is correct
4 Correct 9 ms 340 KB Output is correct
5 Correct 6 ms 212 KB Output is correct
6 Execution timed out 3065 ms 1368 KB Time limit exceeded
7 Halted 0 ms 0 KB -