제출 #463556

#제출 시각아이디문제언어결과실행 시간메모리
463556MounirJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
35 ms5528 KiB
#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){ if (occs[i][nVals] - occs[i][cur] < K) ok = false; cur = lower_bound(occs[i], occs[i] + nVals + 1, occs[i][cur] + K) - occs[i]; } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...