# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
693331 | rainboy | Toilets (JOI16_toilets) | C11 | 21 ms | 1800 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 <string.h>
#define N 200000
long long max(long long a, long long b){ return a > b ? a : b; }
int main() {
int m;
long long sum_, suf_;
scanf("%*d%d", &m);
sum_ = 0, suf_ = 0;
while (m--) {
static char cc[N + 1];
int n, i;
long long k, sum, suf;
scanf("%s%lld", cc, &k), n = strlen(cc);
sum = suf = 0;
for (i = 0; i < n; i++) {
sum += cc[i] == 'M' ? 1 : -1;
if ((suf += cc[i] == 'M' ? 1 : -1) < 0)
suf = 0;
}
sum_ += sum * k, suf_ = max(suf + sum * k, max(sum * (k - 1), 0) + suf);
}
printf("%lld\n", sum_ > 0 ? -1 : (suf_ == 0 ? 0 : suf_ - 1));
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... |