답안 #1087249

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087249 2024-09-12T11:28:34 Z akim9905 Toilets (JOI16_toilets) C++17
100 / 100
18 ms 6924 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 1252 KB Output is correct
24 Correct 1 ms 996 KB Output is correct
25 Correct 1 ms 1120 KB Output is correct
26 Correct 1 ms 1020 KB Output is correct
27 Correct 1 ms 1000 KB Output is correct
28 Correct 1 ms 1000 KB Output is correct
29 Correct 1 ms 1000 KB Output is correct
30 Correct 1 ms 988 KB Output is correct
31 Correct 1 ms 1000 KB Output is correct
32 Correct 1 ms 1000 KB Output is correct
33 Correct 1 ms 1000 KB Output is correct
34 Correct 1 ms 1000 KB Output is correct
35 Correct 1 ms 1000 KB Output is correct
36 Correct 1 ms 1000 KB Output is correct
37 Correct 1 ms 1124 KB Output is correct
38 Correct 1 ms 1000 KB Output is correct
39 Correct 1 ms 1000 KB Output is correct
40 Correct 1 ms 1000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 1252 KB Output is correct
24 Correct 1 ms 996 KB Output is correct
25 Correct 1 ms 1120 KB Output is correct
26 Correct 1 ms 1020 KB Output is correct
27 Correct 1 ms 1000 KB Output is correct
28 Correct 1 ms 1000 KB Output is correct
29 Correct 1 ms 1000 KB Output is correct
30 Correct 1 ms 988 KB Output is correct
31 Correct 1 ms 1000 KB Output is correct
32 Correct 1 ms 1000 KB Output is correct
33 Correct 1 ms 1000 KB Output is correct
34 Correct 1 ms 1000 KB Output is correct
35 Correct 1 ms 1000 KB Output is correct
36 Correct 1 ms 1000 KB Output is correct
37 Correct 1 ms 1124 KB Output is correct
38 Correct 1 ms 1000 KB Output is correct
39 Correct 1 ms 1000 KB Output is correct
40 Correct 1 ms 1000 KB Output is correct
41 Correct 17 ms 6924 KB Output is correct
42 Correct 17 ms 6864 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 3 ms 1464 KB Output is correct
47 Correct 1 ms 860 KB Output is correct
48 Correct 1 ms 860 KB Output is correct
49 Correct 1 ms 860 KB Output is correct
50 Correct 1 ms 860 KB Output is correct
51 Correct 3 ms 1524 KB Output is correct
52 Correct 18 ms 6416 KB Output is correct
53 Correct 15 ms 6416 KB Output is correct
54 Correct 15 ms 6416 KB Output is correct
55 Correct 1 ms 860 KB Output is correct
56 Correct 1 ms 860 KB Output is correct