# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
55414 |
2018-07-07T08:33:42 Z |
강태규(#1543) |
Toilets (JOI16_toilets) |
C++11 |
|
8 ms |
4200 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];
int 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] - 1ll) * s });
sum += (llong)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 |
3448 KB |
Output is correct |
3 |
Correct |
5 ms |
3612 KB |
Output is correct |
4 |
Correct |
5 ms |
3612 KB |
Output is correct |
5 |
Correct |
6 ms |
3816 KB |
Output is correct |
6 |
Correct |
5 ms |
3816 KB |
Output is correct |
7 |
Correct |
6 ms |
3816 KB |
Output is correct |
8 |
Correct |
6 ms |
3816 KB |
Output is correct |
9 |
Correct |
5 ms |
3816 KB |
Output is correct |
10 |
Correct |
6 ms |
3816 KB |
Output is correct |
11 |
Correct |
5 ms |
3820 KB |
Output is correct |
12 |
Correct |
4 ms |
3820 KB |
Output is correct |
13 |
Correct |
5 ms |
3820 KB |
Output is correct |
14 |
Correct |
5 ms |
3820 KB |
Output is correct |
15 |
Correct |
5 ms |
3820 KB |
Output is correct |
16 |
Correct |
6 ms |
3820 KB |
Output is correct |
17 |
Correct |
6 ms |
3820 KB |
Output is correct |
18 |
Correct |
6 ms |
3820 KB |
Output is correct |
19 |
Correct |
5 ms |
3820 KB |
Output is correct |
20 |
Correct |
4 ms |
3820 KB |
Output is correct |
21 |
Correct |
5 ms |
3820 KB |
Output is correct |
22 |
Correct |
5 ms |
3820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3448 KB |
Output is correct |
2 |
Correct |
5 ms |
3448 KB |
Output is correct |
3 |
Correct |
5 ms |
3612 KB |
Output is correct |
4 |
Correct |
5 ms |
3612 KB |
Output is correct |
5 |
Correct |
6 ms |
3816 KB |
Output is correct |
6 |
Correct |
5 ms |
3816 KB |
Output is correct |
7 |
Correct |
6 ms |
3816 KB |
Output is correct |
8 |
Correct |
6 ms |
3816 KB |
Output is correct |
9 |
Correct |
5 ms |
3816 KB |
Output is correct |
10 |
Correct |
6 ms |
3816 KB |
Output is correct |
11 |
Correct |
5 ms |
3820 KB |
Output is correct |
12 |
Correct |
4 ms |
3820 KB |
Output is correct |
13 |
Correct |
5 ms |
3820 KB |
Output is correct |
14 |
Correct |
5 ms |
3820 KB |
Output is correct |
15 |
Correct |
5 ms |
3820 KB |
Output is correct |
16 |
Correct |
6 ms |
3820 KB |
Output is correct |
17 |
Correct |
6 ms |
3820 KB |
Output is correct |
18 |
Correct |
6 ms |
3820 KB |
Output is correct |
19 |
Correct |
5 ms |
3820 KB |
Output is correct |
20 |
Correct |
4 ms |
3820 KB |
Output is correct |
21 |
Correct |
5 ms |
3820 KB |
Output is correct |
22 |
Correct |
5 ms |
3820 KB |
Output is correct |
23 |
Correct |
5 ms |
4092 KB |
Output is correct |
24 |
Correct |
6 ms |
4092 KB |
Output is correct |
25 |
Correct |
6 ms |
4104 KB |
Output is correct |
26 |
Correct |
5 ms |
4104 KB |
Output is correct |
27 |
Correct |
6 ms |
4104 KB |
Output is correct |
28 |
Correct |
6 ms |
4104 KB |
Output is correct |
29 |
Correct |
6 ms |
4104 KB |
Output is correct |
30 |
Correct |
5 ms |
4104 KB |
Output is correct |
31 |
Correct |
5 ms |
4104 KB |
Output is correct |
32 |
Correct |
5 ms |
4104 KB |
Output is correct |
33 |
Correct |
7 ms |
4104 KB |
Output is correct |
34 |
Correct |
7 ms |
4104 KB |
Output is correct |
35 |
Correct |
6 ms |
4104 KB |
Output is correct |
36 |
Correct |
7 ms |
4104 KB |
Output is correct |
37 |
Correct |
7 ms |
4104 KB |
Output is correct |
38 |
Correct |
6 ms |
4104 KB |
Output is correct |
39 |
Correct |
8 ms |
4200 KB |
Output is correct |
40 |
Correct |
6 ms |
4200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3448 KB |
Output is correct |
2 |
Correct |
5 ms |
3448 KB |
Output is correct |
3 |
Correct |
5 ms |
3612 KB |
Output is correct |
4 |
Correct |
5 ms |
3612 KB |
Output is correct |
5 |
Correct |
6 ms |
3816 KB |
Output is correct |
6 |
Correct |
5 ms |
3816 KB |
Output is correct |
7 |
Correct |
6 ms |
3816 KB |
Output is correct |
8 |
Correct |
6 ms |
3816 KB |
Output is correct |
9 |
Correct |
5 ms |
3816 KB |
Output is correct |
10 |
Correct |
6 ms |
3816 KB |
Output is correct |
11 |
Correct |
5 ms |
3820 KB |
Output is correct |
12 |
Correct |
4 ms |
3820 KB |
Output is correct |
13 |
Correct |
5 ms |
3820 KB |
Output is correct |
14 |
Correct |
5 ms |
3820 KB |
Output is correct |
15 |
Correct |
5 ms |
3820 KB |
Output is correct |
16 |
Correct |
6 ms |
3820 KB |
Output is correct |
17 |
Correct |
6 ms |
3820 KB |
Output is correct |
18 |
Correct |
6 ms |
3820 KB |
Output is correct |
19 |
Correct |
5 ms |
3820 KB |
Output is correct |
20 |
Correct |
4 ms |
3820 KB |
Output is correct |
21 |
Correct |
5 ms |
3820 KB |
Output is correct |
22 |
Correct |
5 ms |
3820 KB |
Output is correct |
23 |
Correct |
5 ms |
4092 KB |
Output is correct |
24 |
Correct |
6 ms |
4092 KB |
Output is correct |
25 |
Correct |
6 ms |
4104 KB |
Output is correct |
26 |
Correct |
5 ms |
4104 KB |
Output is correct |
27 |
Correct |
6 ms |
4104 KB |
Output is correct |
28 |
Correct |
6 ms |
4104 KB |
Output is correct |
29 |
Correct |
6 ms |
4104 KB |
Output is correct |
30 |
Correct |
5 ms |
4104 KB |
Output is correct |
31 |
Correct |
5 ms |
4104 KB |
Output is correct |
32 |
Correct |
5 ms |
4104 KB |
Output is correct |
33 |
Correct |
7 ms |
4104 KB |
Output is correct |
34 |
Correct |
7 ms |
4104 KB |
Output is correct |
35 |
Correct |
6 ms |
4104 KB |
Output is correct |
36 |
Correct |
7 ms |
4104 KB |
Output is correct |
37 |
Correct |
7 ms |
4104 KB |
Output is correct |
38 |
Correct |
6 ms |
4104 KB |
Output is correct |
39 |
Correct |
8 ms |
4200 KB |
Output is correct |
40 |
Correct |
6 ms |
4200 KB |
Output is correct |
41 |
Correct |
8 ms |
4200 KB |
Output is correct |
42 |
Incorrect |
7 ms |
4200 KB |
Output isn't correct |
43 |
Halted |
0 ms |
0 KB |
- |