Submission #922776

#TimeUsernameProblemLanguageResultExecution timeMemory
922776dimashhhJJOOII 2 (JOI20_ho_t2)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 12, MOD = 1e9 + 7; typedef long long ll; int n,k,A[N],B[N],C[N]; string s; vector<int> a,b,c; void test(){ cin >> n >> k >> s; s = "#" + s; for(int i = 1;i <= n;i++){ A[i] = A[i - 1]; B[i] = B[i - 1]; C[i] = C[i - 1]; if(s[i] == 'J'){ A[i]++; a.push_back(i); }else if(s[i] == 'O'){ B[i]++; b.push_back(i); }else{ C[i]++; c.push_back(i); } } if(min({(int)a.size(),(int)b.size(),(int)c.size()}) < k){ cout << -1 << '\n'; return; } int l = a[k - 1],r = c[(int)c.size() - k]; if(B[r] - B[l] < k){ cout << -1 << '\n'; return; } int L = 0,R = (int)c.size() - 1,res = 1e9; while(true){ res = min(res,n - k * 3 - (a[L] - 1) - (n - c[R])); if(L + k < (int)a.size() && B[c[R - k + 1]] - B[a[L + k]] >= k){ L++; }else if(R - k >= 0 && B[c[R - k]] - B[a[L + k - 1]] >= k){ R--; }else break; } if(res == 1e9) res = -1; cout<< res << '\n'; } int main() { ios_base::sync_with_stdio(0);cin.tie(0); int T = 1; // cin >> T; while (T--) test(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...