Submission #787241

# Submission time Handle Problem Language Result Execution time Memory
787241 2023-07-19T00:16:57 Z tvladm2009 JJOOII 2 (JOI20_ho_t2) C++17
13 / 100
2000 ms 992 KB
#include <bits/stdc++.h>

using namespace std;

const int INF = (int) 1e9;

int cnt[3];
int n, k;
string s;

int getcost(int x) {
  cnt[0] = cnt[1] = cnt[2] = 0;
  int cost = 0;
  while (x <= n) {
    int where = -1;
    if (s[x] == 'J') {
      where = 0;
    } else if (s[x] == 'O') {
      where = 1;
    } else {
      where = 2;
    }
    int mn = INF;
    for (int i = where - 1; i >= 0; i--) {
      mn = min(mn, cnt[i]);
    }
    if (mn < k || cnt[where] == k) {
      cost++;
    } else {
      cnt[where]++;
    }
    if (cnt[0] == k && cnt[1] == k && cnt[2] == k) {
      break;
    }
    x++;
  }
  if (cnt[0] != k || cnt[1] != k || cnt[2] != k) {
    cost = INF;
  }
  return cost;
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);

  // freopen("input", "r", stdin);

  cin >> n >> k >> s;
  s = "#" + s;
  int sol = INF;
  for (int i = 1; i <= n; i++) {
    sol = min(sol, getcost(i));
  }
  if (sol == INF) {
    cout << "-1";
    return 0;
  }
  cout << sol << "\n";
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 5 ms 320 KB Output is correct
18 Correct 5 ms 212 KB Output is correct
19 Correct 4 ms 212 KB Output is correct
20 Correct 4 ms 212 KB Output is correct
21 Correct 15 ms 212 KB Output is correct
22 Correct 12 ms 332 KB Output is correct
23 Correct 4 ms 312 KB Output is correct
24 Correct 14 ms 320 KB Output is correct
25 Correct 14 ms 212 KB Output is correct
26 Correct 14 ms 212 KB Output is correct
27 Correct 16 ms 336 KB Output is correct
28 Correct 13 ms 316 KB Output is correct
29 Correct 14 ms 328 KB Output is correct
30 Correct 14 ms 328 KB Output is correct
31 Correct 3 ms 212 KB Output is correct
32 Correct 12 ms 320 KB Output is correct
33 Correct 6 ms 320 KB Output is correct
34 Correct 7 ms 328 KB Output is correct
35 Correct 7 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 5 ms 320 KB Output is correct
18 Correct 5 ms 212 KB Output is correct
19 Correct 4 ms 212 KB Output is correct
20 Correct 4 ms 212 KB Output is correct
21 Correct 15 ms 212 KB Output is correct
22 Correct 12 ms 332 KB Output is correct
23 Correct 4 ms 312 KB Output is correct
24 Correct 14 ms 320 KB Output is correct
25 Correct 14 ms 212 KB Output is correct
26 Correct 14 ms 212 KB Output is correct
27 Correct 16 ms 336 KB Output is correct
28 Correct 13 ms 316 KB Output is correct
29 Correct 14 ms 328 KB Output is correct
30 Correct 14 ms 328 KB Output is correct
31 Correct 3 ms 212 KB Output is correct
32 Correct 12 ms 320 KB Output is correct
33 Correct 6 ms 320 KB Output is correct
34 Correct 7 ms 328 KB Output is correct
35 Correct 7 ms 328 KB Output is correct
36 Correct 12 ms 964 KB Output is correct
37 Correct 12 ms 992 KB Output is correct
38 Correct 12 ms 992 KB Output is correct
39 Execution timed out 2076 ms 964 KB Time limit exceeded
40 Halted 0 ms 0 KB -