Submission #343385

# Submission time Handle Problem Language Result Execution time Memory
343385 2021-01-03T20:34:16 Z ijxjdjd Election (BOI18_election) C++14
0 / 100
31 ms 364 KB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> s(N);
    for (int i = 0; i < N; i++) {
        char c;
        cin >> c;
        if (c == 'C') {
            s[i] = 1;
        }
        else {
            s[i] = -1;
        }
    }
    int Q;
    cin >> Q;
    while (Q-->0) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        unordered_set<int> touched;
        int cur = 0;
        for (int i = l; i <= r; i++) {
            cur += s[i];
            if (cur < 0) {
                cur = 0;
                touched.insert(i);
            }
        }
        for (int i = r; i >= l; i--) {
            if (!touched.count(i)) {
                cur += s[i];
                if (cur < 0) {
                    cur = 0;
                    touched.insert(i);
                }
            }
        }
//        for (auto i : touched) {
//            cerr << i << " ";
//        }
        cout << touched.size() << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -