Submission #93702

# Submission time Handle Problem Language Result Execution time Memory
93702 2019-01-10T19:03:21 Z rkocharyan Election (BOI18_election) C++14
28 / 100
3000 ms 2044 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;
    for(; q; --q) {
        int l, r;
        cin >> l >> r;
        --l, --r;
        vector <int> t(n, 1);
        int balance = 0;
        int ans = 0;
        for(int i = l; i <= r; i++) {
            balance += s[i] == 'C' ? 1 : -1;
            if(!t[i]) balance++;
            if(balance < 0) {
                balance = 0;
                ans += t[i];
                t[i] = 0;
            }
        }
        balance = 0;
        for(int i = r; i >= l; i--) {
            balance += s[i] == 'C' ? 1 : -1;
            if(!t[i]) balance++;
            if(balance < 0) {
                balance = 0;
                ans += t[i];
                t[i] = 0;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 8 ms 376 KB Output is correct
5 Correct 7 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 8 ms 376 KB Output is correct
5 Correct 7 ms 380 KB Output is correct
6 Execution timed out 3022 ms 2044 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 8 ms 376 KB Output is correct
5 Correct 7 ms 380 KB Output is correct
6 Execution timed out 3022 ms 2044 KB Time limit exceeded
7 Halted 0 ms 0 KB -