# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
53853 | ainta | Toilets (JOI16_toilets) | C++17 | 41 ms | 5688 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<algorithm>
#include<string>
using namespace std;
long long L;
int n;
char p[201000];
struct point {
string T;
int s, M;
long long K;
}w[101000];
long long ss;
int main() {
int i, j;
scanf("%lld%d", &L, &n);
long long M = 0;
for (i = 1; i <= n; i++) {
scanf("%s", p);
scanf("%lld", &w[i].K);
w[i].s = w[i].M = 0;
for (j = 0; p[j]; j++) {
if (p[j] == 'F')w[i].s++;
else w[i].s--;
w[i].M = max(w[i].M, w[i].s);
}
M = max(M, max(ss + w[i].M, ss + w[i].s*(w[i].K - 1) + w[i].M));
ss += w[i].s*w[i].K;
}
if (ss < 0) {
puts("-1");
return 0;
}
if (M < ss + 1)puts("0");
else printf("%lld\n", M - (ss + 1));
}
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... |