Submission #680513

# Submission time Handle Problem Language Result Execution time Memory
680513 2023-01-11T03:55:07 Z vjudge1 Election (BOI18_election) C++14
28 / 100
3000 ms 2124 KB
#include <bits/stdc++.h>
#define ll long long
#define st first
#define nd second
#define pii pair <ll, ll>
#define rep(i, n, m) for (ll i = (n); i <= (m); i ++)
#define rrep(i, n, m) for (ll i = (n); i >= (m); i --)
using namespace std;
const long long N = 1e6 + 5;
ll n, a[N], q;
bool del[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n;
    rep(i, 1, n) {
        char ch;
        cin >> ch;
        if (ch == 'T') a[i] = -1; else a[i] = 1;
    }

    cin >> q;
    while (q --) {
        int l, r;
        cin >> l >> r;
        int b = 0, ans = 0;
        rep(i, l, r) {
            b += a[i];
            if (b < 0) b ++, ans ++, del[i] = true;
        }
        b = 0;
        rrep(i, r, l) {
            if (!del[i]) {
                b += a[i];
                if (b < 0) b ++, ans ++;
            }
            del[i] = false;
        }

        cout << ans << '\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 2422 ms 2124 KB Output is correct
7 Execution timed out 3069 ms 1652 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 2422 ms 2124 KB Output is correct
7 Execution timed out 3069 ms 1652 KB Time limit exceeded
8 Halted 0 ms 0 KB -