Submission #237427

# Submission time Handle Problem Language Result Execution time Memory
237427 2020-06-06T14:50:41 Z Sorting Election (BOI18_election) C++14
28 / 100
3000 ms 3068 KB
#include <bits/stdc++.h>

using namespace std;

const int mx_N = 5e5 + 3;

int n, q;
string s;

int a[mx_N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> s;

    for(int i = 0; i < n; ++i)
        a[i + 1] = (s[i] == 'C') ? 1 : -1;

    cin >> q;
    for(int i = 0; i < q; ++i){
        int l, r;
        cin >> l >> r;

        vector<int> v;
        int sum = 0, answer = 0;
        for(int j = l; j <= r; ++j){
            if(!sum && a[j] == -1)
                answer++;
            else{
                sum += a[j];
                v.push_back(a[j]);
            }
        }

        reverse(v.begin(), v.end());

        sum = 0;
        for(int x: v){
            if(!sum && x == -1)
                answer++;
            else
                sum += x;
        }

        cout << answer << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 384 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 10 ms 384 KB Output is correct
4 Correct 11 ms 512 KB Output is correct
5 Correct 10 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 384 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 10 ms 384 KB Output is correct
4 Correct 11 ms 512 KB Output is correct
5 Correct 10 ms 512 KB Output is correct
6 Execution timed out 3079 ms 3068 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 384 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 10 ms 384 KB Output is correct
4 Correct 11 ms 512 KB Output is correct
5 Correct 10 ms 512 KB Output is correct
6 Execution timed out 3079 ms 3068 KB Time limit exceeded
7 Halted 0 ms 0 KB -