Submission #565572

# Submission time Handle Problem Language Result Execution time Memory
565572 2022-05-21T06:52:01 Z Majid Election (BOI18_election) C++17
28 / 100
3000 ms 2444 KB
#include<bits/stdc++.h>
using namespace std;
 
//Types
using ll = long long;
using db = double;
 
//Vectors
#define pb push_back
#define sz(vec) ((ll)vec.size())
#define all(vec) vec.begin(), vec.end()
 
//things
#define f first
#define s second
const int SMALLINF = 1e9 + 7;
const ll BIGINF = ((ll)1e18) + 7;
#define Speeed ios::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL);

void solve(){

    ll n, q;
    string s;
    cin>>n>>s>>q;
    
    while(q--){
        
        ll l, r, cntc = 0, cnte = 0, ans = 0;
        map<ll, bool> mark;
        
        cin>>l>>r;
        l--, r--;
        
        for(ll i = l; i <= r; i++){
            
            if(s[i]=='C')cntc++;
            else if(!mark[i])cnte++;
            
            if(cnte>cntc){
                
                if(!mark[i]){
                    
                cnte--;
                mark[i] = true;
                ans++;
                }
            }
        }
        
        cntc = 0, cnte = 0;
        
        for(ll i = r; i >= l; i--){
            
            if(s[i]=='C')cntc++;
            else if(!mark[i])cnte++;
            
            if(cnte>cntc){
                
                if(!mark[i]){
                    
                cnte--;
                mark[i] = true;
                ans++;
                }
            }
        }
        
        cout<<ans<<"\n";
    }
    
    
}


int main(){
	Speeed
	
    ll t=1;
    // cin>>t;
    
    while(t--){
        
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 76 ms 340 KB Output is correct
2 Correct 75 ms 368 KB Output is correct
3 Correct 57 ms 372 KB Output is correct
4 Correct 98 ms 396 KB Output is correct
5 Correct 70 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 340 KB Output is correct
2 Correct 75 ms 368 KB Output is correct
3 Correct 57 ms 372 KB Output is correct
4 Correct 98 ms 396 KB Output is correct
5 Correct 70 ms 364 KB Output is correct
6 Execution timed out 3077 ms 2444 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 76 ms 340 KB Output is correct
2 Correct 75 ms 368 KB Output is correct
3 Correct 57 ms 372 KB Output is correct
4 Correct 98 ms 396 KB Output is correct
5 Correct 70 ms 364 KB Output is correct
6 Execution timed out 3077 ms 2444 KB Time limit exceeded
7 Halted 0 ms 0 KB -