Submission #157041

# Submission time Handle Problem Language Result Execution time Memory
157041 2019-10-09T08:44:15 Z maruii Toilets (JOI16_toilets) C++14
36 / 100
99 ms 796 KB
#include <bits/stdc++.h>
using namespace std;

char S[200005];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int N, M; cin >> N >> M;
	long long y = 0, mny = 0;
	for (int i = 0; i < M; ++i) {
		int K;
		cin >> S + 1 >> K;
		long long sum = 0, mnSum = 0;
		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 376 KB Output is correct
8 Correct 2 ms 424 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 380 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 376 KB Output is correct
8 Correct 2 ms 424 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 380 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 4 ms 760 KB Output is correct
24 Correct 4 ms 760 KB Output is correct
25 Correct 4 ms 764 KB Output is correct
26 Correct 3 ms 760 KB Output is correct
27 Correct 3 ms 736 KB Output is correct
28 Correct 4 ms 760 KB Output is correct
29 Correct 4 ms 760 KB Output is correct
30 Correct 3 ms 688 KB Output is correct
31 Correct 4 ms 760 KB Output is correct
32 Correct 4 ms 760 KB Output is correct
33 Correct 3 ms 760 KB Output is correct
34 Correct 3 ms 760 KB Output is correct
35 Correct 4 ms 796 KB Output is correct
36 Correct 4 ms 760 KB Output is correct
37 Correct 3 ms 764 KB Output is correct
38 Correct 4 ms 764 KB Output is correct
39 Correct 4 ms 760 KB Output is correct
40 Correct 3 ms 760 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 376 KB Output is correct
8 Correct 2 ms 424 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 380 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 4 ms 760 KB Output is correct
24 Correct 4 ms 760 KB Output is correct
25 Correct 4 ms 764 KB Output is correct
26 Correct 3 ms 760 KB Output is correct
27 Correct 3 ms 736 KB Output is correct
28 Correct 4 ms 760 KB Output is correct
29 Correct 4 ms 760 KB Output is correct
30 Correct 3 ms 688 KB Output is correct
31 Correct 4 ms 760 KB Output is correct
32 Correct 4 ms 760 KB Output is correct
33 Correct 3 ms 760 KB Output is correct
34 Correct 3 ms 760 KB Output is correct
35 Correct 4 ms 796 KB Output is correct
36 Correct 4 ms 760 KB Output is correct
37 Correct 3 ms 764 KB Output is correct
38 Correct 4 ms 764 KB Output is correct
39 Correct 4 ms 760 KB Output is correct
40 Correct 3 ms 760 KB Output is correct
41 Incorrect 99 ms 392 KB Output isn't correct
42 Halted 0 ms 0 KB -