답안 #55435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55435 2018-07-07T10:07:04 Z Diuven Toilets (JOI16_toilets) C++11
100 / 100
27 ms 908 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=200010, inf=2e9;

ll n, m;

void NOPE(){
    cout<<-1;
    exit(0);
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;

    ll mn=0, sum=0;

    char S[MX]={}; ll k;
    for(int i=1; i<=m; i++){
        cin>>(S+1)>>k;

        ll now=0, low=0;
        for(int i=1; S[i]!=0; i++){
            now+=(S[i]=='M' ? 1 : -1);
            low=min(low, now);
        }

        mn=min({mn, sum+low, sum+low+now*(k-1)});

        sum+=now*k;
    }

    if(sum>0) NOPE();
    if(sum==mn) cout<<0;
    else cout<<sum-1-mn;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 3 ms 688 KB Output is correct
4 Correct 2 ms 688 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 2 ms 764 KB Output is correct
7 Correct 2 ms 824 KB Output is correct
8 Correct 2 ms 824 KB Output is correct
9 Correct 3 ms 824 KB Output is correct
10 Correct 3 ms 824 KB Output is correct
11 Correct 3 ms 824 KB Output is correct
12 Correct 2 ms 824 KB Output is correct
13 Correct 2 ms 824 KB Output is correct
14 Correct 3 ms 824 KB Output is correct
15 Correct 3 ms 908 KB Output is correct
16 Correct 3 ms 908 KB Output is correct
17 Correct 2 ms 908 KB Output is correct
18 Correct 2 ms 908 KB Output is correct
19 Correct 3 ms 908 KB Output is correct
20 Correct 2 ms 908 KB Output is correct
21 Correct 2 ms 908 KB Output is correct
22 Correct 3 ms 908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 3 ms 688 KB Output is correct
4 Correct 2 ms 688 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 2 ms 764 KB Output is correct
7 Correct 2 ms 824 KB Output is correct
8 Correct 2 ms 824 KB Output is correct
9 Correct 3 ms 824 KB Output is correct
10 Correct 3 ms 824 KB Output is correct
11 Correct 3 ms 824 KB Output is correct
12 Correct 2 ms 824 KB Output is correct
13 Correct 2 ms 824 KB Output is correct
14 Correct 3 ms 824 KB Output is correct
15 Correct 3 ms 908 KB Output is correct
16 Correct 3 ms 908 KB Output is correct
17 Correct 2 ms 908 KB Output is correct
18 Correct 2 ms 908 KB Output is correct
19 Correct 3 ms 908 KB Output is correct
20 Correct 2 ms 908 KB Output is correct
21 Correct 2 ms 908 KB Output is correct
22 Correct 3 ms 908 KB Output is correct
23 Correct 3 ms 908 KB Output is correct
24 Correct 16 ms 908 KB Output is correct
25 Correct 3 ms 908 KB Output is correct
26 Correct 3 ms 908 KB Output is correct
27 Correct 3 ms 908 KB Output is correct
28 Correct 3 ms 908 KB Output is correct
29 Correct 3 ms 908 KB Output is correct
30 Correct 3 ms 908 KB Output is correct
31 Correct 2 ms 908 KB Output is correct
32 Correct 3 ms 908 KB Output is correct
33 Correct 3 ms 908 KB Output is correct
34 Correct 3 ms 908 KB Output is correct
35 Correct 2 ms 908 KB Output is correct
36 Correct 3 ms 908 KB Output is correct
37 Correct 3 ms 908 KB Output is correct
38 Correct 3 ms 908 KB Output is correct
39 Correct 2 ms 908 KB Output is correct
40 Correct 3 ms 908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 3 ms 688 KB Output is correct
4 Correct 2 ms 688 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 2 ms 764 KB Output is correct
7 Correct 2 ms 824 KB Output is correct
8 Correct 2 ms 824 KB Output is correct
9 Correct 3 ms 824 KB Output is correct
10 Correct 3 ms 824 KB Output is correct
11 Correct 3 ms 824 KB Output is correct
12 Correct 2 ms 824 KB Output is correct
13 Correct 2 ms 824 KB Output is correct
14 Correct 3 ms 824 KB Output is correct
15 Correct 3 ms 908 KB Output is correct
16 Correct 3 ms 908 KB Output is correct
17 Correct 2 ms 908 KB Output is correct
18 Correct 2 ms 908 KB Output is correct
19 Correct 3 ms 908 KB Output is correct
20 Correct 2 ms 908 KB Output is correct
21 Correct 2 ms 908 KB Output is correct
22 Correct 3 ms 908 KB Output is correct
23 Correct 3 ms 908 KB Output is correct
24 Correct 16 ms 908 KB Output is correct
25 Correct 3 ms 908 KB Output is correct
26 Correct 3 ms 908 KB Output is correct
27 Correct 3 ms 908 KB Output is correct
28 Correct 3 ms 908 KB Output is correct
29 Correct 3 ms 908 KB Output is correct
30 Correct 3 ms 908 KB Output is correct
31 Correct 2 ms 908 KB Output is correct
32 Correct 3 ms 908 KB Output is correct
33 Correct 3 ms 908 KB Output is correct
34 Correct 3 ms 908 KB Output is correct
35 Correct 2 ms 908 KB Output is correct
36 Correct 3 ms 908 KB Output is correct
37 Correct 3 ms 908 KB Output is correct
38 Correct 3 ms 908 KB Output is correct
39 Correct 2 ms 908 KB Output is correct
40 Correct 3 ms 908 KB Output is correct
41 Correct 27 ms 908 KB Output is correct
42 Correct 27 ms 908 KB Output is correct
43 Correct 2 ms 908 KB Output is correct
44 Correct 2 ms 908 KB Output is correct
45 Correct 2 ms 908 KB Output is correct
46 Correct 6 ms 908 KB Output is correct
47 Correct 3 ms 908 KB Output is correct
48 Correct 3 ms 908 KB Output is correct
49 Correct 3 ms 908 KB Output is correct
50 Correct 3 ms 908 KB Output is correct
51 Correct 6 ms 908 KB Output is correct
52 Correct 23 ms 908 KB Output is correct
53 Correct 22 ms 908 KB Output is correct
54 Correct 22 ms 908 KB Output is correct
55 Correct 3 ms 908 KB Output is correct
56 Correct 3 ms 908 KB Output is correct