# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
793107 | pasin30055 | Election (BOI18_election) | C++14 | 6 ms | 724 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <cstdlib>
#include <iostream>
#define MAXN 2005
using namespace std;
int n, q, l, r;
int a[MAXN], b[MAXN], c[MAXN], d[MAXN];
char s[MAXN];
int main() {
scanf("%d\n%s\n%d", &n, s, &q);
for (; q > 0; q --) {
scanf("%d %d", &l, &r);
a[l - 1] = 0;
b[r + 1] = 0;
c[l - 1] = 0;
d[r + 1] = 0;
int ans = 0;
for (int i = l ; i <= r ; i ++) {
a[i] = a[i - 1];
if (s[i - 1] == 'C') a[i]--;
else a[i]++;
c[i] = max(c[i - 1], a[i]);
}
for (int i = r ; i >= l; i --) {
b[i] = b[i + 1];
if (s[i - 1] == 'C') b[i]--;
else b[i]++;
d[i] = max(d[i + 1], b[i]);
ans = max(ans, d[i + 1] + c[i]);
}
printf("%d\n", ans);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |