/* ************************************************************************** */
/* */
/* ::: ::: ::: */
/* Problem Number: 17709 :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: js9028 <boj.kr/u/js9028> +#+ +#+ +#+ */
/* +#+ +#+ +#+ */
/* https://boj.kr/17709 #+# #+# #+# */
/* Solved: 2024/09/12 19:48:56 by js9028 ### ### ##.kr */
/* */
/* ************************************************************************** */
#include <bits/stdc++.h>
using namespace std;
#define fastio (ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL))
typedef long long ll;
typedef long double lld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int MAXSIZE = 2000000;
const long long INF = 1e18 + 5;
const double EPSILON = 1e-14;
const ll DIV = 2000003;
const long double pi = 3.14159265358979323846264338327950288419716939937510L;
ll n, m;
string s[200055];
ll cnt[200055];
int main()
{
fastio;
cin >> n >> m;
for (int i = 0; i < m; i++)
{
cin >> s[i];
cin >> cnt[i];
}
ll glt = 0;
ll mxt = 0;
for (int i = m - 1; i >= 0; i--)
{
string &cs = s[i];
ll nt = 0;
ll mm = 0;
for (int j = cs.size() - 1; j >= 0; j--)
{
nt += (cs[j] == 'M' ? -1 : 1);
mxt = min(mxt, nt + glt);
}
nt = 0;
glt += nt * (cnt[i] - 1);
for (int j = cs.size() - 1; j >= 0; j--)
{
nt += (cs[j] == 'M' ? -1 : 1);
mxt = min(mxt, nt + glt);
}
glt += nt;
mxt = min(mxt, glt);
}
if (glt < 0)
{
cout << -1;
}
else
{
cout << max(0ll, -mxt - 1);
}
return 0;
}
Compilation message
toilets.cpp: In function 'int main()':
toilets.cpp:45:12: warning: unused variable 'mm' [-Wunused-variable]
45 | ll mm = 0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
3 ms |
6492 KB |
Output is correct |
6 |
Correct |
3 ms |
6488 KB |
Output is correct |
7 |
Correct |
3 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
6492 KB |
Output is correct |
12 |
Correct |
2 ms |
6492 KB |
Output is correct |
13 |
Correct |
3 ms |
6492 KB |
Output is correct |
14 |
Correct |
3 ms |
6492 KB |
Output is correct |
15 |
Correct |
3 ms |
6488 KB |
Output is correct |
16 |
Correct |
3 ms |
6492 KB |
Output is correct |
17 |
Correct |
3 ms |
6492 KB |
Output is correct |
18 |
Correct |
3 ms |
6492 KB |
Output is correct |
19 |
Correct |
3 ms |
6540 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
3 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
3 ms |
6492 KB |
Output is correct |
6 |
Correct |
3 ms |
6488 KB |
Output is correct |
7 |
Correct |
3 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
6492 KB |
Output is correct |
12 |
Correct |
2 ms |
6492 KB |
Output is correct |
13 |
Correct |
3 ms |
6492 KB |
Output is correct |
14 |
Correct |
3 ms |
6492 KB |
Output is correct |
15 |
Correct |
3 ms |
6488 KB |
Output is correct |
16 |
Correct |
3 ms |
6492 KB |
Output is correct |
17 |
Correct |
3 ms |
6492 KB |
Output is correct |
18 |
Correct |
3 ms |
6492 KB |
Output is correct |
19 |
Correct |
3 ms |
6540 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
3 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6492 KB |
Output is correct |
23 |
Correct |
5 ms |
7004 KB |
Output is correct |
24 |
Correct |
4 ms |
7004 KB |
Output is correct |
25 |
Correct |
3 ms |
7004 KB |
Output is correct |
26 |
Correct |
3 ms |
7004 KB |
Output is correct |
27 |
Correct |
3 ms |
7004 KB |
Output is correct |
28 |
Correct |
3 ms |
7004 KB |
Output is correct |
29 |
Correct |
3 ms |
7004 KB |
Output is correct |
30 |
Correct |
3 ms |
7004 KB |
Output is correct |
31 |
Correct |
3 ms |
7004 KB |
Output is correct |
32 |
Correct |
3 ms |
7004 KB |
Output is correct |
33 |
Correct |
3 ms |
7004 KB |
Output is correct |
34 |
Correct |
3 ms |
7004 KB |
Output is correct |
35 |
Correct |
3 ms |
7004 KB |
Output is correct |
36 |
Correct |
3 ms |
7004 KB |
Output is correct |
37 |
Correct |
3 ms |
7004 KB |
Output is correct |
38 |
Correct |
4 ms |
7004 KB |
Output is correct |
39 |
Correct |
3 ms |
7004 KB |
Output is correct |
40 |
Correct |
3 ms |
7004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
3 ms |
6492 KB |
Output is correct |
6 |
Correct |
3 ms |
6488 KB |
Output is correct |
7 |
Correct |
3 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
6492 KB |
Output is correct |
12 |
Correct |
2 ms |
6492 KB |
Output is correct |
13 |
Correct |
3 ms |
6492 KB |
Output is correct |
14 |
Correct |
3 ms |
6492 KB |
Output is correct |
15 |
Correct |
3 ms |
6488 KB |
Output is correct |
16 |
Correct |
3 ms |
6492 KB |
Output is correct |
17 |
Correct |
3 ms |
6492 KB |
Output is correct |
18 |
Correct |
3 ms |
6492 KB |
Output is correct |
19 |
Correct |
3 ms |
6540 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
3 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6492 KB |
Output is correct |
23 |
Correct |
5 ms |
7004 KB |
Output is correct |
24 |
Correct |
4 ms |
7004 KB |
Output is correct |
25 |
Correct |
3 ms |
7004 KB |
Output is correct |
26 |
Correct |
3 ms |
7004 KB |
Output is correct |
27 |
Correct |
3 ms |
7004 KB |
Output is correct |
28 |
Correct |
3 ms |
7004 KB |
Output is correct |
29 |
Correct |
3 ms |
7004 KB |
Output is correct |
30 |
Correct |
3 ms |
7004 KB |
Output is correct |
31 |
Correct |
3 ms |
7004 KB |
Output is correct |
32 |
Correct |
3 ms |
7004 KB |
Output is correct |
33 |
Correct |
3 ms |
7004 KB |
Output is correct |
34 |
Correct |
3 ms |
7004 KB |
Output is correct |
35 |
Correct |
3 ms |
7004 KB |
Output is correct |
36 |
Correct |
3 ms |
7004 KB |
Output is correct |
37 |
Correct |
3 ms |
7004 KB |
Output is correct |
38 |
Correct |
4 ms |
7004 KB |
Output is correct |
39 |
Correct |
3 ms |
7004 KB |
Output is correct |
40 |
Correct |
3 ms |
7004 KB |
Output is correct |
41 |
Incorrect |
15 ms |
7260 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |