답안 #390080

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
390080 2021-04-15T10:09:02 Z tushar_2658 JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
16 ms 4056 KB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 200005;

int n, k;
string s;
int pref[3][maxn];
int a[maxn];

int main(int argc, char const *argv[])
{
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n >> k;
  cin >> s;
  for(int i = 0; i < n; ++i){
    if(s[i] == 'J')a[i] = 0;
    else if(s[i] == 'O')a[i] = 1;
    else a[i] = 2;
    pref[a[i]][i] = 1;
  }
  for(int i = 0; i < 3; ++i){
    for(int j = 1; j < n; ++j){
      pref[i][j] += pref[i][j - 1];
    }
  }
  int ans = n + 1;
  for(int i = 0; i < n; ++i){
    if(s[i] != 'J')continue;
    int l = i, r = n - 1, ans1 = -1;
    while(l <= r){
      int mid = (l + r) >> 1;
      if(pref[0][mid] - pref[0][i - 1] >= k){
        ans1 = mid;
        r = mid - 1;
      }else {
        l = mid + 1;
      }
    }
    if(ans1 == -1)break; 
    int idx = ans1;
    l = idx, r = n - 1, ans1 = -1;
    while(l <= r){
      int mid = (l + r) >> 1;
      if(pref[1][mid] - pref[1][idx - 1] >= k){
        ans1 = mid;
        r = mid - 1;
      }else {
        l = mid + 1;
      }
    }
    if(ans1 == -1)break;
    idx = ans1;
    l = idx, r = n - 1, ans1 = -1;
    while(l <= r){
      int mid = (l + r) >> 1;
      if(pref[2][mid] - pref[2][idx - 1] >= k){
        ans1 = mid;
        r = mid - 1;
      }else {
        l = mid + 1;
      }
    }
    if(ans1 == -1)break;
    ans = min(ans, ans1 - i + 1 - (3 * k));
  }
  if(ans == n + 1)cout << "-1" << '\n';
  else cout << ans << '\n';

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 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 1 ms 332 KB Output is correct
19 Correct 1 ms 324 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 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 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 328 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 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 1 ms 332 KB Output is correct
19 Correct 1 ms 324 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 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 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 328 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 12 ms 3668 KB Output is correct
37 Correct 13 ms 3924 KB Output is correct
38 Correct 13 ms 3940 KB Output is correct
39 Correct 15 ms 3904 KB Output is correct
40 Correct 8 ms 4056 KB Output is correct
41 Correct 14 ms 3964 KB Output is correct
42 Correct 16 ms 3912 KB Output is correct
43 Correct 4 ms 2636 KB Output is correct
44 Correct 5 ms 3160 KB Output is correct
45 Correct 6 ms 3928 KB Output is correct
46 Correct 6 ms 3940 KB Output is correct
47 Correct 6 ms 3928 KB Output is correct
48 Correct 6 ms 3928 KB Output is correct
49 Correct 4 ms 2776 KB Output is correct
50 Correct 6 ms 3928 KB Output is correct
51 Correct 6 ms 3928 KB Output is correct
52 Correct 6 ms 3800 KB Output is correct
53 Correct 6 ms 3928 KB Output is correct
54 Correct 11 ms 3928 KB Output is correct
55 Correct 7 ms 3928 KB Output is correct
56 Correct 4 ms 3964 KB Output is correct