# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
381207 | patrikpavic2 | Toilets (JOI16_toilets) | C++17 | 26 ms | 516 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 <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 2e5 + 500;
ll n, P, S, cF;
int m, k;
char s[N];
int main(){
scanf("%lld%d", &n, &m);
for(;m--;){
ll PP = 0, SS = 0, cFF = 0, kol;
scanf("%s %lld", s, &kol); k = strlen(s);
for(int i = 0;i < k;i++){
SS += (s[i] == 'F' ? -1 : 1);
cFF += (s[i] == 'F');
PP = min(PP, SS);
}
cF += cFF * kol;
P = min(PP, S + PP + min(0LL, (kol - 1) * SS));
S += SS * kol;
}
if(cF < n)
printf("-1\n");
else
printf("%lld\n", max(0LL, (2LL * n - 2LL * cF - 1) - P));
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... |