# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
155386 | 2019-09-27T17:44:40 Z | TadijaSebez | Toilets (JOI16_toilets) | C++11 | 39 ms | 4844 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int N=200050; char s[N]; int main() { ll n; int m; scanf("%lld %i",&n,&m); vector<pair<ll,pair<ll,ll>>> v; ll all=0; for(int i=1;i<=m;i++) { scanf("%s",s+1); int len=strlen(s+1); ll k; scanf("%lld",&k); ll mx=0,balance=0; for(int j=len;j>=1;j--) { balance+=(s[j]=='F'?-1:1); mx=max(mx,balance); if(s[j]=='F') all-=k; else all+=k; } v.pb({k,{mx,balance}}); //printf("%lld %lld\n",mx,balance); } if(all>0) return 0*printf("-1\n"); ll sum=0,ans=0; while(v.size()) { ll k,mx,b; //tie(k,mx,b)=v.back(); k=v.back().first; mx=v.back().second.first; b=v.back().second.second; v.pop_back(); if(b>0) ans=max(ans,mx+sum+b*(k-1)); else ans=max(ans,mx+sum); sum+=k*b; } printf("%lld\n",max((ll)0,ans-1)); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 348 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 256 KB | Output is correct |
15 | Correct | 2 ms | 392 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 348 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 256 KB | Output is correct |
15 | Correct | 2 ms | 392 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 2 ms | 376 KB | Output is correct |
23 | Correct | 4 ms | 760 KB | Output is correct |
24 | Correct | 4 ms | 632 KB | Output is correct |
25 | Correct | 4 ms | 632 KB | Output is correct |
26 | Correct | 3 ms | 760 KB | Output is correct |
27 | Correct | 4 ms | 760 KB | Output is correct |
28 | Correct | 4 ms | 760 KB | Output is correct |
29 | Correct | 4 ms | 760 KB | Output is correct |
30 | Correct | 4 ms | 636 KB | Output is correct |
31 | Correct | 4 ms | 760 KB | Output is correct |
32 | Correct | 4 ms | 632 KB | Output is correct |
33 | Correct | 4 ms | 760 KB | Output is correct |
34 | Correct | 3 ms | 760 KB | Output is correct |
35 | Correct | 4 ms | 632 KB | Output is correct |
36 | Correct | 4 ms | 632 KB | Output is correct |
37 | Correct | 3 ms | 632 KB | Output is correct |
38 | Correct | 4 ms | 632 KB | Output is correct |
39 | Correct | 4 ms | 632 KB | Output is correct |
40 | Correct | 6 ms | 848 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 348 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 256 KB | Output is correct |
15 | Correct | 2 ms | 392 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 2 ms | 376 KB | Output is correct |
23 | Correct | 4 ms | 760 KB | Output is correct |
24 | Correct | 4 ms | 632 KB | Output is correct |
25 | Correct | 4 ms | 632 KB | Output is correct |
26 | Correct | 3 ms | 760 KB | Output is correct |
27 | Correct | 4 ms | 760 KB | Output is correct |
28 | Correct | 4 ms | 760 KB | Output is correct |
29 | Correct | 4 ms | 760 KB | Output is correct |
30 | Correct | 4 ms | 636 KB | Output is correct |
31 | Correct | 4 ms | 760 KB | Output is correct |
32 | Correct | 4 ms | 632 KB | Output is correct |
33 | Correct | 4 ms | 760 KB | Output is correct |
34 | Correct | 3 ms | 760 KB | Output is correct |
35 | Correct | 4 ms | 632 KB | Output is correct |
36 | Correct | 4 ms | 632 KB | Output is correct |
37 | Correct | 3 ms | 632 KB | Output is correct |
38 | Correct | 4 ms | 632 KB | Output is correct |
39 | Correct | 4 ms | 632 KB | Output is correct |
40 | Correct | 6 ms | 848 KB | Output is correct |
41 | Correct | 39 ms | 4844 KB | Output is correct |
42 | Correct | 38 ms | 4816 KB | Output is correct |
43 | Correct | 2 ms | 256 KB | Output is correct |
44 | Correct | 2 ms | 376 KB | Output is correct |
45 | Correct | 2 ms | 396 KB | Output is correct |
46 | Correct | 9 ms | 1208 KB | Output is correct |
47 | Correct | 5 ms | 632 KB | Output is correct |
48 | Correct | 4 ms | 504 KB | Output is correct |
49 | Correct | 4 ms | 632 KB | Output is correct |
50 | Correct | 3 ms | 632 KB | Output is correct |
51 | Correct | 9 ms | 1208 KB | Output is correct |
52 | Correct | 34 ms | 4456 KB | Output is correct |
53 | Correct | 33 ms | 4456 KB | Output is correct |
54 | Correct | 35 ms | 4460 KB | Output is correct |
55 | Correct | 4 ms | 504 KB | Output is correct |
56 | Correct | 3 ms | 504 KB | Output is correct |