Submission #192203

# Submission time Handle Problem Language Result Execution time Memory
192203 2020-01-15T05:19:28 Z dndhk Toilets (JOI16_toilets) C++14
36 / 100
8 ms 1628 KB
#include <bits/stdc++.h>

#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX_N = 10000;

ll N;
int M;
string str[MAX_N+1];
ll num[MAX_N+1];
ll ans = 0;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin>>N>>M;
	for(int i=1; i<=M; i++){
		cin>>str[i];
		cin>>num[i];
	}
	ll sum = 0;
	for(int i=M; i>=1; i--){
		ll S = 0;
		for(int j=0; j<str[i].size(); j++){
			if(str[i][j]=='M')	S++;
			else	S--;
		}
		if(S>0){
			sum+=(num[i]-1LL)*S;
		}
		for(int j=str[i].size()-1; j>=0; j--){
			if(str[i][j]=='M') sum++;
			else{
				sum--;
				ans = max(ans, sum);
			}
		}
		if(S<=0){
			sum+=(num[i]-1LL)*S;
		}
	}
	if(sum>0)	cout<<-1;
	else	cout<<ans;
	return 0;
}

Compilation message

toilets.cpp: In function 'int main()':
toilets.cpp:30:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<str[i].size(); j++){
                ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 732 KB Output is correct
3 Correct 2 ms 732 KB Output is correct
4 Correct 1 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 6 ms 632 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 2 ms 688 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 3 ms 696 KB Output is correct
15 Correct 2 ms 632 KB Output is correct
16 Correct 3 ms 632 KB Output is correct
17 Correct 2 ms 728 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 5 ms 732 KB Output is correct
20 Correct 2 ms 632 KB Output is correct
21 Correct 2 ms 632 KB Output is correct
22 Correct 2 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 732 KB Output is correct
3 Correct 2 ms 732 KB Output is correct
4 Correct 1 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 6 ms 632 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 2 ms 688 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 3 ms 696 KB Output is correct
15 Correct 2 ms 632 KB Output is correct
16 Correct 3 ms 632 KB Output is correct
17 Correct 2 ms 728 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 5 ms 732 KB Output is correct
20 Correct 2 ms 632 KB Output is correct
21 Correct 2 ms 632 KB Output is correct
22 Correct 2 ms 632 KB Output is correct
23 Correct 2 ms 1156 KB Output is correct
24 Correct 6 ms 1400 KB Output is correct
25 Correct 8 ms 1400 KB Output is correct
26 Correct 4 ms 1368 KB Output is correct
27 Correct 3 ms 1156 KB Output is correct
28 Correct 6 ms 1484 KB Output is correct
29 Correct 5 ms 1284 KB Output is correct
30 Correct 5 ms 1400 KB Output is correct
31 Correct 6 ms 1400 KB Output is correct
32 Correct 6 ms 1384 KB Output is correct
33 Correct 4 ms 1400 KB Output is correct
34 Correct 4 ms 1404 KB Output is correct
35 Correct 6 ms 1352 KB Output is correct
36 Correct 6 ms 1284 KB Output is correct
37 Correct 4 ms 1284 KB Output is correct
38 Correct 6 ms 1376 KB Output is correct
39 Correct 5 ms 1156 KB Output is correct
40 Correct 5 ms 1212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 732 KB Output is correct
3 Correct 2 ms 732 KB Output is correct
4 Correct 1 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 6 ms 632 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 2 ms 688 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 3 ms 696 KB Output is correct
15 Correct 2 ms 632 KB Output is correct
16 Correct 3 ms 632 KB Output is correct
17 Correct 2 ms 728 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 5 ms 732 KB Output is correct
20 Correct 2 ms 632 KB Output is correct
21 Correct 2 ms 632 KB Output is correct
22 Correct 2 ms 632 KB Output is correct
23 Correct 2 ms 1156 KB Output is correct
24 Correct 6 ms 1400 KB Output is correct
25 Correct 8 ms 1400 KB Output is correct
26 Correct 4 ms 1368 KB Output is correct
27 Correct 3 ms 1156 KB Output is correct
28 Correct 6 ms 1484 KB Output is correct
29 Correct 5 ms 1284 KB Output is correct
30 Correct 5 ms 1400 KB Output is correct
31 Correct 6 ms 1400 KB Output is correct
32 Correct 6 ms 1384 KB Output is correct
33 Correct 4 ms 1400 KB Output is correct
34 Correct 4 ms 1404 KB Output is correct
35 Correct 6 ms 1352 KB Output is correct
36 Correct 6 ms 1284 KB Output is correct
37 Correct 4 ms 1284 KB Output is correct
38 Correct 6 ms 1376 KB Output is correct
39 Correct 5 ms 1156 KB Output is correct
40 Correct 5 ms 1212 KB Output is correct
41 Runtime error 7 ms 1628 KB Execution killed with signal 11 (could be triggered by violating memory limits)
42 Halted 0 ms 0 KB -