Submission #105715

# Submission time Handle Problem Language Result Execution time Memory
105715 2019-04-14T04:21:34 Z Pro_ktmr Toilets (JOI16_toilets) C++14
100 / 100
120 ms 5852 KB
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define MP(a,b) make_pair(a,b)
LL N,M;
string S[100000];
LL K[100000];
LL ans = 0;
int main(){
	cin >> N >> M;
	LL male2 = 0;
	for(int i=0; i<M; i++){
		cin >> S[i] >> K[i];
		for(int j=0; j<S[i].size(); j++){
			if(S[i][j] == 'M') male2 += K[i];
		}
		reverse(S[i].begin(), S[i].end());
	}
	reverse(S, S+M);
	reverse(K, K+M);
	if(male2 > N){
		cout << -1 << endl;
		return 0;
	}
	LL sumMale = 0;
	LL sum = 0;
	for(int i=0; i<M; i++){
		LL male = 0;
		for(LL j=0; j<S[i].size(); j++){
			if(S[i][j] == 'M'){
				ans = max(ans, 2*(male+sumMale) - (j+sum));
				male++;
			}
		}
		sumMale += male * (K[i] - 1);
		sum += (LL)S[i].size() * (K[i] - 1);

		male = 0;
		for(LL j=0; j<S[i].size(); j++){
			if(S[i][j] == 'M'){
				ans = max(ans, 2*(male+sumMale) - (j+sum));
				male++;
			}
		}
		sumMale += male;
		sum += (LL)S[i].size();
	}

	cout << ans << endl;

	return 0;
}

Compilation message

