Submission #237428

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

#pragma GCC optimize("O3")

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 13 ms 384 KB Output is correct
2 Correct 12 ms 384 KB Output is correct
3 Correct 11 ms 384 KB Output is correct
4 Correct 12 ms 384 KB Output is correct
5 Correct 9 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 384 KB Output is correct
2 Correct 12 ms 384 KB Output is correct
3 Correct 11 ms 384 KB Output is correct
4 Correct 12 ms 384 KB Output is correct
5 Correct 9 ms 384 KB Output is correct
6 Execution timed out 3078 ms 2124 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 384 KB Output is correct
2 Correct 12 ms 384 KB Output is correct
3 Correct 11 ms 384 KB Output is correct
4 Correct 12 ms 384 KB Output is correct
5 Correct 9 ms 384 KB Output is correct
6 Execution timed out 3078 ms 2124 KB Time limit exceeded
7 Halted 0 ms 0 KB -