Submission #696632

# Submission time Handle Problem Language Result Execution time Memory
696632 2023-02-07T02:15:08 Z jhwest2 Toilets (JOI16_toilets) C++17
100 / 100
22 ms 5836 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 101010;

ll n, m, cnt[N]; string s[N];
int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    cin >> n >> m;
    ll var = 0;
    for (int i = 0; i < m; i++) {
        cin >> s[i] >> cnt[i];
        reverse(s[i].begin(), s[i].end());

        int v = 0;
        for (int j = 0; j < s[i].size(); j++) {
            if (s[i][j] == 'M')
                ++v;
            else
                --v;
        }
        var += 1ll * v * cnt[i];
    }
    if (var > 0)
        return !(cout << -1);

    ll T = 0, V = 0;
    for (int i = m - 1; i >= 0; i--) {
        ll t = 0, v = 0;
        for (int j = 0; j < s[i].size(); j++) {
            if (s[i][j] == 'M')
                ++t;
            else
                --t;
            
            v = max(v, t);
        }
        if (t >= 0) 
            V = max(V, T + (cnt[i] - 1) * t + v);
        else
            V = max(V, T + v);
        
        T += cnt[i] * t;
    }
    cout << max(0ll, V - 1);
}

Compilation message

toilets.cpp: In function 'int main()':
toilets.cpp:17:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         for (int j = 0; j < s[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~
toilets.cpp:31:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for (int j = 0; j < s[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 2 ms 3492 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 3 ms 3488 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Correct 2 ms 3496 KB Output is correct
8 Correct 2 ms 3540 KB Output is correct
9 Correct 2 ms 3412 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 2 ms 3412 KB Output is correct
12 Correct 2 ms 3492 KB Output is correct
13 Correct 2 ms 3412 KB Output is correct
14 Correct 2 ms 3440 KB Output is correct
15 Correct 2 ms 3412 KB Output is correct
16 Correct 2 ms 3412 KB Output is correct
17 Correct 2 ms 3496 KB Output is correct
18 Correct 2 ms 3496 KB Output is correct
19 Correct 2 ms 3412 KB Output is correct
20 Correct 2 ms 3412 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 2 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 2 ms 3492 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 3 ms 3488 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Correct 2 ms 3496 KB Output is correct
8 Correct 2 ms 3540 KB Output is correct
9 Correct 2 ms 3412 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 2 ms 3412 KB Output is correct
12 Correct 2 ms 3492 KB Output is correct
13 Correct 2 ms 3412 KB Output is correct
14 Correct 2 ms 3440 KB Output is correct
15 Correct 2 ms 3412 KB Output is correct
16 Correct 2 ms 3412 KB Output is correct
17 Correct 2 ms 3496 KB Output is correct
18 Correct 2 ms 3496 KB Output is correct
19 Correct 2 ms 3412 KB Output is correct
20 Correct 2 ms 3412 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 2 ms 3412 KB Output is correct
23 Correct 3 ms 4052 KB Output is correct
24 Correct 3 ms 4016 KB Output is correct
25 Correct 3 ms 4052 KB Output is correct
26 Correct 3 ms 4052 KB Output is correct
27 Correct 3 ms 4036 KB Output is correct
28 Correct 3 ms 4052 KB Output is correct
29 Correct 3 ms 4052 KB Output is correct
30 Correct 3 ms 4036 KB Output is correct
31 Correct 3 ms 4036 KB Output is correct
32 Correct 3 ms 4016 KB Output is correct
33 Correct 3 ms 4052 KB Output is correct
34 Correct 3 ms 4036 KB Output is correct
35 Correct 3 ms 4052 KB Output is correct
36 Correct 3 ms 4040 KB Output is correct
37 Correct 3 ms 4052 KB Output is correct
38 Correct 3 ms 4052 KB Output is correct
39 Correct 3 ms 4052 KB Output is correct
40 Correct 3 ms 4052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 2 ms 3492 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 3 ms 3488 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Correct 2 ms 3496 KB Output is correct
8 Correct 2 ms 3540 KB Output is correct
9 Correct 2 ms 3412 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 2 ms 3412 KB Output is correct
12 Correct 2 ms 3492 KB Output is correct
13 Correct 2 ms 3412 KB Output is correct
14 Correct 2 ms 3440 KB Output is correct
15 Correct 2 ms 3412 KB Output is correct
16 Correct 2 ms 3412 KB Output is correct
17 Correct 2 ms 3496 KB Output is correct
18 Correct 2 ms 3496 KB Output is correct
19 Correct 2 ms 3412 KB Output is correct
20 Correct 2 ms 3412 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 2 ms 3412 KB Output is correct
23 Correct 3 ms 4052 KB Output is correct
24 Correct 3 ms 4016 KB Output is correct
25 Correct 3 ms 4052 KB Output is correct
26 Correct 3 ms 4052 KB Output is correct
27 Correct 3 ms 4036 KB Output is correct
28 Correct 3 ms 4052 KB Output is correct
29 Correct 3 ms 4052 KB Output is correct
30 Correct 3 ms 4036 KB Output is correct
31 Correct 3 ms 4036 KB Output is correct
32 Correct 3 ms 4016 KB Output is correct
33 Correct 3 ms 4052 KB Output is correct
34 Correct 3 ms 4036 KB Output is correct
35 Correct 3 ms 4052 KB Output is correct
36 Correct 3 ms 4040 KB Output is correct
37 Correct 3 ms 4052 KB Output is correct
38 Correct 3 ms 4052 KB Output is correct
39 Correct 3 ms 4052 KB Output is correct
40 Correct 3 ms 4052 KB Output is correct
41 Correct 22 ms 5836 KB Output is correct
42 Correct 22 ms 5796 KB Output is correct
43 Correct 2 ms 3412 KB Output is correct
44 Correct 2 ms 3412 KB Output is correct
45 Correct 2 ms 3412 KB Output is correct
46 Correct 5 ms 4052 KB Output is correct
47 Correct 4 ms 3864 KB Output is correct
48 Correct 3 ms 3924 KB Output is correct
49 Correct 3 ms 3884 KB Output is correct
50 Correct 3 ms 3868 KB Output is correct
51 Correct 5 ms 4068 KB Output is correct
52 Correct 19 ms 5296 KB Output is correct
53 Correct 19 ms 5276 KB Output is correct
54 Correct 18 ms 5324 KB Output is correct
55 Correct 3 ms 3888 KB Output is correct
56 Correct 3 ms 3872 KB Output is correct