답안 #1034492

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034492 2024-07-25T14:28:17 Z nguyendinhanh1508 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
13 ms 5608 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mx 1000007
#define inf LLONG_MAX/20
#define pi pair<int, int>
#define mp make_pair

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int J[n];
  int O[n];
  int I[n];
  J[0] = 0;
  O[0] = 0;
  I[0] = 0;
  if(s[0] == 'J') J[0]++;
  else if(s[0] == 'O') O[0]++;
  else if(s[0] == 'I') I[0]++;
  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 if(s[i] == 'I') I[i]++;
  }
  int ans = inf;
  for(int i = 0; i < n; i++){
    int prevJ = 0;
    if(i != 0) prevJ = J[i - 1];  
    if(s[i] != 'J') continue;
    int jay = lower_bound(J + i, J + n, k + prevJ) - J;
    if(jay == n) continue;
    int oou = lower_bound(O + jay + 1, O + n, k + O[jay]) - O;
    if(oou == n) continue;
    int aii = lower_bound(I + oou + 1, I + n, k + I[oou]) - I;
    if(aii == n) continue;
    int cost = (aii - i + 1) - (3 * k);
    ans = min(cost, ans); 
  }
  if(ans == inf) ans = -1;
  cout << ans;
  return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 456 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 532 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 460 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 452 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 456 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 532 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 460 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 452 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 10 ms 5096 KB Output is correct
37 Correct 10 ms 5608 KB Output is correct
38 Correct 10 ms 5596 KB Output is correct
39 Correct 11 ms 5608 KB Output is correct
40 Correct 10 ms 5608 KB Output is correct
41 Correct 11 ms 5608 KB Output is correct
42 Correct 12 ms 5608 KB Output is correct
43 Correct 5 ms 3676 KB Output is correct
44 Correct 7 ms 4368 KB Output is correct
45 Correct 13 ms 5608 KB Output is correct
46 Correct 8 ms 5596 KB Output is correct
47 Correct 9 ms 5608 KB Output is correct
48 Correct 9 ms 5608 KB Output is correct
49 Correct 6 ms 3948 KB Output is correct
50 Correct 9 ms 5608 KB Output is correct
51 Correct 9 ms 5608 KB Output is correct
52 Correct 8 ms 5352 KB Output is correct
53 Correct 7 ms 5604 KB Output is correct
54 Correct 8 ms 5608 KB Output is correct
55 Correct 6 ms 5608 KB Output is correct
56 Correct 5 ms 5608 KB Output is correct