Submission #414157

# Submission time Handle Problem Language Result Execution time Memory
414157 2021-05-30T07:13:02 Z shivensinha4 Election (BOI18_election) C++17
28 / 100
3000 ms 1780 KB
#include <bits/stdc++.h>
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
#define endl '\n'


int main() {
#ifdef mlocal
    freopen("test.in", "r", stdin);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    vi nums(n);
    for_(i, 0, n) {
        char c; cin >> c;
        nums[i] = c == 'C' ? 1 : -1;
    }

    auto solve = [&] (int l, int r) {
        int s = 0, mov = 0, mx = 0;
        for_(i, l, r+1) {
            s += nums[i];
            if (s < 0) {
                mov++;
                s = 0;
            }
            mx = max(mx, s);
        }
        return mov+mx-s;
    };

    int q; cin >> q;
    while (q--) {
        int l, r; cin >> l >> r;
        cout << solve(l-1, r-1) << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 4 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 5 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 4 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 5 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 1618 ms 1780 KB Output is correct
7 Execution timed out 3055 ms 1452 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 4 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 5 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 1618 ms 1780 KB Output is correct
7 Execution timed out 3055 ms 1452 KB Time limit exceeded
8 Halted 0 ms 0 KB -