Submission #443561

# Submission time Handle Problem Language Result Execution time Memory
443561 2021-07-10T19:48:38 Z MilosMilutinovic JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
6 ms 2512 KB
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<int> pref(n);
  for (int i = 0; i < n; i++) {
    if (i > 0) {
      pref[i] = pref[i - 1];
    }
    if (s[i] == 'O') {
      pref[i]++;
    }
  }
  vector<int> x, y;
  for (int i = 0; i < n; i++) {
  	if (s[i] == 'J') {
      x.push_back(i);
    }
    if (s[i] == 'I') {
      y.push_back(i);
    }
  }
  int ans = n + 1;
  for (int i = k - 1, j = 0; i < (int) x.size(); i++) {
    while (j < (int) y.size() && pref[y[j]] - pref[x[i]] < k) {
      j++;
    }
    if (j <= (int) y.size() - k && pref[y[j]] - pref[x[i]] >= k) {
      ans = min(ans, n - 3 * k - x[i - k + 1] - (n - y[j + k - 1] - 1));  
    }
  }
  cout << (ans > n ? -1 : ans);
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 5 ms 2048 KB Output is correct
37 Correct 6 ms 2356 KB Output is correct
38 Correct 6 ms 2512 KB Output is correct
39 Correct 6 ms 2388 KB Output is correct
40 Correct 6 ms 2336 KB Output is correct
41 Correct 6 ms 2388 KB Output is correct
42 Correct 6 ms 2344 KB Output is correct
43 Correct 4 ms 1704 KB Output is correct
44 Correct 5 ms 1748 KB Output is correct
45 Correct 5 ms 2308 KB Output is correct
46 Correct 6 ms 2368 KB Output is correct
47 Correct 5 ms 2336 KB Output is correct
48 Correct 6 ms 2384 KB Output is correct
49 Correct 4 ms 1624 KB Output is correct
50 Correct 5 ms 2400 KB Output is correct
51 Correct 5 ms 2368 KB Output is correct
52 Correct 5 ms 2008 KB Output is correct
53 Correct 5 ms 2388 KB Output is correct
54 Correct 3 ms 2512 KB Output is correct
55 Correct 4 ms 2512 KB Output is correct
56 Correct 3 ms 2512 KB Output is correct