# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
55419 | 2018-07-07T08:53:49 Z | 김세빈(#1545) | Toilets (JOI16_toilets) | C++11 | 66 ms | 9412 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; char str[202020]; string S[202020]; ll K[202020], F[202020], M[202020]; ll n, k, f, m, ans1, ans2; int main() { ll i, j, s, e; scanf("%lld%lld", &n, &k); for(i=0;i<k;i++){ scanf("%s%lld", str, K+i); S[i] = str; for(j=0;str[j];j++){ if(str[j] == 'F') F[i] ++; else M[i] ++; } f += F[i] * K[i]; m += M[i] * K[i]; } if(f < m){ printf("-1\n"); return 0; } f = m = 0; for(i=k-1;i>=0;i--){ if(K[i] < 4){ s = S[i].size(); for(j=s*K[i]-1;j>=0;j--){ if(S[i][j%s] == 'M') m ++; else f ++; if(m + f & 1) ans1 = max(ans1, m - f + !(m - f & 1)); else ans2 = max(ans2, m - f + (m - f & 1)); } } else{ s = S[i].size(); for(j=s*2-1;j>=0;j--){ if(S[i][j%s] == 'M') m ++; else f ++; if(m + f & 1) ans1 = max(ans1, m - f + !(m - f & 1)); else ans2 = max(ans2, m - f + (m - f & 1)); } m += M[i] * (K[i] - 4); f += F[i] * (K[i] - 4); for(j=s*2-1;j>=0;j--){ if(S[i][j%s] == 'M') m ++; else f ++; if(m + f & 1) ans1 = max(ans1, m - f + !(m - f & 1)); else ans2 = max(ans2, m - f + (m - f & 1)); } } } printf("%lld\n", min(ans1, ans2)); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 6648 KB | Output is correct |
2 | Correct | 7 ms | 6756 KB | Output is correct |
3 | Correct | 7 ms | 6832 KB | Output is correct |
4 | Correct | 7 ms | 6832 KB | Output is correct |
5 | Correct | 7 ms | 6832 KB | Output is correct |
6 | Correct | 8 ms | 6832 KB | Output is correct |
7 | Correct | 6 ms | 6972 KB | Output is correct |
8 | Correct | 6 ms | 6972 KB | Output is correct |
9 | Correct | 7 ms | 6972 KB | Output is correct |
10 | Correct | 9 ms | 6972 KB | Output is correct |
11 | Correct | 8 ms | 6972 KB | Output is correct |
12 | Correct | 8 ms | 6972 KB | Output is correct |
13 | Correct | 10 ms | 6972 KB | Output is correct |
14 | Correct | 7 ms | 6972 KB | Output is correct |
15 | Correct | 7 ms | 6972 KB | Output is correct |
16 | Correct | 7 ms | 6972 KB | Output is correct |
17 | Correct | 10 ms | 6972 KB | Output is correct |
18 | Correct | 7 ms | 6972 KB | Output is correct |
19 | Correct | 9 ms | 6972 KB | Output is correct |
20 | Correct | 7 ms | 6972 KB | Output is correct |
21 | Correct | 9 ms | 6972 KB | Output is correct |
22 | Correct | 6 ms | 6972 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 6648 KB | Output is correct |
2 | Correct | 7 ms | 6756 KB | Output is correct |
3 | Correct | 7 ms | 6832 KB | Output is correct |
4 | Correct | 7 ms | 6832 KB | Output is correct |
5 | Correct | 7 ms | 6832 KB | Output is correct |
6 | Correct | 8 ms | 6832 KB | Output is correct |
7 | Correct | 6 ms | 6972 KB | Output is correct |
8 | Correct | 6 ms | 6972 KB | Output is correct |
9 | Correct | 7 ms | 6972 KB | Output is correct |
10 | Correct | 9 ms | 6972 KB | Output is correct |
11 | Correct | 8 ms | 6972 KB | Output is correct |
12 | Correct | 8 ms | 6972 KB | Output is correct |
13 | Correct | 10 ms | 6972 KB | Output is correct |
14 | Correct | 7 ms | 6972 KB | Output is correct |
15 | Correct | 7 ms | 6972 KB | Output is correct |
16 | Correct | 7 ms | 6972 KB | Output is correct |
17 | Correct | 10 ms | 6972 KB | Output is correct |
18 | Correct | 7 ms | 6972 KB | Output is correct |
19 | Correct | 9 ms | 6972 KB | Output is correct |
20 | Correct | 7 ms | 6972 KB | Output is correct |
21 | Correct | 9 ms | 6972 KB | Output is correct |
22 | Correct | 6 ms | 6972 KB | Output is correct |
23 | Correct | 14 ms | 7280 KB | Output is correct |
24 | Correct | 14 ms | 7280 KB | Output is correct |
25 | Correct | 13 ms | 7356 KB | Output is correct |
26 | Correct | 15 ms | 7376 KB | Output is correct |
27 | Correct | 10 ms | 7376 KB | Output is correct |
28 | Correct | 17 ms | 7376 KB | Output is correct |
29 | Correct | 13 ms | 7376 KB | Output is correct |
30 | Correct | 18 ms | 7376 KB | Output is correct |
31 | Correct | 16 ms | 7376 KB | Output is correct |
32 | Correct | 17 ms | 7376 KB | Output is correct |
33 | Correct | 9 ms | 7376 KB | Output is correct |
34 | Correct | 13 ms | 7376 KB | Output is correct |
35 | Correct | 15 ms | 7376 KB | Output is correct |
36 | Correct | 16 ms | 7376 KB | Output is correct |
37 | Correct | 11 ms | 7376 KB | Output is correct |
38 | Correct | 9 ms | 7376 KB | Output is correct |
39 | Correct | 12 ms | 7376 KB | Output is correct |
40 | Correct | 14 ms | 7376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 6648 KB | Output is correct |
2 | Correct | 7 ms | 6756 KB | Output is correct |
3 | Correct | 7 ms | 6832 KB | Output is correct |
4 | Correct | 7 ms | 6832 KB | Output is correct |
5 | Correct | 7 ms | 6832 KB | Output is correct |
6 | Correct | 8 ms | 6832 KB | Output is correct |
7 | Correct | 6 ms | 6972 KB | Output is correct |
8 | Correct | 6 ms | 6972 KB | Output is correct |
9 | Correct | 7 ms | 6972 KB | Output is correct |
10 | Correct | 9 ms | 6972 KB | Output is correct |
11 | Correct | 8 ms | 6972 KB | Output is correct |
12 | Correct | 8 ms | 6972 KB | Output is correct |
13 | Correct | 10 ms | 6972 KB | Output is correct |
14 | Correct | 7 ms | 6972 KB | Output is correct |
15 | Correct | 7 ms | 6972 KB | Output is correct |
16 | Correct | 7 ms | 6972 KB | Output is correct |
17 | Correct | 10 ms | 6972 KB | Output is correct |
18 | Correct | 7 ms | 6972 KB | Output is correct |
19 | Correct | 9 ms | 6972 KB | Output is correct |
20 | Correct | 7 ms | 6972 KB | Output is correct |
21 | Correct | 9 ms | 6972 KB | Output is correct |
22 | Correct | 6 ms | 6972 KB | Output is correct |
23 | Correct | 14 ms | 7280 KB | Output is correct |
24 | Correct | 14 ms | 7280 KB | Output is correct |
25 | Correct | 13 ms | 7356 KB | Output is correct |
26 | Correct | 15 ms | 7376 KB | Output is correct |
27 | Correct | 10 ms | 7376 KB | Output is correct |
28 | Correct | 17 ms | 7376 KB | Output is correct |
29 | Correct | 13 ms | 7376 KB | Output is correct |
30 | Correct | 18 ms | 7376 KB | Output is correct |
31 | Correct | 16 ms | 7376 KB | Output is correct |
32 | Correct | 17 ms | 7376 KB | Output is correct |
33 | Correct | 9 ms | 7376 KB | Output is correct |
34 | Correct | 13 ms | 7376 KB | Output is correct |
35 | Correct | 15 ms | 7376 KB | Output is correct |
36 | Correct | 16 ms | 7376 KB | Output is correct |
37 | Correct | 11 ms | 7376 KB | Output is correct |
38 | Correct | 9 ms | 7376 KB | Output is correct |
39 | Correct | 12 ms | 7376 KB | Output is correct |
40 | Correct | 14 ms | 7376 KB | Output is correct |
41 | Correct | 47 ms | 9300 KB | Output is correct |
42 | Correct | 53 ms | 9300 KB | Output is correct |
43 | Correct | 8 ms | 9300 KB | Output is correct |
44 | Correct | 8 ms | 9300 KB | Output is correct |
45 | Correct | 8 ms | 9300 KB | Output is correct |
46 | Correct | 35 ms | 9300 KB | Output is correct |
47 | Correct | 29 ms | 9300 KB | Output is correct |
48 | Correct | 32 ms | 9300 KB | Output is correct |
49 | Correct | 27 ms | 9300 KB | Output is correct |
50 | Correct | 30 ms | 9300 KB | Output is correct |
51 | Correct | 37 ms | 9300 KB | Output is correct |
52 | Correct | 66 ms | 9320 KB | Output is correct |
53 | Correct | 62 ms | 9320 KB | Output is correct |
54 | Correct | 65 ms | 9412 KB | Output is correct |
55 | Correct | 20 ms | 9412 KB | Output is correct |
56 | Correct | 21 ms | 9412 KB | Output is correct |