답안 #787772

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
787772 2023-07-19T12:23:20 Z tvladm2009 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
29 ms 5524 KB
#include <bits/stdc++.h>

using namespace std;

const int N = (int) 2e5 + 7;
const int INF = (int) 1e9;
int J[N], O[N], I[N];
int whereJ[N], whereO[N], whereI[N];
int n, k;
string s;

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

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

  cin >> n >> k >> s;
  s = "#" + s;
  for (int i = 1; i <= n; i++) {
    J[i] = J[i - 1];
    O[i] = O[i - 1];
    I[i] = I[i - 1];
    if (s[i] == 'J') {
      J[i]++;
    } else if (s[i] == 'O') {
      O[i]++;
    } else {
      I[i]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    int low = 1, high = n;
    while (low <= high) {
      int mid = (low + high) / 2;
      if (J[mid] - J[i - 1] >= k) {
        whereJ[i] = mid;
        high = mid - 1;
      } else {
        low = mid + 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int low = 1, high = n;
    while (low <= high) {
      int mid = (low + high) / 2;
      if (O[mid] - O[i - 1] >= k) {
        whereO[i] = mid;
        high = mid - 1;
      } else {
        low = mid + 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int low = 1, high = n;
    while (low <= high) {
      int mid = (low + high) / 2;
      if (I[mid] - I[i - 1] >= k) {
        whereI[i] = mid;
        high = mid - 1;
      } else {
        low = mid + 1;
      }
    }
  }
  int ret = INF;
  for (int i = 1; i <= n; i++) {
    int j = whereJ[i];
    j = whereO[j];
    j = whereI[j];
    if (j != 0) {
      ret = min(ret, j - i + 1 - 3 * k);
    }
  }
  if (ret == INF) {
    ret = -1;
  }
  cout << ret << "\n";
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 27 ms 5104 KB Output is correct
37 Correct 29 ms 5448 KB Output is correct
38 Correct 29 ms 5524 KB Output is correct
39 Correct 27 ms 5252 KB Output is correct
40 Correct 27 ms 4792 KB Output is correct
41 Correct 26 ms 5152 KB Output is correct
42 Correct 28 ms 5436 KB Output is correct
43 Correct 14 ms 3152 KB Output is correct
44 Correct 18 ms 3784 KB Output is correct
45 Correct 23 ms 4636 KB Output is correct
46 Correct 25 ms 4688 KB Output is correct
47 Correct 23 ms 4628 KB Output is correct
48 Correct 23 ms 4696 KB Output is correct
49 Correct 16 ms 3212 KB Output is correct
50 Correct 24 ms 4668 KB Output is correct
51 Correct 23 ms 4668 KB Output is correct
52 Correct 15 ms 3364 KB Output is correct
53 Correct 16 ms 3612 KB Output is correct
54 Correct 19 ms 4636 KB Output is correct
55 Correct 16 ms 4164 KB Output is correct
56 Correct 13 ms 3868 KB Output is correct