Submission #434113

# Submission time Handle Problem Language Result Execution time Memory
434113 2021-06-20T15:11:19 Z AmineTrabelsi Election (BOI18_election) C++14
28 / 100
3000 ms 1008 KB
#include "bits/stdc++.h"
using namespace std;
// Hi 

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--;
        vector<bool> vis(n+1,0);
        int cnt = 0;
        int ans = 0;
        for(int i=l;i<=r;i++){
            cnt += (s[i] == 'C' ? 1 : -1);
            //cout << i<<" "<<cnt<< '\n';
            if(cnt < 0){
                vis[i] = 1;
                cnt++;
                ans++;
            }
        }
        cnt = 0;
        for(int i=r;i>=l;i--){
            if(vis[i])continue;
            cnt += (s[i] == 'C' ? 1 : -1);
            //cout << i<<" "<<cnt<< '\n';
            if(cnt < 0){
                cnt++;
                ans++;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 332 KB Output is correct
2 Correct 7 ms 320 KB Output is correct
3 Correct 6 ms 332 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 332 KB Output is correct
2 Correct 7 ms 320 KB Output is correct
3 Correct 6 ms 332 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
6 Execution timed out 3067 ms 1008 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 332 KB Output is correct
2 Correct 7 ms 320 KB Output is correct
3 Correct 6 ms 332 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
6 Execution timed out 3067 ms 1008 KB Time limit exceeded
7 Halted 0 ms 0 KB -