# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
770175 | allllekssssa | Election (BOI18_election) | C++14 | 5 ms | 980 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<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxN = 3000;
string s;
int n, q;
int d[maxN];
int main() {
cin >> n;
cin >> s;
cin >> q;
while(q--) {
int l, r;
scanf("%d%d", &l, &r);
int cur = 0;
int mm = 0;
for (int i = l; i <= r; i++) {
if (s[i - 1] == 'T') ++cur; else cur--;
mm = max(mm, cur);
d[i] = mm;
}
cur = 0;
mm = 0;
for (int i = r; i>=l; i--) {
d[i]+=mm;
if (s[i - 1] == 'T') ++cur; else cur--;
mm = max(mm, cur);
}
int mx = 0;
for (int i = l; i<=r; i++) {
mx = max(mx, d[i]);
}
printf("%d\n", mx);
}
}
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... |