Submission #244873

# Submission time Handle Problem Language Result Execution time Memory
244873 2020-07-05T07:59:06 Z rama_pang JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
5 ms 384 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  vector<vector<int>> P(N, vector<int>(3, 0));
  for (int i = 0; i < N; i++) {
    if (i > 0) {
      P[i] = P[i - 1];
    }
    if (S[i] == 'J') {
      P[i][0]++;
    } else if (S[i] == 'O') {
      P[i][1]++;
    } else if (S[i] == 'I') {
      P[i][2]++;
    }
  }
  auto Sum = [&](int i, int j, int k) {
    return P[j][k] - (i > 0 ? P[i - 1][k] : 0);
  };
  auto Next = [&](int s, int k) {
    if (s == N) {
      return N;
    }
    int lo = s + 1, hi = N;
    while (lo < hi) {
      int md = (lo + hi) / 2;
      if (Sum(s, md, k) >= K) {
        hi = md;
      } else {
        lo = md + 1;
      }
    }
    return lo;
  };
  auto Solve = [&](int st) {
    int to = Next(Next(Next(st, 0), 1), 2);
    if (to == N) {
      return N + N;
    }
    int len = to - st + 1;
    return len - 3 * K;
  };
  int ans = N + N;
  for (int i = 0; i < N; i++) {
    ans = min(ans, Solve(i));
  }
  if (ans > N) {
    ans = -1;
  }
  cout << ans << "\n";
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -