#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(NULL)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v) (v).begin(), (v).end()
#define pre(a) cout<<fixed; cout.precision(a)
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
ll n, m;
string s[100010];
ll k[100010];
ll dp[400010];
vector<pll> v;
int main() {
fast;
cin >> n;
cin >> m;
for(int i=1; i<=m; i++) {
cin >> s[i] >> k[i];
reverse(all(s[i]));
ll mx = -INF * 2;
for(int j=0; j<s[i].size(); j++) {
dp[j+1] = dp[j];
if(s[i][j] == 'F') dp[j+1]--;
else dp[j+1]++;
if(s[i][j] == 'F') mx = max(mx, dp[j+1]);
}
v.eb(max(mx, mx + (k[i]-1) * dp[s[i].size()]), dp[s[i].size()] * k[i]);
}
reverse(all(v));
ll ans = 0;
ll cur = 0;
for(auto i : v) {
ans = max(ans, i.fi + cur);
//cout << ans << " " << cur << endl;
cur += i.se;
}
if(cur > 0) cout << -1;
else cout << ans;
}
Compilation message
toilets.cpp: In function 'int main()':
toilets.cpp:39:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<s[i].size(); j++) {
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3456 KB |
Output is correct |
2 |
Correct |
3 ms |
3456 KB |
Output is correct |
3 |
Correct |
3 ms |
3456 KB |
Output is correct |
4 |
Correct |
3 ms |
3456 KB |
Output is correct |
5 |
Correct |
2 ms |
3456 KB |
Output is correct |
6 |
Correct |
2 ms |
3456 KB |
Output is correct |
7 |
Correct |
2 ms |
3456 KB |
Output is correct |
8 |
Correct |
3 ms |
3456 KB |
Output is correct |
9 |
Correct |
2 ms |
3456 KB |
Output is correct |
10 |
Correct |
2 ms |
3456 KB |
Output is correct |
11 |
Correct |
2 ms |
3456 KB |
Output is correct |
12 |
Correct |
2 ms |
3456 KB |
Output is correct |
13 |
Correct |
2 ms |
3456 KB |
Output is correct |
14 |
Correct |
2 ms |
3456 KB |
Output is correct |
15 |
Correct |
2 ms |
3456 KB |
Output is correct |
16 |
Correct |
2 ms |
3456 KB |
Output is correct |
17 |
Correct |
2 ms |
3456 KB |
Output is correct |
18 |
Correct |
2 ms |
3456 KB |
Output is correct |
19 |
Correct |
2 ms |
3456 KB |
Output is correct |
20 |
Correct |
2 ms |
3456 KB |
Output is correct |
21 |
Correct |
2 ms |
3456 KB |
Output is correct |
22 |
Correct |
2 ms |
3456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3456 KB |
Output is correct |
2 |
Correct |
3 ms |
3456 KB |
Output is correct |
3 |
Correct |
3 ms |
3456 KB |
Output is correct |
4 |
Correct |
3 ms |
3456 KB |
Output is correct |
5 |
Correct |
2 ms |
3456 KB |
Output is correct |
6 |
Correct |
2 ms |
3456 KB |
Output is correct |
7 |
Correct |
2 ms |
3456 KB |
Output is correct |
8 |
Correct |
3 ms |
3456 KB |
Output is correct |
9 |
Correct |
2 ms |
3456 KB |
Output is correct |
10 |
Correct |
2 ms |
3456 KB |
Output is correct |
11 |
Correct |
2 ms |
3456 KB |
Output is correct |
12 |
Correct |
2 ms |
3456 KB |
Output is correct |
13 |
Correct |
2 ms |
3456 KB |
Output is correct |
14 |
Correct |
2 ms |
3456 KB |
Output is correct |
15 |
Correct |
2 ms |
3456 KB |
Output is correct |
16 |
Correct |
2 ms |
3456 KB |
Output is correct |
17 |
Correct |
2 ms |
3456 KB |
Output is correct |
18 |
Correct |
2 ms |
3456 KB |
Output is correct |
19 |
Correct |
2 ms |
3456 KB |
Output is correct |
20 |
Correct |
2 ms |
3456 KB |
Output is correct |
21 |
Correct |
2 ms |
3456 KB |
Output is correct |
22 |
Correct |
2 ms |
3456 KB |
Output is correct |
23 |
Correct |
5 ms |
5388 KB |
Output is correct |
24 |
Correct |
5 ms |
5388 KB |
Output is correct |
25 |
Correct |
5 ms |
5388 KB |
Output is correct |
26 |
Correct |
4 ms |
5388 KB |
Output is correct |
27 |
Correct |
4 ms |
5388 KB |
Output is correct |
28 |
Correct |
5 ms |
5388 KB |
Output is correct |
29 |
Correct |
5 ms |
5388 KB |
Output is correct |
30 |
Correct |
4 ms |
5388 KB |
Output is correct |
31 |
Correct |
4 ms |
5388 KB |
Output is correct |
32 |
Correct |
5 ms |
5388 KB |
Output is correct |
33 |
Correct |
6 ms |
5388 KB |
Output is correct |
34 |
Correct |
4 ms |
5388 KB |
Output is correct |
35 |
Correct |
7 ms |
5388 KB |
Output is correct |
36 |
Correct |
5 ms |
5388 KB |
Output is correct |
37 |
Correct |
4 ms |
5388 KB |
Output is correct |
38 |
Correct |
6 ms |
5388 KB |
Output is correct |
39 |
Correct |
4 ms |
5388 KB |
Output is correct |
40 |
Correct |
6 ms |
5388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3456 KB |
Output is correct |
2 |
Correct |
3 ms |
3456 KB |
Output is correct |
3 |
Correct |
3 ms |
3456 KB |
Output is correct |
4 |
Correct |
3 ms |
3456 KB |
Output is correct |
5 |
Correct |
2 ms |
3456 KB |
Output is correct |
6 |
Correct |
2 ms |
3456 KB |
Output is correct |
7 |
Correct |
2 ms |
3456 KB |
Output is correct |
8 |
Correct |
3 ms |
3456 KB |
Output is correct |
9 |
Correct |
2 ms |
3456 KB |
Output is correct |
10 |
Correct |
2 ms |
3456 KB |
Output is correct |
11 |
Correct |
2 ms |
3456 KB |
Output is correct |
12 |
Correct |
2 ms |
3456 KB |
Output is correct |
13 |
Correct |
2 ms |
3456 KB |
Output is correct |
14 |
Correct |
2 ms |
3456 KB |
Output is correct |
15 |
Correct |
2 ms |
3456 KB |
Output is correct |
16 |
Correct |
2 ms |
3456 KB |
Output is correct |
17 |
Correct |
2 ms |
3456 KB |
Output is correct |
18 |
Correct |
2 ms |
3456 KB |
Output is correct |
19 |
Correct |
2 ms |
3456 KB |
Output is correct |
20 |
Correct |
2 ms |
3456 KB |
Output is correct |
21 |
Correct |
2 ms |
3456 KB |
Output is correct |
22 |
Correct |
2 ms |
3456 KB |
Output is correct |
23 |
Correct |
5 ms |
5388 KB |
Output is correct |
24 |
Correct |
5 ms |
5388 KB |
Output is correct |
25 |
Correct |
5 ms |
5388 KB |
Output is correct |
26 |
Correct |
4 ms |
5388 KB |
Output is correct |
27 |
Correct |
4 ms |
5388 KB |
Output is correct |
28 |
Correct |
5 ms |
5388 KB |
Output is correct |
29 |
Correct |
5 ms |
5388 KB |
Output is correct |
30 |
Correct |
4 ms |
5388 KB |
Output is correct |
31 |
Correct |
4 ms |
5388 KB |
Output is correct |
32 |
Correct |
5 ms |
5388 KB |
Output is correct |
33 |
Correct |
6 ms |
5388 KB |
Output is correct |
34 |
Correct |
4 ms |
5388 KB |
Output is correct |
35 |
Correct |
7 ms |
5388 KB |
Output is correct |
36 |
Correct |
5 ms |
5388 KB |
Output is correct |
37 |
Correct |
4 ms |
5388 KB |
Output is correct |
38 |
Correct |
6 ms |
5388 KB |
Output is correct |
39 |
Correct |
4 ms |
5388 KB |
Output is correct |
40 |
Correct |
6 ms |
5388 KB |
Output is correct |
41 |
Correct |
40 ms |
6184 KB |
Output is correct |
42 |
Correct |
43 ms |
6136 KB |
Output is correct |
43 |
Correct |
2 ms |
3456 KB |
Output is correct |
44 |
Correct |
2 ms |
3456 KB |
Output is correct |
45 |
Correct |
3 ms |
3456 KB |
Output is correct |
46 |
Correct |
7 ms |
3968 KB |
Output is correct |
47 |
Correct |
4 ms |
3712 KB |
Output is correct |
48 |
Correct |
4 ms |
3712 KB |
Output is correct |
49 |
Correct |
4 ms |
3712 KB |
Output is correct |
50 |
Correct |
4 ms |
3712 KB |
Output is correct |
51 |
Correct |
7 ms |
3968 KB |
Output is correct |
52 |
Correct |
25 ms |
6136 KB |
Output is correct |
53 |
Correct |
26 ms |
6136 KB |
Output is correct |
54 |
Correct |
25 ms |
6136 KB |
Output is correct |
55 |
Correct |
4 ms |
3712 KB |
Output is correct |
56 |
Correct |
3 ms |
3712 KB |
Output is correct |