Submission #105715

#TimeUsernameProblemLanguageResultExecution timeMemory
105715Pro_ktmrToilets (JOI16_toilets)C++14
100 / 100
120 ms5852 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...