답안 #192210

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
192210 2020-01-15T05:20:49 Z dndhk Toilets (JOI16_toilets) C++14
100 / 100
35 ms 5948 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 = 100000;

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++){
                ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3448 KB Output is correct
2 Correct 5 ms 3448 KB Output is correct
3 Correct 5 ms 3448 KB Output is correct
4 Correct 7 ms 3448 KB Output is correct
5 Correct 6 ms 3452 KB Output is correct
6 Correct 6 ms 3448 KB Output is correct
7 Correct 5 ms 3448 KB Output is correct
8 Correct 10 ms 3452 KB Output is correct
9 Correct 8 ms 3492 KB Output is correct
10 Correct 5 ms 3448 KB Output is correct
11 Correct 5 ms 3508 KB Output is correct
12 Correct 5 ms 3448 KB Output is correct
13 Correct 5 ms 3448 KB Output is correct
14 Correct 5 ms 3552 KB Output is correct
15 Correct 5 ms 3420 KB Output is correct
16 Correct 5 ms 3548 KB Output is correct
17 Correct 5 ms 3448 KB Output is correct
18 Correct 5 ms 3448 KB Output is correct
19 Correct 5 ms 3548 KB Output is correct
20 Correct 5 ms 3448 KB Output is correct
21 Correct 4 ms 3552 KB Output is correct
22 Correct 4 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3448 KB Output is correct
2 Correct 5 ms 3448 KB Output is correct
3 Correct 5 ms 3448 KB Output is correct
4 Correct 7 ms 3448 KB Output is correct
5 Correct 6 ms 3452 KB Output is correct
6 Correct 6 ms 3448 KB Output is correct
7 Correct 5 ms 3448 KB Output is correct
8 Correct 10 ms 3452 KB Output is correct
9 Correct 8 ms 3492 KB Output is correct
10 Correct 5 ms 3448 KB Output is correct
11 Correct 5 ms 3508 KB Output is correct
12 Correct 5 ms 3448 KB Output is correct
13 Correct 5 ms 3448 KB Output is correct
14 Correct 5 ms 3552 KB Output is correct
15 Correct 5 ms 3420 KB Output is correct
16 Correct 5 ms 3548 KB Output is correct
17 Correct 5 ms 3448 KB Output is correct
18 Correct 5 ms 3448 KB Output is correct
19 Correct 5 ms 3548 KB Output is correct
20 Correct 5 ms 3448 KB Output is correct
21 Correct 4 ms 3552 KB Output is correct
22 Correct 4 ms 3448 KB Output is correct
23 Correct 7 ms 4060 KB Output is correct
24 Correct 8 ms 4060 KB Output is correct
25 Correct 8 ms 3972 KB Output is correct
26 Correct 7 ms 4060 KB Output is correct
27 Correct 6 ms 3972 KB Output is correct
28 Correct 8 ms 3972 KB Output is correct
29 Correct 8 ms 4072 KB Output is correct
30 Correct 8 ms 4040 KB Output is correct
31 Correct 8 ms 4016 KB Output is correct
32 Correct 8 ms 4088 KB Output is correct
33 Correct 7 ms 4060 KB Output is correct
34 Correct 7 ms 4060 KB Output is correct
35 Correct 8 ms 4060 KB Output is correct
36 Correct 8 ms 4048 KB Output is correct
37 Correct 6 ms 4060 KB Output is correct
38 Correct 8 ms 4060 KB Output is correct
39 Correct 7 ms 4064 KB Output is correct
40 Correct 9 ms 4072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3448 KB Output is correct
2 Correct 5 ms 3448 KB Output is correct
3 Correct 5 ms 3448 KB Output is correct
4 Correct 7 ms 3448 KB Output is correct
5 Correct 6 ms 3452 KB Output is correct
6 Correct 6 ms 3448 KB Output is correct
7 Correct 5 ms 3448 KB Output is correct
8 Correct 10 ms 3452 KB Output is correct
9 Correct 8 ms 3492 KB Output is correct
10 Correct 5 ms 3448 KB Output is correct
11 Correct 5 ms 3508 KB Output is correct
12 Correct 5 ms 3448 KB Output is correct
13 Correct 5 ms 3448 KB Output is correct
14 Correct 5 ms 3552 KB Output is correct
15 Correct 5 ms 3420 KB Output is correct
16 Correct 5 ms 3548 KB Output is correct
17 Correct 5 ms 3448 KB Output is correct
18 Correct 5 ms 3448 KB Output is correct
19 Correct 5 ms 3548 KB Output is correct
20 Correct 5 ms 3448 KB Output is correct
21 Correct 4 ms 3552 KB Output is correct
22 Correct 4 ms 3448 KB Output is correct
23 Correct 7 ms 4060 KB Output is correct
24 Correct 8 ms 4060 KB Output is correct
25 Correct 8 ms 3972 KB Output is correct
26 Correct 7 ms 4060 KB Output is correct
27 Correct 6 ms 3972 KB Output is correct
28 Correct 8 ms 3972 KB Output is correct
29 Correct 8 ms 4072 KB Output is correct
30 Correct 8 ms 4040 KB Output is correct
31 Correct 8 ms 4016 KB Output is correct
32 Correct 8 ms 4088 KB Output is correct
33 Correct 7 ms 4060 KB Output is correct
34 Correct 7 ms 4060 KB Output is correct
35 Correct 8 ms 4060 KB Output is correct
36 Correct 8 ms 4048 KB Output is correct
37 Correct 6 ms 4060 KB Output is correct
38 Correct 8 ms 4060 KB Output is correct
39 Correct 7 ms 4064 KB Output is correct
40 Correct 9 ms 4072 KB Output is correct
41 Correct 35 ms 5848 KB Output is correct
42 Correct 35 ms 5948 KB Output is correct
43 Correct 5 ms 3448 KB Output is correct
44 Correct 5 ms 3420 KB Output is correct
45 Correct 5 ms 3532 KB Output is correct
46 Correct 11 ms 4184 KB Output is correct
47 Correct 8 ms 3936 KB Output is correct
48 Correct 8 ms 3832 KB Output is correct
49 Correct 5 ms 3976 KB Output is correct
50 Correct 5 ms 3960 KB Output is correct
51 Correct 12 ms 4088 KB Output is correct
52 Correct 30 ms 5496 KB Output is correct
53 Correct 30 ms 5368 KB Output is correct
54 Correct 30 ms 5536 KB Output is correct
55 Correct 7 ms 3944 KB Output is correct
56 Correct 7 ms 4064 KB Output is correct