toilets.cpp: In function 'int main()':
toilets.cpp:14:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<S[i].size(); j++){
                ~^~~~~~~~~~~~
toilets.cpp:29:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(LL j=0; j<S[i].size(); j++){
               ~^~~~~~~~~~~~
toilets.cpp:39:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(LL j=0; j<S[i].size(); j++){
               ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3584 KB Output is correct
2 Correct 5 ms 3456 KB Output is correct
3 Correct 5 ms 3456 KB Output is correct
4 Correct 5 ms 3456 KB Output is correct
5 Correct 4 ms 3456 KB Output is correct
6 Correct 4 ms 3456 KB Output is correct
7 Correct 5 ms 3456 KB Output is correct
8 Correct 5 ms 3484 KB Output is correct
9 Correct 4 ms 3456 KB Output is correct
10 Correct 5 ms 3456 KB Output is correct
11 Correct 5 ms 3524 KB Output is correct
12 Correct 5 ms 3456 KB Output is correct
13 Correct 5 ms 3456 KB Output is correct
14 Correct 5 ms 3456 KB Output is correct
15 Correct 5 ms 3456 KB Output is correct
16 Correct 6 ms 3456 KB Output is correct
17 Correct 6 ms 3456 KB Output is correct
18 Correct 6 ms 3456 KB Output is correct
19 Correct 6 ms 3456 KB Output is correct
20 Correct 4 ms 3456 KB Output is correct
21 Correct 4 ms 3456 KB Output is correct
22 Correct 4 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3584 KB Output is correct
2 Correct 5 ms 3456 KB Output is correct
3 Correct 5 ms 3456 KB Output is correct
4 Correct 5 ms 3456 KB Output is correct
5 Correct 4 ms 3456 KB Output is correct
6 Correct 4 ms 3456 KB Output is correct
7 Correct 5 ms 3456 KB Output is correct
8 Correct 5 ms 3484 KB Output is correct
9 Correct 4 ms 3456 KB Output is correct
10 Correct 5 ms 3456 KB Output is correct
11 Correct 5 ms 3524 KB Output is correct
12 Correct 5 ms 3456 KB Output is correct
13 Correct 5 ms 3456 KB Output is correct
14 Correct 5 ms 3456 KB Output is correct
15 Correct 5 ms 3456 KB Output is correct
16 Correct 6 ms 3456 KB Output is correct
17 Correct 6 ms 3456 KB Output is correct
18 Correct 6 ms 3456 KB Output is correct
19 Correct 6 ms 3456 KB Output is correct
20 Correct 4 ms 3456 KB Output is correct
21 Correct 4 ms 3456 KB Output is correct
22 Correct 4 ms 3456 KB Output is correct
23 Correct 14 ms 3984 KB Output is correct
24 Correct 14 ms 4096 KB Output is correct
25 Correct 14 ms 4068 KB Output is correct
26 Correct 12 ms 3984 KB Output is correct
27 Correct 11 ms 3984 KB Output is correct
28 Correct 15 ms 3984 KB Output is correct
29 Correct 14 ms 4032 KB Output is correct
30 Correct 16 ms 3984 KB Output is correct
31 Correct 16 ms 3984 KB Output is correct
32 Correct 15 ms 4004 KB Output is correct
33 Correct 12 ms 4096 KB Output is correct
34 Correct 17 ms 4068 KB Output is correct
35 Correct 14 ms 4028 KB Output is correct
36 Correct 20 ms 3984 KB Output is correct
37 Correct 14 ms 3984 KB Output is correct
38 Correct 13 ms 3984 KB Output is correct
39 Correct 18 ms 4012 KB Output is correct
40 Correct 15 ms 4096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3584 KB Output is correct
2 Correct 5 ms 3456 KB Output is correct
3 Correct 5 ms 3456 KB Output is correct
4 Correct 5 ms 3456 KB Output is correct
5 Correct 4 ms 3456 KB Output is correct
6 Correct 4 ms 3456 KB Output is correct
7 Correct 5 ms 3456 KB Output is correct
8 Correct 5 ms 3484 KB Output is correct
9 Correct 4 ms 3456 KB Output is correct
10 Correct 5 ms 3456 KB Output is correct
11 Correct 5 ms 3524 KB Output is correct
12 Correct 5 ms 3456 KB Output is correct
13 Correct 5 ms 3456 KB Output is correct
14 Correct 5 ms 3456 KB Output is correct
15 Correct 5 ms 3456 KB Output is correct
16 Correct 6 ms 3456 KB Output is correct
17 Correct 6 ms 3456 KB Output is correct
18 Correct 6 ms 3456 KB Output is correct
19 Correct 6 ms 3456 KB Output is correct
20 Correct 4 ms 3456 KB Output is correct
21 Correct 4 ms 3456 KB Output is correct
22 Correct 4 ms 3456 KB Output is correct
23 Correct 14 ms 3984 KB Output is correct
24 Correct 14 ms 4096 KB Output is correct
25 Correct 14 ms 4068 KB Output is correct
26 Correct 12 ms 3984 KB Output is correct
27 Correct 11 ms 3984 KB Output is correct
28 Correct 15 ms 3984 KB Output is correct
29 Correct 14 ms 4032 KB Output is correct
30 Correct 16 ms 3984 KB Output is correct
31 Correct 16 ms 3984 KB Output is correct
32 Correct 15 ms 4004 KB Output is correct
33 Correct 12 ms 4096 KB Output is correct
34 Correct 17 ms 4068 KB Output is correct
35 Correct 14 ms 4028 KB Output is correct
36 Correct 20 ms 3984 KB Output is correct
37 Correct 14 ms 3984 KB Output is correct
38 Correct 13 ms 3984 KB Output is correct
39 Correct 18 ms 4012 KB Output is correct
40 Correct 15 ms 4096 KB Output is correct
41 Correct 120 ms 5828 KB Output is correct
42 Correct 99 ms 5852 KB Output is correct
43 Correct 5 ms 3456 KB Output is correct
44 Correct 6 ms 3456 KB Output is correct
45 Correct 6 ms 3456 KB Output is correct
46 Correct 33 ms 4344 KB Output is correct
47 Correct 19 ms 3968 KB Output is correct
48 Correct 15 ms 3968 KB Output is correct
49 Correct 16 ms 3968 KB Output is correct
50 Correct 15 ms 3968 KB Output is correct
51 Correct 24 ms 4216 KB Output is correct
52 Correct 83 ms 5332 KB Output is correct
53 Correct 76 ms 5276 KB Output is correct
54 Correct 67 ms 5368 KB Output is correct
55 Correct 14 ms 3968 KB Output is correct
56 Correct 15 ms 3968 KB Output is correct