Submission #51770

# Submission time Handle Problem Language Result Execution time Memory
51770 2018-06-21T04:57:04 Z model_code Toilets (JOI16_toilets) C++17
100 / 100
43 ms 5764 KB
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>


int main()
{
	// speed up std::cin & std::cout
	std::ios::sync_with_stdio(false);

	long long N;
	int M;
	std::vector<std::string> S;
	std::vector<long long> K;

	std::cin >> N >> M;
	for(int i = 0; i < M; ++i) {
		std::string S_i;
		long long K_i;
		std::cin >> S_i >> K_i;
		S.push_back(S_i);
		K.push_back(K_i);
	}

	long long minimum = 0;
	long long global_count = 0;

	for(int section = M - 1; section >= 0; --section) {

		const std::string& S_i = S[section];
		const long long K_i = K[section];

		int local_count = 0, diff_minimum = 0;

		for(int index = S_i.size() - 1; index >= 0; --index) {
			const char c = S_i[index];
			local_count += (c == 'F' ? 1 : -1);
			diff_minimum = std::min(diff_minimum, local_count);
		}

		const long long candidate_first = global_count + diff_minimum;
		const long long candidate_last = global_count + (K_i - 1) * local_count
		                                 + diff_minimum;

		minimum = std::min(minimum, std::min(candidate_first, candidate_last));
		global_count += local_count * K_i;
	}

	long long answer;

	// global_count = |female| - |male|
	if(global_count < 0) {

		answer = -1;

	} else {

		if(minimum >= -1) {
			answer = 0;
		} else {
			answer = -(minimum + 1);
		}
	}

	std::cout << answer << std::endl;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 3 ms 720 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 740 KB Output is correct
19 Correct 2 ms 740 KB Output is correct
20 Correct 2 ms 740 KB Output is correct
21 Correct 2 ms 740 KB Output is correct
22 Correct 3 ms 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 3 ms 720 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 740 KB Output is correct
19 Correct 2 ms 740 KB Output is correct
20 Correct 2 ms 740 KB Output is correct
21 Correct 2 ms 740 KB Output is correct
22 Correct 3 ms 740 KB Output is correct
23 Correct 5 ms 1148 KB Output is correct
24 Correct 4 ms 1164 KB Output is correct
25 Correct 4 ms 1164 KB Output is correct
26 Correct 4 ms 1164 KB Output is correct
27 Correct 3 ms 1272 KB Output is correct
28 Correct 3 ms 1272 KB Output is correct
29 Correct 3 ms 1272 KB Output is correct
30 Correct 4 ms 1272 KB Output is correct
31 Correct 3 ms 1272 KB Output is correct
32 Correct 3 ms 1272 KB Output is correct
33 Correct 3 ms 1272 KB Output is correct
34 Correct 3 ms 1272 KB Output is correct
35 Correct 3 ms 1272 KB Output is correct
36 Correct 3 ms 1272 KB Output is correct
37 Correct 3 ms 1272 KB Output is correct
38 Correct 3 ms 1272 KB Output is correct
39 Correct 3 ms 1272 KB Output is correct
40 Correct 3 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 3 ms 720 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 740 KB Output is correct
19 Correct 2 ms 740 KB Output is correct
20 Correct 2 ms 740 KB Output is correct
21 Correct 2 ms 740 KB Output is correct
22 Correct 3 ms 740 KB Output is correct
23 Correct 5 ms 1148 KB Output is correct
24 Correct 4 ms 1164 KB Output is correct
25 Correct 4 ms 1164 KB Output is correct
26 Correct 4 ms 1164 KB Output is correct
27 Correct 3 ms 1272 KB Output is correct
28 Correct 3 ms 1272 KB Output is correct
29 Correct 3 ms 1272 KB Output is correct
30 Correct 4 ms 1272 KB Output is correct
31 Correct 3 ms 1272 KB Output is correct
32 Correct 3 ms 1272 KB Output is correct
33 Correct 3 ms 1272 KB Output is correct
34 Correct 3 ms 1272 KB Output is correct
35 Correct 3 ms 1272 KB Output is correct
36 Correct 3 ms 1272 KB Output is correct
37 Correct 3 ms 1272 KB Output is correct
38 Correct 3 ms 1272 KB Output is correct
39 Correct 3 ms 1272 KB Output is correct
40 Correct 3 ms 1272 KB Output is correct
41 Correct 35 ms 5676 KB Output is correct
42 Correct 35 ms 5676 KB Output is correct
43 Correct 3 ms 5676 KB Output is correct
44 Correct 2 ms 5676 KB Output is correct
45 Correct 2 ms 5676 KB Output is correct
46 Correct 9 ms 5676 KB Output is correct
47 Correct 4 ms 5676 KB Output is correct
48 Correct 3 ms 5676 KB Output is correct
49 Correct 4 ms 5676 KB Output is correct
50 Correct 3 ms 5676 KB Output is correct
51 Correct 7 ms 5676 KB Output is correct
52 Correct 30 ms 5764 KB Output is correct
53 Correct 43 ms 5764 KB Output is correct
54 Correct 30 ms 5764 KB Output is correct
55 Correct 3 ms 5764 KB Output is correct
56 Correct 4 ms 5764 KB Output is correct