Submission #463549

# Submission time Handle Problem Language Result Execution time Memory
463549 2021-08-11T10:04:37 Z Mounir JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define all(x) x.begin(), x.end()
#define pb push_back
#define pii pair<int, int>
#define deb first
#define fin second
#define int long long
using namespace std;
 
signed main(){ 
      ios::sync_with_stdio(false);
      cin.tie(nullptr);
      cout.tie(nullptr);
 
      int nVals, K; cin >> nVals >> K;
      string chaine; cin >> chaine;
      int occs[3][nVals + 1];

      for (int i = 0; i < 3; ++i)
            occs[i][0] = 0;
      for (int ind = 0; ind < nVals; ++ind){
            for (int i = 0; i < 3; ++i)
                  occs[i][ind + 1] = occs[i][ind];
            if (chaine[ind] == 'J')
                  occs[0][ind + 1]++;
            else if (chaine[ind] == 'O')
                  occs[1][ind + 1]++;
            else
                  occs[2][ind + 1]++;            
      }

      int mini = nVals + 5;
      for (int deb = 1; deb < nVals; ++deb){
            int cur = deb - 1;
            bool ok = true;

            for (int i = 0; i < 3; ++i){
                  int bef = cur;
                  cur = lower_bound(occs[i], occs[i] + nVals + 1, occs[i][cur] + K) - occs[i];
                  ok &= (occs[i][cur] - occs[i][bef] >= K);
            }
            
            if (ok) {
                  //cout << deb << " " << cur << endl;
                  chmin(mini, cur - deb + 1);
            }
      }

      if (mini <= nVals)
            cout << mini - 3 * K << endl;
      else
            cout << -1 << endl;
      return 0;
 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Incorrect 0 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Incorrect 0 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Incorrect 0 ms 204 KB Output isn't correct
8 Halted 0 ms 0 KB -