Submission #245414

# Submission time Handle Problem Language Result Execution time Memory
245414 2020-07-06T11:02:57 Z kevlee JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
5 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 = inf, a[200005], b[200005], c[200005];
string s;
int jnn, on, in;
bool found;
int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k >> s;
  FOR(i, 0, n-1) {
    if (s[i] == 'J') {
      a[jnn++] = i;
    } else if (s[i] == 'O') {
      b[on++] = i;
    } else {
      c[in++] = i;
    }
  } 
  FOR(i, 0, jnn-1) {
    if (i + k - 1 >= jnn) break;
    int pos = upper_bound(b, b+on, a[i+k-1]) - b;
    if (pos == on) break;
    if (pos + k - 1 >= on) break;
    pos = upper_bound(c, c+in, b[pos+k-1]) - c;
    if (pos == in) break;
    pos = c[pos+k-1];
    found = true;
    ans = min(ans, pos - a[i] + 1 - 3 * k);
  }
  if (!found) cout << "-1" << endl;
  else cout << ans << endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Incorrect 4 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Incorrect 4 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Incorrect 4 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -