Submission #157043

# Submission time Handle Problem Language Result Execution time Memory
157043 2019-10-09T08:51:59 Z maruii Toilets (JOI16_toilets) C++14
100 / 100
30 ms 1912 KB
#include <bits/stdc++.h>
using namespace std;

char S[200005];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	long long N; int M; cin >> N >> M;
	long long y = 0, mny = 0;
	for (int i = 0; i < M; ++i) {
		long long K, sum = 0, mnSum = 0;
		cin >> S + 1 >> K;
		for (int i = 1, t = 0; S[i]; ++i) {
			t++;
			if (S[i] != S[i + 1]) {
				sum += S[i] == 'M' ? t : -t;
				mnSum = min(mnSum, sum);
				t = 0;
			}
		}
		mny = min({mny, y + sum * (K - 1) + mnSum, y + mnSum});
		y += K * sum;
	}
	if (y > 0) printf("-1");
	else printf("%lld", max(0ll, y -mny - 1));
	return 0;
}

Compilation message

toilets.cpp: In function 'int main()':
toilets.cpp:12:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   cin >> S + 1 >> K;
          ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 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 380 KB Output is correct
8 Correct 2 ms 376 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 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 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 376 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 380 KB Output is correct
8 Correct 2 ms 376 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 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 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 3 ms 504 KB Output is correct
24 Correct 4 ms 504 KB Output is correct
25 Correct 4 ms 572 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 632 KB Output is correct
31 Correct 4 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 524 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 4 ms 504 KB Output is correct
36 Correct 4 ms 504 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 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 380 KB Output is correct
8 Correct 2 ms 376 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 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 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 3 ms 504 KB Output is correct
24 Correct 4 ms 504 KB Output is correct
25 Correct 4 ms 572 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 632 KB Output is correct
31 Correct 4 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 524 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 4 ms 504 KB Output is correct
36 Correct 4 ms 504 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 30 ms 1912 KB Output is correct
42 Correct 30 ms 1888 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 7 ms 760 KB Output is correct
47 Correct 4 ms 516 KB Output is correct
48 Correct 4 ms 504 KB Output is correct
49 Correct 3 ms 504 KB Output is correct
50 Correct 3 ms 504 KB Output is correct
51 Correct 7 ms 632 KB Output is correct
52 Correct 25 ms 1400 KB Output is correct
53 Correct 25 ms 1400 KB Output is correct
54 Correct 25 ms 1400 KB Output is correct
55 Correct 3 ms 504 KB Output is correct
56 Correct 3 ms 632 KB Output is correct