답안 #245408

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
245408 2020-07-06T10:43:39 Z kevlee JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
4 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define flush fflush(stdout)
#define debug printf("Hello\n")
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
//priority_queue <int, vector <int>, greater <int> > pq;
int n, m, k, x, y, sum, cnt, ans = -1;
string s;
bool check(int mid) {
  int J = 0, O = 0, I = 0;
  cnt = 0;
  FOR(i, mid-1, n-1) {
    if (J < k) {
      if (s[i] == 'J') J++;
      else cnt++;
    } else if (O < k) {
      if (s[i] == 'O') O++;
      else cnt++;
    } else if (I < k) {
      if (s[i] == 'I') I++;
      else cnt++;
    }
    if (J == k && O == k && I == k) {
      ans = cnt;
      return true;
    }
  }
  return false;
}
int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k >> s;
  int lo = 1, hi = n;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (check(mid)) {
      lo = mid + 1;
    } else {
      hi = mid - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -