# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
56005 | youngyojun | Toilets (JOI16_toilets) | C++11 | 44 ms | 2700 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 <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
char A[200005];
ll sum, mn;
ll M, X;
int main() {
scanf("%*lld%lld", &M);
for(; M--;) {
scanf(" %s%lld", A, &X);
ll ret = 0, h = 0;
for(int i = 0; A[i]; i++) {
ret += ('M' == A[i] ? 1 : -1);
upmin(h, ret);
}
upmin(mn, sum + min({h, h + ret*(X-1), ret*X}));
sum += ret*X;
}
mn -= sum;
if(0 < sum) puts("-1");
else if(-1 <= mn) puts("0");
else cout << (-mn-1) << endl;
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... |