Submission #55415

# Submission time Handle Problem Language Result Execution time Memory
55415 2018-07-07T08:38:30 Z 강태규(#1543) Toilets (JOI16_toilets) C++11
100 / 100
55 ms 12724 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

llong n;
int m;
string str[100000];
llong k[100000];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> str[i] >> k[i];
    }
    llong sum = 0, mn = 0;
    for (int i = m; i--; ) {
        int s = 0, t = 0;
        for (int j = str[i].length(); j--; ) {
            s += (str[i][j] == 'M' ? -1 : 1);
            t = min(t, s);
        }
        mn = min({ mn, sum + t, sum + t + (k[i] - 1) * s });
        sum += k[i] * s;
    }
    if (sum < 0) printf("-1\n");
    else if (mn > -2) printf("0\n");
    else printf("%lld\n", -(mn + 1));
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3448 KB Output is correct
2 Correct 5 ms 3556 KB Output is correct
3 Correct 5 ms 3636 KB Output is correct
4 Correct 4 ms 3636 KB Output is correct
5 Correct 4 ms 3636 KB Output is correct
6 Correct 5 ms 3636 KB Output is correct
7 Correct 4 ms 3636 KB Output is correct
8 Correct 4 ms 3728 KB Output is correct
9 Correct 5 ms 3728 KB Output is correct
10 Correct 5 ms 3728 KB Output is correct
11 Correct 6 ms 3728 KB Output is correct
12 Correct 5 ms 3728 KB Output is correct
13 Correct 6 ms 3728 KB Output is correct
14 Correct 4 ms 3728 KB Output is correct
15 Correct 5 ms 3876 KB Output is correct
16 Correct 6 ms 3876 KB Output is correct
17 Correct 5 ms 3876 KB Output is correct
18 Correct 6 ms 3876 KB Output is correct
19 Correct 5 ms 3876 KB Output is correct
20 Correct 5 ms 3876 KB Output is correct
21 Correct 4 ms 3876 KB Output is correct
22 Correct 5 ms 3876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3448 KB Output is correct
2 Correct 5 ms 3556 KB Output is correct
3 Correct 5 ms 3636 KB Output is correct
4 Correct 4 ms 3636 KB Output is correct
5 Correct 4 ms 3636 KB Output is correct
6 Correct 5 ms 3636 KB Output is correct
7 Correct 4 ms 3636 KB Output is correct
8 Correct 4 ms 3728 KB Output is correct
9 Correct 5 ms 3728 KB Output is correct
10 Correct 5 ms 3728 KB Output is correct
11 Correct 6 ms 3728 KB Output is correct
12 Correct 5 ms 3728 KB Output is correct
13 Correct 6 ms 3728 KB Output is correct
14 Correct 4 ms 3728 KB Output is correct
15 Correct 5 ms 3876 KB Output is correct
16 Correct 6 ms 3876 KB Output is correct
17 Correct 5 ms 3876 KB Output is correct
18 Correct 6 ms 3876 KB Output is correct
19 Correct 5 ms 3876 KB Output is correct
20 Correct 5 ms 3876 KB Output is correct
21 Correct 4 ms 3876 KB Output is correct
22 Correct 5 ms 3876 KB Output is correct
23 Correct 5 ms 4092 KB Output is correct
24 Correct 7 ms 4092 KB Output is correct
25 Correct 6 ms 4100 KB Output is correct
26 Correct 6 ms 4100 KB Output is correct
27 Correct 7 ms 4216 KB Output is correct
28 Correct 7 ms 4216 KB Output is correct
29 Correct 6 ms 4216 KB Output is correct
30 Correct 6 ms 4216 KB Output is correct
31 Correct 6 ms 4216 KB Output is correct
32 Correct 5 ms 4216 KB Output is correct
33 Correct 5 ms 4216 KB Output is correct
34 Correct 6 ms 4216 KB Output is correct
35 Correct 9 ms 4216 KB Output is correct
36 Correct 7 ms 4216 KB Output is correct
37 Correct 8 ms 4216 KB Output is correct
38 Correct 7 ms 4216 KB Output is correct
39 Correct 6 ms 4216 KB Output is correct
40 Correct 7 ms 4216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3448 KB Output is correct
2 Correct 5 ms 3556 KB Output is correct
3 Correct 5 ms 3636 KB Output is correct
4 Correct 4 ms 3636 KB Output is correct
5 Correct 4 ms 3636 KB Output is correct
6 Correct 5 ms 3636 KB Output is correct
7 Correct 4 ms 3636 KB Output is correct
8 Correct 4 ms 3728 KB Output is correct
9 Correct 5 ms 3728 KB Output is correct
10 Correct 5 ms 3728 KB Output is correct
11 Correct 6 ms 3728 KB Output is correct
12 Correct 5 ms 3728 KB Output is correct
13 Correct 6 ms 3728 KB Output is correct
14 Correct 4 ms 3728 KB Output is correct
15 Correct 5 ms 3876 KB Output is correct
16 Correct 6 ms 3876 KB Output is correct
17 Correct 5 ms 3876 KB Output is correct
18 Correct 6 ms 3876 KB Output is correct
19 Correct 5 ms 3876 KB Output is correct
20 Correct 5 ms 3876 KB Output is correct
21 Correct 4 ms 3876 KB Output is correct
22 Correct 5 ms 3876 KB Output is correct
23 Correct 5 ms 4092 KB Output is correct
24 Correct 7 ms 4092 KB Output is correct
25 Correct 6 ms 4100 KB Output is correct
26 Correct 6 ms 4100 KB Output is correct
27 Correct 7 ms 4216 KB Output is correct
28 Correct 7 ms 4216 KB Output is correct
29 Correct 6 ms 4216 KB Output is correct
30 Correct 6 ms 4216 KB Output is correct
31 Correct 6 ms 4216 KB Output is correct
32 Correct 5 ms 4216 KB Output is correct
33 Correct 5 ms 4216 KB Output is correct
34 Correct 6 ms 4216 KB Output is correct
35 Correct 9 ms 4216 KB Output is correct
36 Correct 7 ms 4216 KB Output is correct
37 Correct 8 ms 4216 KB Output is correct
38 Correct 7 ms 4216 KB Output is correct
39 Correct 6 ms 4216 KB Output is correct
40 Correct 7 ms 4216 KB Output is correct
41 Correct 55 ms 6124 KB Output is correct
42 Correct 39 ms 7744 KB Output is correct
43 Correct 6 ms 7744 KB Output is correct
44 Correct 6 ms 7744 KB Output is correct
45 Correct 10 ms 7744 KB Output is correct
46 Correct 21 ms 7744 KB Output is correct
47 Correct 9 ms 7744 KB Output is correct
48 Correct 6 ms 7920 KB Output is correct
49 Correct 8 ms 8248 KB Output is correct
50 Correct 15 ms 8336 KB Output is correct
51 Correct 11 ms 8800 KB Output is correct
52 Correct 34 ms 10428 KB Output is correct
53 Correct 36 ms 11572 KB Output is correct
54 Correct 27 ms 12724 KB Output is correct
55 Correct 5 ms 12724 KB Output is correct
56 Correct 7 ms 12724 KB Output is correct