답안 #201619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201619 2020-02-11T12:41:40 Z waynetuinfor JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
76 ms 3080 KB
#include <algorithm>
#include <array>
#include <iostream>
#include <string>
#include <vector>

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  int n, k;
  std::cin >> n >> k;
  std::string s;
  std::cin >> s;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'J') {
      s[i] = 0;
    } else if (s[i] == 'O') {
      s[i] = 1;
    } else if (s[i] == 'I') {
      s[i] = 2;
    }
  }
  std::vector<std::array<int, 3>> pref(n + 1, std::array<int, 3>{});
  for (int i = 0; i < n; ++i) {
    pref[i + 1] = pref[i];
    pref[i + 1][s[i]]++;
  }
  int ans = n + 1;
  for (int i = 0; i < n; ++i) {
    bool ok = true;
    int p = i;
    for (int j = 0; j < 3; ++j) {
      int r = n + 1;
      for (int d = 20; d >= 0; --d) {
        if (r - (1 << d) <= p) continue;
        if (pref[r - (1 << d)][j] - pref[p][j] >= k) r -= (1 << d);
      }
      if (r > n) {
        ok = false;
        break;
      }
      p = r;
    }
    if (!ok) break;
    int res = 0;
    for (int j = 0; j < 3; ++j) res += pref[p][j] - pref[i][j] - k;
    ans = std::min(ans, res);
  }
  if (ans == n + 1) ans = -1;
  std::cout << ans << "\n";
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 248 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 248 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 380 KB Output is correct
16 Correct 6 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 6 ms 380 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 380 KB Output is correct
24 Correct 5 ms 380 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 380 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 248 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 380 KB Output is correct
16 Correct 6 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 6 ms 380 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 380 KB Output is correct
24 Correct 5 ms 380 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 380 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 57 ms 2884 KB Output is correct
37 Correct 62 ms 3076 KB Output is correct
38 Correct 60 ms 3076 KB Output is correct
39 Correct 71 ms 2948 KB Output is correct
40 Correct 26 ms 3076 KB Output is correct
41 Correct 57 ms 3080 KB Output is correct
42 Correct 76 ms 2948 KB Output is correct
43 Correct 8 ms 2040 KB Output is correct
44 Correct 9 ms 2436 KB Output is correct
45 Correct 10 ms 2948 KB Output is correct
46 Correct 10 ms 2948 KB Output is correct
47 Correct 11 ms 3076 KB Output is correct
48 Correct 10 ms 2948 KB Output is correct
49 Correct 8 ms 2180 KB Output is correct
50 Correct 10 ms 3076 KB Output is correct
51 Correct 11 ms 2948 KB Output is correct
52 Correct 16 ms 2948 KB Output is correct
53 Correct 10 ms 2948 KB Output is correct
54 Correct 32 ms 2948 KB Output is correct
55 Correct 18 ms 2948 KB Output is correct
56 Correct 9 ms 2948 KB Output is correct