Submission #1102032

# Submission time Handle Problem Language Result Execution time Memory
1102032 2024-10-17T10:27:44 Z woohyun_jng Toilets (JOI16_toilets) C++17
100 / 100
17 ms 8520 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int N, M, K, sm = 0, cur = 0, mn = 0, smn;
    vector<pair<string, int>> inp;
    string S;

    cin >> N >> M;
    while (M--) {
        cin >> S >> K;
        inp.push_back({S, K});
    }

    reverse(inp.begin(), inp.end());
    for (pair<string, int> i : inp) {
        S = i.first, K = i.second, cur = 0, smn = 0;

        for (int i = S.size() - 1; i >= 0; i--) {
            cur += (S[i] == 'F' ? 1 : -1);
            smn = min(smn, cur);
        }

        mn = min({mn, sm + smn, sm + cur * (K - 1) + smn});
        sm += cur * K;
    }

    if (sm < 0) cout << -1;
    else cout << max(0ll, -mn - 1);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 352 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 504 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 352 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 504 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 1248 KB Output is correct
24 Correct 2 ms 1264 KB Output is correct
25 Correct 2 ms 1248 KB Output is correct
26 Correct 2 ms 1416 KB Output is correct
27 Correct 2 ms 1248 KB Output is correct
28 Correct 2 ms 1248 KB Output is correct
29 Correct 2 ms 1248 KB Output is correct
30 Correct 2 ms 1248 KB Output is correct
31 Correct 2 ms 1248 KB Output is correct
32 Correct 2 ms 1248 KB Output is correct
33 Correct 2 ms 1248 KB Output is correct
34 Correct 2 ms 1248 KB Output is correct
35 Correct 2 ms 1248 KB Output is correct
36 Correct 2 ms 1412 KB Output is correct
37 Correct 2 ms 1248 KB Output is correct
38 Correct 2 ms 1248 KB Output is correct
39 Correct 2 ms 1248 KB Output is correct
40 Correct 2 ms 1248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 352 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 504 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 1248 KB Output is correct
24 Correct 2 ms 1264 KB Output is correct
25 Correct 2 ms 1248 KB Output is correct
26 Correct 2 ms 1416 KB Output is correct
27 Correct 2 ms 1248 KB Output is correct
28 Correct 2 ms 1248 KB Output is correct
29 Correct 2 ms 1248 KB Output is correct
30 Correct 2 ms 1248 KB Output is correct
31 Correct 2 ms 1248 KB Output is correct
32 Correct 2 ms 1248 KB Output is correct
33 Correct 2 ms 1248 KB Output is correct
34 Correct 2 ms 1248 KB Output is correct
35 Correct 2 ms 1248 KB Output is correct
36 Correct 2 ms 1412 KB Output is correct
37 Correct 2 ms 1248 KB Output is correct
38 Correct 2 ms 1248 KB Output is correct
39 Correct 2 ms 1248 KB Output is correct
40 Correct 2 ms 1248 KB Output is correct
41 Correct 17 ms 8520 KB Output is correct
42 Correct 17 ms 8388 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 352 KB Output is correct
45 Correct 1 ms 352 KB Output is correct
46 Correct 4 ms 1456 KB Output is correct
47 Correct 2 ms 852 KB Output is correct
48 Correct 1 ms 852 KB Output is correct
49 Correct 1 ms 852 KB Output is correct
50 Correct 1 ms 852 KB Output is correct
51 Correct 4 ms 1640 KB Output is correct
52 Correct 16 ms 8132 KB Output is correct
53 Correct 17 ms 8132 KB Output is correct
54 Correct 15 ms 8132 KB Output is correct
55 Correct 1 ms 856 KB Output is correct
56 Correct 1 ms 852 KB Output is correct