# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
56005 | 2018-07-09T10:04:23 Z | youngyojun | Toilets (JOI16_toilets) | C++11 | 44 ms | 2700 KB |
#include <bits/stdc++.h> #define pb push_back #define eb emplace_back #define sz(V) ((int)(V).size()) #define allv(V) ((V).begin()),((V).end()) #define befv(V) ((V)[(sz(V)-2)]) #define sorv(V) sort(allv(V)) #define revv(V) reverse(allv(V)) #define univ(V) (V).erase(unique(allv(V)),(V).end()) #define clv(V) (V).clear() #define upmin(a,b) (a)=min((a),(b)) #define upmax(a,b) (a)=max((a),(b)) #define INF (0x3f3f3f3f) #define INFLL (0x3f3f3f3f3f3f3f3fll) using namespace std; typedef long long ll; char A[200005]; ll sum, mn; ll M, X; int main() { scanf("%*lld%lld", &M); for(; M--;) { scanf(" %s%lld", A, &X); ll ret = 0, h = 0; for(int i = 0; A[i]; i++) { ret += ('M' == A[i] ? 1 : -1); upmin(h, ret); } upmin(mn, sum + min({h, h + ret*(X-1), ret*X})); sum += ret*X; } mn -= sum; if(0 < sum) puts("-1"); else if(-1 <= mn) puts("0"); else cout << (-mn-1) << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 488 KB | Output is correct |
3 | Correct | 2 ms | 488 KB | Output is correct |
4 | Correct | 2 ms | 572 KB | Output is correct |
5 | Correct | 2 ms | 572 KB | Output is correct |
6 | Correct | 2 ms | 608 KB | Output is correct |
7 | Correct | 2 ms | 672 KB | Output is correct |
8 | Correct | 4 ms | 724 KB | Output is correct |
9 | Correct | 2 ms | 724 KB | Output is correct |
10 | Correct | 2 ms | 724 KB | Output is correct |
11 | Correct | 3 ms | 724 KB | Output is correct |
12 | Correct | 2 ms | 724 KB | Output is correct |
13 | Correct | 2 ms | 724 KB | Output is correct |
14 | Correct | 2 ms | 724 KB | Output is correct |
15 | Correct | 2 ms | 724 KB | Output is correct |
16 | Correct | 2 ms | 724 KB | Output is correct |
17 | Correct | 2 ms | 724 KB | Output is correct |
18 | Correct | 2 ms | 724 KB | Output is correct |
19 | Correct | 2 ms | 724 KB | Output is correct |
20 | Correct | 2 ms | 724 KB | Output is correct |
21 | Correct | 2 ms | 724 KB | Output is correct |
22 | Correct | 2 ms | 724 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 488 KB | Output is correct |
3 | Correct | 2 ms | 488 KB | Output is correct |
4 | Correct | 2 ms | 572 KB | Output is correct |
5 | Correct | 2 ms | 572 KB | Output is correct |
6 | Correct | 2 ms | 608 KB | Output is correct |
7 | Correct | 2 ms | 672 KB | Output is correct |
8 | Correct | 4 ms | 724 KB | Output is correct |
9 | Correct | 2 ms | 724 KB | Output is correct |
10 | Correct | 2 ms | 724 KB | Output is correct |
11 | Correct | 3 ms | 724 KB | Output is correct |
12 | Correct | 2 ms | 724 KB | Output is correct |
13 | Correct | 2 ms | 724 KB | Output is correct |
14 | Correct | 2 ms | 724 KB | Output is correct |
15 | Correct | 2 ms | 724 KB | Output is correct |
16 | Correct | 2 ms | 724 KB | Output is correct |
17 | Correct | 2 ms | 724 KB | Output is correct |
18 | Correct | 2 ms | 724 KB | Output is correct |
19 | Correct | 2 ms | 724 KB | Output is correct |
20 | Correct | 2 ms | 724 KB | Output is correct |
21 | Correct | 2 ms | 724 KB | Output is correct |
22 | Correct | 2 ms | 724 KB | Output is correct |
23 | Correct | 5 ms | 964 KB | Output is correct |
24 | Correct | 5 ms | 1152 KB | Output is correct |
25 | Correct | 5 ms | 1348 KB | Output is correct |
26 | Correct | 5 ms | 1544 KB | Output is correct |
27 | Correct | 4 ms | 1740 KB | Output is correct |
28 | Correct | 5 ms | 1904 KB | Output is correct |
29 | Correct | 3 ms | 1908 KB | Output is correct |
30 | Correct | 4 ms | 1908 KB | Output is correct |
31 | Correct | 4 ms | 1908 KB | Output is correct |
32 | Correct | 3 ms | 1908 KB | Output is correct |
33 | Correct | 4 ms | 1908 KB | Output is correct |
34 | Correct | 5 ms | 1908 KB | Output is correct |
35 | Correct | 3 ms | 1908 KB | Output is correct |
36 | Correct | 4 ms | 1908 KB | Output is correct |
37 | Correct | 3 ms | 1908 KB | Output is correct |
38 | Correct | 4 ms | 1908 KB | Output is correct |
39 | Correct | 4 ms | 1908 KB | Output is correct |
40 | Correct | 3 ms | 1908 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 488 KB | Output is correct |
3 | Correct | 2 ms | 488 KB | Output is correct |
4 | Correct | 2 ms | 572 KB | Output is correct |
5 | Correct | 2 ms | 572 KB | Output is correct |
6 | Correct | 2 ms | 608 KB | Output is correct |
7 | Correct | 2 ms | 672 KB | Output is correct |
8 | Correct | 4 ms | 724 KB | Output is correct |
9 | Correct | 2 ms | 724 KB | Output is correct |
10 | Correct | 2 ms | 724 KB | Output is correct |
11 | Correct | 3 ms | 724 KB | Output is correct |
12 | Correct | 2 ms | 724 KB | Output is correct |
13 | Correct | 2 ms | 724 KB | Output is correct |
14 | Correct | 2 ms | 724 KB | Output is correct |
15 | Correct | 2 ms | 724 KB | Output is correct |
16 | Correct | 2 ms | 724 KB | Output is correct |
17 | Correct | 2 ms | 724 KB | Output is correct |
18 | Correct | 2 ms | 724 KB | Output is correct |
19 | Correct | 2 ms | 724 KB | Output is correct |
20 | Correct | 2 ms | 724 KB | Output is correct |
21 | Correct | 2 ms | 724 KB | Output is correct |
22 | Correct | 2 ms | 724 KB | Output is correct |
23 | Correct | 5 ms | 964 KB | Output is correct |
24 | Correct | 5 ms | 1152 KB | Output is correct |
25 | Correct | 5 ms | 1348 KB | Output is correct |
26 | Correct | 5 ms | 1544 KB | Output is correct |
27 | Correct | 4 ms | 1740 KB | Output is correct |
28 | Correct | 5 ms | 1904 KB | Output is correct |
29 | Correct | 3 ms | 1908 KB | Output is correct |
30 | Correct | 4 ms | 1908 KB | Output is correct |
31 | Correct | 4 ms | 1908 KB | Output is correct |
32 | Correct | 3 ms | 1908 KB | Output is correct |
33 | Correct | 4 ms | 1908 KB | Output is correct |
34 | Correct | 5 ms | 1908 KB | Output is correct |
35 | Correct | 3 ms | 1908 KB | Output is correct |
36 | Correct | 4 ms | 1908 KB | Output is correct |
37 | Correct | 3 ms | 1908 KB | Output is correct |
38 | Correct | 4 ms | 1908 KB | Output is correct |
39 | Correct | 4 ms | 1908 KB | Output is correct |
40 | Correct | 3 ms | 1908 KB | Output is correct |
41 | Correct | 44 ms | 2644 KB | Output is correct |
42 | Correct | 34 ms | 2664 KB | Output is correct |
43 | Correct | 3 ms | 2664 KB | Output is correct |
44 | Correct | 2 ms | 2664 KB | Output is correct |
45 | Correct | 3 ms | 2664 KB | Output is correct |
46 | Correct | 8 ms | 2664 KB | Output is correct |
47 | Correct | 4 ms | 2664 KB | Output is correct |
48 | Correct | 4 ms | 2700 KB | Output is correct |
49 | Correct | 4 ms | 2700 KB | Output is correct |
50 | Correct | 5 ms | 2700 KB | Output is correct |
51 | Correct | 7 ms | 2700 KB | Output is correct |
52 | Correct | 28 ms | 2700 KB | Output is correct |
53 | Correct | 27 ms | 2700 KB | Output is correct |
54 | Correct | 39 ms | 2700 KB | Output is correct |
55 | Correct | 4 ms | 2700 KB | Output is correct |
56 | Correct | 5 ms | 2700 KB | Output is correct |